Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
how_to_make
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Erik Strand
how_to_make
Commits
c8a867ed
Commit
c8a867ed
authored
6 years ago
by
Erik Strand
Browse files
Options
Downloads
Patches
Plain Diff
Update code again
parent
5b492b15
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
content/08_embedded_programming.md
+0
-2
0 additions, 2 deletions
content/08_embedded_programming.md
static/designs/08_blink.c
+0
-78
0 additions, 78 deletions
static/designs/08_blink.c
with
0 additions
and
80 deletions
content/08_embedded_programming.md
+
0
−
2
View file @
c8a867ed
...
@@ -63,7 +63,6 @@ int main(void) {
...
@@ -63,7 +63,6 @@ int main(void) {
// Activate button_pin's pullup resistor.
// Activate button_pin's pullup resistor.
PORTA |= button_pin;
PORTA |= button_pin;
// Nothing left to do, so just spin.
while (1) {
while (1) {
// Turn on the LED when the button is pressed.
// Turn on the LED when the button is pressed.
if (PINA & button_pin) {
if (PINA & button_pin) {
...
@@ -158,7 +157,6 @@ int main(void) {
...
@@ -158,7 +157,6 @@ int main(void) {
int bouncy_switch_state = 0;
int bouncy_switch_state = 0;
int debounced_switch_state = 0;
int debounced_switch_state = 0;
// Nothing left to do, so just spin.
while (1) {
while (1) {
// Use the timer to count how long it's been
// Use the timer to count how long it's been
// since button_pin changed state.
// since button_pin changed state.
...
...
This diff is collapsed.
Click to expand it.
static/designs/08_blink.c
deleted
100644 → 0
+
0
−
78
View file @
5b492b15
#include
<avr/io.h>
#define switch_pin (1 << PA7)
#define led_pin (1 << PB2)
int
main
(
void
)
{
// Set the clock prescaler to 1.
CLKPR
=
(
1
<<
CLKPCE
);
CLKPR
=
(
0
<<
CLKPS3
)
|
(
0
<<
CLKPS2
)
|
(
0
<<
CLKPS1
)
|
(
0
<<
CLKPS0
);
// Set the 8 bit timer's prescaler to 1/1024.
TCCR0B
|=
0
b00000101
;
// Configure led_pin as an output.
DDRB
|=
led_pin
;
// Configure switch_pin as an input.
DDRA
|=
switch_pin
;
// Activate switch_pin's pullup resistor.
PORTA
|=
switch_pin
;
//int count1 = 0;
//int count2 = 0;
int
bouncy_switch_state
=
0
;
int
debounced_switch_state
=
0
;
while
(
1
)
{
// Turn on the led when the button is pressed
/*
if (PINA & switch_pin) {
PORTB &= ~led_pin;
} else {
PORTB |= led_pin;
}
*/
// ~5s blink period based on counting
/*
if (++count1 == 255) {
if (++count2 == 255) {
PORTB ^= led_pin;
count1 = 0;
count2 = 0;
}
}
*/
// ~2.5s second blink period
// 255 * 200 * (1024 / 20M) = 2.6112
/*
if (TCNT0 >= 200) {
TCNT0 = 0;
if (++count1 == 255) {
PORTB ^= led_pin;
count1 = 0;
}
}
*/
// the button toggles the led (with debouncing)
if
((
PINA
&
switch_pin
)
!=
bouncy_switch_state
)
{
bouncy_switch_state
=
PINA
&
switch_pin
;
TCNT0
=
0
;
}
if
(
TCNT0
>=
195
)
{
// It's been 10ms since the switch changed.
if
(
bouncy_switch_state
!=
debounced_switch_state
)
{
debounced_switch_state
=
bouncy_switch_state
;
if
(
debounced_switch_state
==
0
)
{
PORTB
^=
led_pin
;
}
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment