Thursday, February 28, 2013

My first AVR LED Blink program in C


I recieved my AVR programmer device last week so, i wrote my first LED blinking program in C (AVR). I used ATMEGA328P-PU chip. Earlier i have assembled my own arduino board so i used the same board for AVR by erasing the bootloader. below is my code

#include <avr/io.h>
#include <util/delay.h>

  @author Ujjwal Soni
  Connect a LED between pin 13 and GND.

void delay()
  unsigned char counter = 0;
  while (counter != 50)
    /* wait (30000 x 4) cycles = wait 120000 cycles */

int main(void)
  /* Initialization, set PB5 (arduino digital pin 13) as output */
  DDRB |= (1<<PB5);

  while (1) 
    PORTB |= (1<<PB5);  //arduino digital pin 5 -> 5V
    PORTB &= ~(1<<PB5);  //arduino digital pin 5 -> GND   
  return 0;

Please note that my LED is connected on PIN13.  
I will be also writing pushbutton code which i will be posting here soon.


Ujjwal Soni


toby led said...

Buy LED lighting products from LED Canada. We are suppliers for LED down lights, spotlights and LED Panel.
For more details please Visit:

Hublit said...

Hublit Lighting Pvt. Ltd. was founded in 1990, and has grown to be one of the most professional led light companies in India.

Hublit Led Lights Manufacturers

Cavin Mark said...

Autopal Merito – Excellence in lighting manufacture of LED, Spot, Indoor, COB, Flood, LGP, Panel Lightings and Series. A New Solution for Tomorrow’s Evolution. We are LED Manufacturing specialist, Exporters, Supplier in India.
Residential Led Lighting
Best Led Lights Company