diff options
Diffstat (limited to 'c/timer/timerctc.c')
-rw-r--r-- | c/timer/timerctc.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/c/timer/timerctc.c b/c/timer/timerctc.c new file mode 100644 index 0000000..7e65b52 --- /dev/null +++ b/c/timer/timerctc.c @@ -0,0 +1,26 @@ +#include <avr/io.h> + +enum{ + Dcnt = 62499 /* 1Hz */ +}; + +int +main() +{ + int led; + + led = 1<<PB1; + DDRB |= led; + TCCR1B |= 1<<CS12; /* f/256 prescaling */ + TCCR1B |= 1<<WGM12; /* ctc op mode */ + OCR1A = Dcnt; /* setup TOP */ + + for(;;){ + /* check if we reached TOP */ + if(TIFR1 & (1<<OCF1A)){ + PORTB ^= led; + TIFR1 = 1<<OCF1A; /* reset the flag */ + } + } +} + |