«

»

write a c code to flash a LED and burn it to atmega16 using AVR kit

LED Blinking Project

Interface a led with internal 8Mhz clock, connected to pin 6 in PORTA and flash it every 1 second.

1-Open AVR studio /and select new project

2-select the project type is AVR GCC and write the project name LEDBlinking

avr1

3-choose device atmega16

avr2

4-in the source file and LEDBlinking.c file write the following code:

#include <avr/io.h>

#include <util/delay.h> // to use delay function

int main(void)

{

DDRA = DDRA | (1<<PA6); //configure pin 6 in PORTA as output pin

PORTA |= (1<<PA6); // LED Off

while(1)

{

PORTA = PORTA & (~(1<<PA6)); // LED ON

_delay_ms(1000);

PORTA = PORTA | (1<<PA6); // LED OFF

_delay_ms(1000);

}

}

5- save the file and build

avr4

6-goto the saved project location ,you wil find LEDBlinking.hex file which we will burn it to microcontroller

7-by using USBASP programmer driver and AVR extrem

  • Download and setup avr extrem which is the burner program
  • Download and setup USBASP programmer driver

8-open avr extrem and select the file LEDblinking.hex and burn

Note to use the C51 kit for AVR microcontrollers you need the avr adaptor plate converter as on www.maklabstore

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>