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"
#include"util/delay.h"
//Start main function
void main()
{
//Set a particular port as input or output
DDRC = 0xFF; //PORTC output
DDRC = 0xFF; //PORTC output
//infinite loop
while(1)
{
while(1)
{
//set all the pins of PORTC to 1
PORTC = 0xFF;
PORTC = 0xFF;
//apply 100 ms delay
_delay_ms(100);
_delay_ms(100);
//set all the pins of PORTC to 0
PORTC = 0x00;
PORTC = 0x00;
//apply 100 ms delay
_delay_ms(100);
}
}
_delay_ms(100);
}
}
0 comments:
Post a Comment