ATtiny13 – blinky with Watchdog Timer

Yet another ATtiny13  blinky project. In our circuit a LED is connected to PB0 and it is made to blink for roughly every second by using Watchdog Timer. 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/wdt.h>
#include <avr/interrupt.h>
#include <avr/sleep.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
        wdt_enable(WDTO_500MS); // set prescaler to 0.5s and enable Watchdog Timer
        WDTCR |= _BV(WDTIE); // enable Watchdog Timer interrupt
        sei(); // enable global interrupts

        /* loop */
        while (1);

Leave a Comment