Tuesday, 11 June 2013

START WITH BLINKING LED

Good to see you again. Now we could code a bit.
Let’s start with Blinking LED.
//HOW CAN I BLINK THE 8 LED’s USING MY PORTB OF ATMEL ATMEGA 16

#include<avr/io.h>       //include AVR Header file
#include<util/delay.h> // include delay header file

main ()                 // main function
{
DDRB=0xFF;       //Declare PB4 as a Output

while (1)               //infinite loop

{

PORTB=0xFF;   //buzzer on
_delay_ms (1000);   // delay
PORTB=0b00000000; // buzzer off
_delay_ms (1000); // delay

} //while closed


}

Regarding the program
      1.     The header files used have predefined avr functions and commands.  
      2 . If we are using a delay in the program then we need to use the header of delay.
      3.   It is best way to write both the headers of C while using avr. There are much headers to be used next.
         4.     Going into the main function we have declared PortB as output port by putting all the pins 1.You can also             give the particular pin 1 in which you need the output. Suppose we need the output in my third pin so my PortB will be (DDRB=ob00000100).Don’t get confused why I used in this way but I have used in some other way in the program. It’s very simple, (0x) stands for hexadecimal and (0b) stands for binary. I am weak in conversion from binary to HEX so you can convert the same code and can use it in hex(DDRB=0x04). No matter’s whichever you like,
    5.     Now you have made all your PortB pins as output pins. We know that when the binary 1 fetched, the led glows and vice versa.
    6.     The values given in PortB is given as (PORTB=0xFF) which implies all the pins are given as 1.
    7.     The delay command used has a unit of millisecond delay.
    8.     The summary of this simple program is all the pins of PortB are made as output ports and all the led’s are supposed to glow and off after a delay of 1000 msec.
    9.     When you have written in avr just press f7 or build the program.
   10.  Go to the Avr boot flasher and browse the .hex file and it is over .
Thanks a lot…………………….. 

No comments:

Post a Comment