Home TutorialstinyAVR Attiny2313 flashing LED examnple

Attiny2313 flashing LED examnple

This was one of the first Attint chips that I looked at, so I decided to create a simple DIY development board (more on that later) and create some basic examples to play around with

Not a very exciting example, just the usual flashing LED example with a couple of LEDs connected to our attiny, lets look at the schematic.

Schematic

attiny2313 and leds

attiny2313 and leds

Code

We wrote this example in Atmel Studio. Fairly basic stuff here, set PORT D as outputs, switch on the LED connected to PD0, then the PD1 LED on, both LEDS on, then switch them off.

 

[codesyntax lang=”c”]

#define F_CPU 1000000UL // 1 MHz

#include <avr/io.h>
#include <util/delay.h>

//

int main(void)
{
// LEDs are on portD 0 and 1
DDRD = 0xff;

while(1)
{
PORTD = 0x01;
_delay_ms(500);
PORTD = 0x02;
_delay_ms(500);
PORTD = 0x03;
_delay_ms(500);
PORTD = 0x00;
_delay_ms(500);
}
}

[/codesyntax]

 

Links

5PCS ATTINY2313A

10 PCS ATTINY2313A 8-bit Microcontroller

You may also like