Thursday, March 1, 2012

Blinking LEDs

In this tutorial I am going to show you, how to blink LEDs using AVR micro controller. I am using ATmega128/ ATmega64 (both of the micro controller can be used interchangeably as they differ in the size of flash memory only). The 8 LEDs which I am going to blink/toggle are connected to PORTC of the micro  controller and they will toggle after 100 ms. So let's start with it............

*********************************************************************************
Blinking LEDs
*********************************************************************************

//Include AVR Header file
 #include"avr/io.h"
 
//Include DELAY Header file
#include"util/delay.h" 

//Start main function
void main()
{
   
     //Set a particular port as input or output
     DDRC = 0xFF;            //PORTC output
 
     //infinite loop
     while(1)              
     {
          //set all the pins of PORTC to 1  
         PORTC = 0xFF;      
 
          //apply 100 ms delay
         _delay_ms(100);        

         //set all the pins of PORTC to 0  
         PORTC = 0x00;            

         //apply 100 ms delay
         _delay_ms(100);      
     }
}

0 comments:

Post a Comment

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Affiliate Network Reviews