Blogger Widgets

Search This Blog

Monday, 17 December 2012


Here I just gives a brief introduction for AVR programming in Linux. I'm using ubuntu 11.10 . Finally we can able to blink an LED( Hello world program). Here I'm uses ATMEGA8 and usbasp programmer.

Step1 : Install the tool chains required for AVR programming
  •           sudo apt-get install gcc-avr
  •           sudo apt-get install avrdude
  •           sudo apt-get install libc

Step2 : Next step is to write an Hello world program - Here it is to just
            blink an LED .save this as led.c
                      DDRB = 0xff;
                      PORTB = 0xff;
                    Where <avr/io.h> is the header file for AVR programming.DDRB is the data direction register of PORTB, by writing 0xff we set this as output port.Then we write PORTB = 0xff it will set PORTB (8pins) to HIGH.

Step3 : Here we want to compile the program and make it hex code . for that  use the following steps.
  •           convert led.c to the object file led.o
                 avr-gcc -mmcu=atmega8  led.c -o led.o
                 some times we need to optimize the code
                 avr-gcc -mmcu=atmega8 -Os led.c -o led.o

  •           then convert the object file to hex file
                 avr-objcopy -j .text -j .data -O ihex  led.o  led.hex

 Step3 : Connect the usbasp programmer to the usb of the lap top
usbasp programmer

usbasp - development board
Step 4: To burn the hex code in to the ATMEGA8 connect the development  board to usb-asp. Then connect to the usb of the laptop .Connect a LED with a resistor to PORTB. Then run the following command
  • sudo avrdude -c usbasp -p m8 -U flash:w:led.hex:a 

you can see that the led connected to portB is blinking

some more avr-programming codes are adde in my github

No comments:

Post a Comment

Blogger Widgets