#include #include "utils.h" #include "bitmanip.h" #include "timer.h" #define PERIOD 500 // led turns on and off every PERIOD ms using CTC timer int main() { MODE_OUTPUT(LED2); TCCR1B |= (1 << WGM12); // Table 16-4 : set timer in CTC (Clear Time on Compare) mode, use bit WGM12, located in register TCCR1B (16.11.2) TCCR1A |= (1 << COM1A0); // 14.3.1 : set Compare Output with COM1A0, it toggles OC1A on compare match (Table 16-1), OC1A is alternate function for PORTB1 (Table 14-3) OCR1A = TIME_MS(PERIOD); // Table 16-4 : set CTC compare value on channel A, the counter is cleared to zero when the counter value (TCNT1) matches the OCR1A register TCCR1B |= (PRESCALE_SET(PRESCALE_VALUE)); while(1); }