Setting up AVR development platform

You can be encouraged to use various types of AVR development tools. Most of them cost money to get full functionality and support. Most common commercial packages are: CodeVisionAVR, Imagecraft ICCV, IAR Workbench. All they are great tools out of box with fast support that you have to pay for. Of course you can give a try with their limited versions to se capabilities. As we mentioned before we are going to use free tools that great enough comparing to commercial.

WinAVR or AVR-GCC tools

WinAVR is a toolset for C programming the AVR microcontrollers. It is actually a bunch of small programs that make development as easy as possible. Main tools here are avr-gcc compiler, avrdude programmer, avr-gdb debugger and even more. These actually are command line tools so you need to integrate them in to some integrated development environment (IDE). There can be any IDE supporting external tools like Eclipse and of course AVRStudio that we will be using. Besides, WinAVR comes with great program writing tool – Programmers Notepad. Actually with WinAVR you can write, compile, upload to chip and even debug your firmware either in emulator or via hardware debugger. As we are only going to use compiler only with different IDE we won’t be going into more details. Ah, probably you will find some rumors that WinAVR-20100110 is the last release if this great tool. Eric Weddington (maintainer) who is also a Product Manager at Atmel is probably going to shift this product to official ATMEL release. This won’t affect following tutorial as it still will be based on same avr-gcc compiler. So install, use it and don’t worry.

AVRStudio – also free and powerful

We are going to use AVRStudio intensively during this tutorial so get used to it. It is actually great IDE with lots of useful features like editor, debugger and programmer. It has ASM compiler ready to go and plugin that supports avr-gcc compiler from WinAVR. When you install both winAVR and AVRStudio you are ready to go. Let’s go through the process and compile our first program.

First program in AVRStudio

Launch AVRStudio create New Project by selecting menu Project->New Project. You should see following window pop-up:

Here you can create two types of Projects – ASM and C. As we want to create C project, select AVR GCC option. Select location where project will be stored.  It is good practice to Create folder where all project files will be stored and if creating new program, then create initial file (it can also be created later). If you are set here then clock Next button. In next window things become more interesting as here you have to select debugging platform and AVR chip:

As we are not using any hardware debuggers just select AVR Simulator for software debugging and choose your device. I’ve selected ATmega16. Click Finish to go to editor. Before writing code lets configure necessary settings so we could properly compile code. Go to menu Project->Configuration Options.

Here you can see a bunch of settings. This time we need to select our device (Atmega16) and enter frequency of oscillator. Make sure that there is a checkbox Create Hex File marked – this will generate hex file ready to upload to chip. Click OK to save and let’s write simple program.

#include <avr/io.h>
#include <util/delay.h>
int main (void)
	DDRB = 0x01; //set PB0 pin as output
	while(1) //loop for ever
		PORTB =0x00; //turn LED ON
		_delay_ms(1000); //wait 1s
		PORTB =0x01; //turn LED OFF
		_delay_ms(1000);//wait 1s
	return 0;

This is very simple and straightforward program that will blink single LED connected to PB0 pin of B port. This is only to show building process so don’t care too much about program itself. Circuit is simple as well:

When code is entered you can build the project. Go to menu Build->Build and you should compile it without errors and see message bellow:

Build started 18.10.2010 at 23:11:48

AVR Memory Usage
Device: atmega16

Program:     156 bytes (1.0% Full)
(.text + .data + .bootloader)

Data:          0 bytes (0.0% Full)
(.data + .bss + .noinit)

Build succeeded with 0 Warnings...

If you go to the project folder, in default sub-folder you will find your hex file that can be programmed to your chip. How to flash the chip and debug we will discuss later. Now you should know how to compile simple program in AVRStudio.

Bookmark the permalink.


  1. thanks for the article

    btw, i think C1 and C2 are missing connections to ground in the schematic

  2. Oops! Thanks for showing this. Fixed.

  3. Pingback: Blog » Blog Archive » Setting up AVR development platform

  4. hi i did all u said but i keep getting errors when i compile

  5. i named the project as flash it keeps popping
    avr-objcopy: ‘flash.elf’: No such file
    make: *** [flash.hex] Error 1
    Build failed with 1 errors and 0 warnings…

Leave a Reply

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