#include <iom32v.h>
#include <macros.h>
void port_init(void)
{
PORTA = 0x00;
DDRA = 0x00;
PORTB = 0x08;
DDRB = 0x08;
PORTC = 0x00;
DDRC = 0x00;
PORTD = 0x00;
DDRD = 0x00;
}
//TIMER0 initialize - prescale:64
// WGM: Normal
// desired value: 1KHz
// actual value: 1.002KHz (0.2%)
void timer0_init(void)
{
TCCR0 = 0x00; //stop
TCNT0 = 0x8D; //set count
OCR0 = 0x73; //set compare
TCCR0 = 0x23; //start timer
}
#pragma interrupt_handler timer0_comp_isr:10
timer0_comp_isr()
{
}
#pragma interrupt_handler timer0_ovf_isr:12
timer0_ovf_isr()
{
TCNT0 = 0x8D;
}
//call this routine to initialize all peripherals
main()
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
timer0_init();
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x03; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
} |