Getting Started with Embedded System Design on AVR


In this tutorial, we will learn how to interface LED with Atmega16 using AVR Studio.

An embedded system is built around a processor.
The design goals of an embedded system are to reduce size, cost and power consumption and to increase performance and reliability.

The microprocessor we are using is ATMEGA16.
The processor has limited internal memory, and if this is not sufficient for a given application external memory devices are used.
The hardware also includes any components that facilitate the user-application interaction such as display units, keypad.
The light emitting diodes are used for getting status information, such as power on, check output(high/low).
You all must have observed led decoration lights, which can glow in different patterns.

First, we will learn to interface a single Led and then 8 LEDs to learn a simple toggling technique.

Components Required:-
  • AVR controller(Atmega16)
  • LEDs
  • Connecting wires
  • USBASP Programmer
For single Led dump the following code:

#include<avr/io.h>
#include<util/delay.h>
void main()
{
DDRB=0xff;
int a=1;
while(1)
{
PORTB=a;
_delay_ms(100);
}
}

2.For toggling using 8 LEDs dump the following code:-

#include<avr/io.h>
#include<util/delay.h>
void main()
{
DDRB=0xff;
int a;
while(1)
{
for(a=1;a<=128;a=a*2)
{
PORTB=a;
_delay_ms(100); 
}
}
}
Thinking?
Join our hands-on training courses.
To know more visit us at http://www.sudolearn.com/
Next
Previous