#include "at90s8515.h" int count; // Timer/Counter0 Overflow counter int main (void) { DDRB = 0xff; // configure as output PORTB = 0xff; // turn all leds off DDRD = 0x0; // configure as input SREG |= 1<<7; // Global Interrupt enable GIMSK |= 1<<6; // External Interrupt Request 0 enable TIMSK |= 1<<1; // Timer/Counter0 Overflow Interrupt enable MCUCR |= 0xfe; // the falling edge of INT0 generates an interrupt request while (1) {} return 0; } void EXT_INT0 (void) SIGNAL; void TIM0_OVF (void) SIGNAL; void EXT_INT0 (void) { count = 0; if (MCUCR == 0xfe) { TCCR0 = 0x05; // start Timer/Counter0 with prescale CK/1024 MCUCR |= 0xff; // the rising edge of INT0 generates an interrupt request } else { MCUCR |= 0xfe; // the falling edge of INT0 generates an interrupt request TCCR0 = 0x0; // stop Timer/Counter0 PORTB |= 1<<2; // turn off led 2 } } void TIM0_OVF (void) { count++; if (count == 35) { PORTB &= ~(1<<2); // turn on led 2 TCCR0 = 0x0; // stop Timer/Counter0 } }