#include <stdio.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#define TIMER0_PRESCALER_1 0x01
#define TIMER0_PRESCALER_8 0x02
#define TIMER0_PRESCALER_64 0x03
#define TIMER0_PRESCALER_256 0x04
#define TIMER0_PRESCALER_1024 0x05
#define OUTPUTS 3 //ports A,B,C,D
SIGNAL(SIG_OVERFLOW0);
int main(void);
unsigned int port_walk=0; //global port counter
/*
* Timer0 Interrupt Service Routine
*/
SIGNAL(SIG_OVERFLOW0) {
TCNT0=0xDF; //ticks 33 = 256 - 33 = 223 = 0xDF
//rotation restart for LED group flashing
if ( port_walk > OUTPUTS ) {
port_walk=0;
}
//flash all ports
PORTA=0xFF;
PORTB=0xFF;
PORTC=0xFF;
PORTD=0xFF;
//remove flash from one port at a time
if ( port_walk == 0 ) {
PORTA=0x00;
} else if ( port_walk == 1 ) {
PORTB=0x00;
} else if ( port_walk == 2 ) {
PORTC=0x00;
} else if ( port_walk == 3 ) {
PORTD=0x00;
}
port_walk++;
}
int main(void)
{
//Enable PORT{A,B,C,D} 0-7 as outputs
DDRA=0xFF;
DDRB=0xFF;
DDRC=0xFF;
DDRD=0xFF;
TCCR0A=TIMER0_PRESCALER_64; //prescaler setup for timer0
TCNT0=0x00; //start timer with nothing
TIMSK0 = (1 << TOIE0); //unmask timer0 overflow register
sei(); //set (global) Enable Interrupts
while(1);
}