/* timer_ctc_mode_01.c ATmega88 @ 8MHz */ #include <avr/io.h> #include <avr/interrupt.h> #define LED (1<<PB3) // LED auf Portpin B3 int main(void) { DDRB |= (1<<PB3); // Portpin B3 = output TCCR1B |= (1 << CS12); // Vorteiler auf 256 und Timer start TCCR1B |= (1 << WGM12); // Mode 4, CTC on OCR1A OCR1A = 31249; // Compare match auf 31249 setzen TIMSK1 |= (1 << OCIE1A); // Interrupt bei compare match aktivieren sei(); // enable interrupts while(1) { asm ("NOP"); // Nichts tun } } ISR (TIMER1_COMPA_vect) // Timer1 Compare Match Interrupt { PORTB ^= LED; // LED im Sekundentakt toggeln lassen }