Monday 16 July 2018

Interfacing LED with AVR Microcontroller (Atmega-8)


Aim:

Light Emitting Diodes (LED) is the most commonly used components, usually for displaying pins digital states. Typical uses of LEDs include alarm devices, timers and confirmation of user input such as a mouse click or keystroke. The main aim of this project is how to interface a single LED to atmega-8 microcontroller.
images (1)

Description:

Interfacing LED:
Fig. 1 shows how to interface the LED to microcontroller. As you can see the Cathode is connected through a resistor to GND & the Anoode is connected to the Microcontroller pin. So when the Port Pin is HIGH the LED is ON & when the Port Pin is LOW the LED is turned OFF.
intetrface led
Interfacing LED with Atmega8

We now want to flash a LED in atmega8 board. It works by turning ON a LED & then turning it OFF & then looping back to START. However the operating speed of microcontroller is very high so the flashing frequency will also be very fast to be detected by human eye.
The atmega8 board has eight numbers of point LEDs, connected with I/O Port lines to make port pins high.
Pin Assignment with atmega8
Point LEDsAtmega 8  directionAtmega 8 LinesLED SelectionConnections
DIGITAL OUTPUTSLED.0 DDRx=0x01PORTx=0x01dddConnect Any one PORT from
PORTB, PORTC, PORTD
LED.1DDRx=0x02PORTx=0x02
LED.2DDRx=0x04PORTx=0x04
LED.3DDRx=0x08PORTx=0x08
LED.4DDRx=0x10PORTx=0x10
LED.5DDRx=0x20PORTx=0x20
LED.6DDRx=0x40PORTx=0x40
LED.7DDRx=0x80PORTx=0x80

Block Diagram

1. interfacing single led

Schematic:

Code:

// ***********************************************************
// Project: Interfacing Single LED to atmega8
// Author: Code Bloges
// Module description: Operate single LED
// ***********************************************************

#define F_CPU 8000000UL
#include <avr/io.h>
#include<util/delay.h>

int main(void)
 {
     DDRB=0x01;
     while(1)
     {
         PORTB=0x01;
     }
 }

Downloads:


No comments:

Post a Comment