I'm new programming in C and would like a pointer as to what's up with some code. I'm using an AtMega32-16PU processor and attempting to light up an LED using a simple interrupt routine. I have the LED plugged into pin1 with an in series resistor.
This code does not work:
**********************
#include <avr/io.h>
#include <avr/interrupt.h>
int main(void)
{
sei();
DDRB |= 1<<PINB0;
TCCR1B = 0b00001001;
TIMSK |= 1<<OCIE1A;
OCR1A = 25;
while(1){
}
}
ISR(TIMER1_COMPA_vect){
PORTB ^= 1<<PINB0;
}
***************
However, if I initialize PORTB to 0x01, the LED lights up. The LED does not light if PORTB is initialized to 0x00.
I'm clearly missing some piece of information which surely makes this result the obvious correct behavior, but it seems odd to me that I have to initialize the value of PORTB and it has to be 0 here given the the way I've written the interrupt routine.
Thoughts?