Trouble with Timer 0 I'm taking my first wobbly steps outside the Arduino IDE and I'm not having much success with timers / interrupts. I can set a pin to output and light an LED with registers fine but I cannot for the life of me get it to blink using a timer. I have tried numerous tutorials and followed the Atmel ATmega328 datasheet very closely.

Using an Arduino Uno R3 &amp; Atmel ICE (ISP.) My dev system is Raspbian (Debian) with the GNU AVR toolchain (avr-gcc, avr-objcopy, avrdude.) Apart from not having a bootloader it's a bog standard board (including fuses.)

Here's my current code:

#include &lt;avr/io.h&gt;
#include &lt;avr/interrupt.h&gt;

ISR(TIMER0_COMPA_vect)
{
    PORTB ^= (1 &lt;&lt; PB5); // Toggle Arduino Pin #13
}

int main (void)
{
    DDRB = (1 &lt;&lt; DDB5); // Arduino Pin #13 is Output

    cli(); // Clear Interrupts

    OCR0A = (unsigned char)0xFF; // Compare Register A = 255
    TIMSK0 = (1 &lt;&lt; OCIE0A); // Enable Interrupt for Comp. Reg. A
    TCCR0A = (1 &lt;&lt; WGM01); // CTC Mode

    sei(); // Set Interrupts
    TCCR0B = (1 &lt;&lt; CS02) | (1 &lt;&lt; CS00); // Divide by 1024 Prescaler (GO!)

    return 0;
}


I don't know if I'm just not seeing something or if I've set registers in the wrong order but it's driving me crazy.
return 0 resets the device. Use while(1); instead, to make it wait indefinitely.