author | Tero Marttila <terom@paivola.fi> |
Thu, 03 Apr 2014 20:25:12 +0300 | |
changeset 53 | dfe67409fbcd |
parent 52 | 237d1f5c1c32 |
child 54 | ec42f36d8614 |
permissions | -rw-r--r-- |
47
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
1 |
#include <avr/io.h> |
49 | 2 |
|
52
237d1f5c1c32
hello: split out timer; add serial
Tero Marttila <terom@paivola.fi>
parents:
50
diff
changeset
|
3 |
#include "stdlib.h" |
237d1f5c1c32
hello: split out timer; add serial
Tero Marttila <terom@paivola.fi>
parents:
50
diff
changeset
|
4 |
#include "timer.c" // XXX |
237d1f5c1c32
hello: split out timer; add serial
Tero Marttila <terom@paivola.fi>
parents:
50
diff
changeset
|
5 |
#include "serial.c" // XXX |
47
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
6 |
|
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
7 |
int main (void) |
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
8 |
{ |
49 | 9 |
timer_init(); |
52
237d1f5c1c32
hello: split out timer; add serial
Tero Marttila <terom@paivola.fi>
parents:
50
diff
changeset
|
10 |
serial_init(); |
49 | 11 |
|
47
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
12 |
// LED |
49 | 13 |
sbi(&DDRB, DDB5); |
14 |
||
15 |
sei(); |
|
16 |
||
17 |
// blink |
|
52
237d1f5c1c32
hello: split out timer; add serial
Tero Marttila <terom@paivola.fi>
parents:
50
diff
changeset
|
18 |
char c = 'X'; |
53
dfe67409fbcd
hello: interruptable timer sleep, with buffered serial IO
Tero Marttila <terom@paivola.fi>
parents:
52
diff
changeset
|
19 |
short timeout = 8000; |
49 | 20 |
short delta = 10; |
47
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
21 |
|
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
22 |
while (true) { |
53
dfe67409fbcd
hello: interruptable timer sleep, with buffered serial IO
Tero Marttila <terom@paivola.fi>
parents:
52
diff
changeset
|
23 |
// toggle |
49 | 24 |
xbi(&PORTB, PORTB5); |
47
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
25 |
|
53
dfe67409fbcd
hello: interruptable timer sleep, with buffered serial IO
Tero Marttila <terom@paivola.fi>
parents:
52
diff
changeset
|
26 |
// sleep |
dfe67409fbcd
hello: interruptable timer sleep, with buffered serial IO
Tero Marttila <terom@paivola.fi>
parents:
52
diff
changeset
|
27 |
if (timer_sleep(timeout)) { |
dfe67409fbcd
hello: interruptable timer sleep, with buffered serial IO
Tero Marttila <terom@paivola.fi>
parents:
52
diff
changeset
|
28 |
c = '.'; |
dfe67409fbcd
hello: interruptable timer sleep, with buffered serial IO
Tero Marttila <terom@paivola.fi>
parents:
52
diff
changeset
|
29 |
|
dfe67409fbcd
hello: interruptable timer sleep, with buffered serial IO
Tero Marttila <terom@paivola.fi>
parents:
52
diff
changeset
|
30 |
} else if ((c = serial_read())) { |
dfe67409fbcd
hello: interruptable timer sleep, with buffered serial IO
Tero Marttila <terom@paivola.fi>
parents:
52
diff
changeset
|
31 |
// got serial data |
dfe67409fbcd
hello: interruptable timer sleep, with buffered serial IO
Tero Marttila <terom@paivola.fi>
parents:
52
diff
changeset
|
32 |
} else { |
dfe67409fbcd
hello: interruptable timer sleep, with buffered serial IO
Tero Marttila <terom@paivola.fi>
parents:
52
diff
changeset
|
33 |
c = '?'; |
dfe67409fbcd
hello: interruptable timer sleep, with buffered serial IO
Tero Marttila <terom@paivola.fi>
parents:
52
diff
changeset
|
34 |
} |
49 | 35 |
|
53
dfe67409fbcd
hello: interruptable timer sleep, with buffered serial IO
Tero Marttila <terom@paivola.fi>
parents:
52
diff
changeset
|
36 |
// output... |
dfe67409fbcd
hello: interruptable timer sleep, with buffered serial IO
Tero Marttila <terom@paivola.fi>
parents:
52
diff
changeset
|
37 |
serial_write(c); |
47
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
38 |
} |
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
39 |
} |