ATtiny13 – blinky with timer OVF (Overflow)

Yet another blinky project that is based on internal timer. In our circuit a LED is connected to PB0 and it is made to blink for roughly every second by using timer OVF (overflow). The code is on Github, click here.

Parts Required

Circuit Diagram



This code is written in C and can be compiled using the avr-gcc. More details on how compile this project is here.

#include <avr/io.h>
#include <avr/interrupt.h>

#define LED_PIN PB0


        PORTB ^= _BV(LED_PIN); // toggle LED pin


        /* setup */
        DDRB = 0b00000001; // set LED pin as OUTPUT
        PORTB = 0b00000000; // set all pins to LOW
        TCCR0B |= _BV(CS02)|_BV(CS00); // set prescaler to 1024 (CLK=1200000Hz/1024/256=4Hz, 0.25s)
        TIMSK0 |= _BV(TOIE0); // enable Timer Overflow interrupt
        sei(); // enable global interrupts

        /* loop */
        while (1);

Leave a Comment