Programming AVR ICs with Eclipse

Eclipse is  a multiplatform supported IDE for C, C++, Android development in Windows and Linux. This post intends to give light for embedded developers, how to program AVR Microcontrollers using Eclipse. The reason why eclipse is chosen is due to its  code completion ability and availability of plugins.

Eclipse for AVR

Eclipse for AVR

The tutorial is based on the setup done in Windows 7 with Eclipse Indigo(3.7) and WinAVR – 20100110.

Download and install latest version of winavr from here inside C:/WinAVR.

Download Eclipse Indigo for C/C++ from here.

Extract the downloaded zip file to any directory, please note that it is good to extract in location where its path doesn’t contain any spaces. Open eclipse.exe from the extracted folder and create a workspace of your choice. Download the AVR-Eclipse plugin from here and install to eclipse as follows.

Note: Follow the tutorial in the download page of AVR-Eclipse plugin, for those who don’t know how to install                  plugins in Eclipse IDE.

After installing the Plugin, restart the Eclipse IDE. Navigate to Help –>  Help Contents –> AVR plugin to find instructions for creating an AVR Cross Target Application Project.

Create a source file named main.c inside the project, and copy paste the following code into it.


#include<avr/io.h>
#include<avr/interrupt.h>
#include<util/delay.h>
#define F_CPU 16000000UL
int main(void)

{
DDRB |= 0xFF;
PORTB |= 0xFF;
sei(); // set global interrupt
while (1)
{
PORTB ^= 0xFF;
_delay_ms(500);
__asm__ volatile("nop"); // so the endless loop isn't optimized away
}

return (1); // should never happen
}

You should create a programming interface by creating it from Window –> Preferences.

Eclipse_Programmer_AVRRe

In Project –> Properties –> AVR –> AVRDude select the Programmer that is created in the above step.

In Project –> Properties –> C/C++ Build –> Settings , tick Generate Hex file for Flash memory Dialog as shown below.

Create_hex

Compile the program using Project –> Build all.

AVR download button Press the AVR Download button to download the compiled file to hex.

Now the LED connected to PORTB will start blinking!!!.

Advertisements

2 thoughts on “Programming AVR ICs with Eclipse

  1. Pingback: Debugging AVR ICs using JTAGICE and Eclipse in Linux | Random Codes - Elementz Tech Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s