ATtiny13 – blinky with delay function

This tiny project shows how to interface LED to the microcontroller ATtiny13 and write a simple program to make it blink. The code is on Github, click here.

LEDs are widely used for various display functions and can be directly (not quite directly, through the resistor) driven from the pins of AVR chip. In our circuit a LED is connected to PB0 and it is made to blink for roughly every second by using delay function.

Parts Required

Circuit Diagram

blinky-one-led

Software

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 <util/delay.h>

#define LED_PIN PB0                     // PB0 as a LED pin

int
main(void)
{

        /* setup */
        DDRB = 0b00000001;              // set LED pin as OUTPUT 
        PORTB = 0b00000000;             // set all pins to LOW

        /* loop */
        while (1) {
                PORTB ^= _BV(LED_PIN);  // toggle LED pin
                _delay_ms(500);
        }
}

 

One thought on “ATtiny13 – blinky with delay function

  1. Hi…
    I want to build this project using BASCOM AVR.. maybe u can help me to build the coding … thx u.

Leave a Comment