// ---------------------------------------------------------------------------- // timer.c // ---------------------------------------------------------------------------- #include #include // ---------------------------------------------------------------------------- #define OUT_PORT PORTB #define OUT_PIN 0 #define F_CPU 8000000L // 8 MHz clock #define PIN(x) (*(&x - 2)) // input register of port x #define DDR(x) (*(&x - 1)) // data direction register of port x // ---------------------------------------------------------------------------- int main(void) { DDR(OUT_PORT) |= _BV(OUT_PIN); // set out-port TIMSK |= _BV(TOIE0); // enable TIMER0_OVERFLOW TCCR0 |= (_BV(CS00) | _BV(CS02)); // start timer, prescale 1024 sei(); // enable global interrupt for(;;); // loop } // ---------------------------------------------------------------------------- // ISR(TIMER0_OVF_vect) // Interrupt handler for TC0 overflow. // ---------------------------------------------------------------------------- ISR(TIMER0_OVF_vect) { OUT_PORT ^= 0x01; // toggle } // ----------------------------------------------------------------------------