microhope/microhope-doc/prog/blink.c
raw| 1 | #include <avr/io.h> |
| 2 | |
| 3 | void delay (uint16_t k) |
| 4 | /* generates delay by decrementing a number until it reaches zero. |
| 5 | roughly 2 usec per loop at 8 MHz system clock |
| 6 | */ |
| 7 | { |
| 8 | volatile uint16_t x = k; |
| 9 | while (x) --x; |
| 10 | } |
| 11 | |
| 12 | int main (void) |
| 13 | { |
| 14 | DDRB = 1; // Data Direction Register for port B |
| 15 | |
| 16 | for(;;) |
| 17 | { |
| 18 | PORTB = 1; |
| 19 | delay(30000); |
| 20 | PORTB = 0; |
| 21 | delay(30000); |
| 22 | } |
| 23 | } |