My First Steps into Embedded System

In this post, i would like to share a few links and tips which will make you to setup an AVR development environment for Linux with in five minutes, and writing your first AVR program.



First of all, you need to install 3 libraries avr-libc gcc-avr .

$sudo apt-get install avr-libc gcc-avr 

If you want to know the use of avr-libc and gcc-avr libraries read this.

My First Program: Blinking an LED

#include<avr/io.h>
#include<util/delay.h>
main()
	{
	DDRB |= _BV(PB0);
	while(1)
		{
		
		PORTB |=_BV(PB0);
		_delay_ms(1000);
		PORTB &= 0<<PB0;
		_delay_ms(1000);
		}
	}

This code assumes an LED is connected to port B 0 pin.

Compiling and Linking

$avr-gcc -g -Os -mmcu=atmega8 -c blink.c

-mmcu specifies your chip type. This command will produce a blink.o file. Next we link this file

$avr-gcc -g -mmcu=atmega8 -o blink.elf blink.o

It will create another file blink.elf. Next we want to convert it to hex

$avr-objcopy -j .text -j .data -O ihex blink.elf blink.hex

It will produce a blink.hex file. Now we can burn this file into microcontroller.

Burning .hex file into MCU

This part depends upon the programmer that you use to program the chip. I am using USB programmer brought from extreme electronics. You can use avrdude or extreme burner-avr.
I use extreme burner software, because it is free and Linux and windows versions of the software is available also GUI is very much user friendly.


The last step is to write the blink.hex file created earlier to the flash memory of atmega8. If you do all the above steps correctly, LED will blink. Welcome to Embedded System world 🙂

2 thoughts on “My First Steps into Embedded System

  1. Will be following your footsteps. But can i erase or modify the code once installed or do I need to purchase a pile of chips for each of my trials ?

    1. No. Definitely you can erase and rewrite new code into chip. If you look at the eXtreme Burner software, there is an option to erase chip data.

Leave a comment