#include <io.h>
#include <interrupt.h>
#include <signal.h>
unsigned char led;
SIGNAL(SIG_OVERFLOW0) /* signal handler for tcnt0 overflow interrupt */
{
outp(~led, PORTB); /* invert the output since a zero means: LED on */
led <<= 1; /* move to next LED */
if (!led) /* overflow: start with Port B0 again */
led = 1;
outp(0, TCNT0); /* reset counter to get this interrupt again */
}
int main(void)
{
outp(0xff,DDRB); /* use all pins on PortB for output */
outp((1<<TOIE0), TIMSK); /* enable TCNT0 overflow */
outp(0, TCNT0); /* reset TCNT0 */
outp(5, TCCR0); /* count with cpu clock/1024 */
led = 1; /* init variable representing the LED state */
sei(); /* enable interrupts */
for (;;) {} /* loop forever */
}