Sunday, November 7, 2010

AVR Tutorial - C Language-



We use AVR Butterfly and AVR Studio


You might wonder why blinking an LED is the first project, when traditional C programming texts start with the classic “Hello, world” program. It certainly seems that since the Butterfly has an LCD that can show the words it would be easy. But the reality is that controlling the LCD is much more complex than linking an LED, so we’ll save the LCD for later when we’ve gotten a better handle on things.
Find Programmers Notepad that was installed as part of WinAVR (you should have an icon for it on your desktop) and open it. You will need to add a tool, which will let you use the AVR Studio simulator.

the Code :
//blinking.c

#include
#include

int main (void)
{
//set PortD for Output
DDRD =0xFF;
while(1)
{
for(int i=1;i<128;i=i*2)
{
PORTD=i;
_delay_loop_2(30000);
}
for(int i=128;i>1;i-=i/2)
{
PORTD=i;
_delay_loop_2(30000);
}
}
return 1;
}