AVR C Programming - Digital Outputs



UpdatedUpdatedOctober 07 - 2017October 07 - 2017

AVR C structure

Let's go through the following C program first.

blinkLED.c



Explanation of blinkLED.c file:



Summary of blinkLED.c file:

First we have included <avr/io.h> and <util/delay.h> files.
<avr/io.h> is a header file that includes AVR device-specific IO definitions. In our program it defines all the DDRs and PORTs.
<util/delay.h> defines the _delay_ms() function which we use to delay between two blinks.
_delay_ms(500): in this case the delay between ON/OFF states is 500 ms.

Output of this program:

I have connected PB0 to the first LED (from right side). So that Red LED is blinking continuously (500 ms delay between two blinks).


Setup connection

Accessories:

  • 1 breadboard
  • 6 red LEDs
  • 6 resistors (each one of them is 1k Ohm)
  • wires

Connection diagram:

avr2LED.png


In summary:

PB5
PB4
PB3
PB2
PB1
PB0
LED5LED4LED3LED2LED1LED0