- Code for the fun of it
Setting up programming environment for ATMega1280
none ATMega1280 
There are several options available to allow you to develop, debug, simulate and upload your code.  I personally use AVR Studio and WinAVR as my development platform because it provides the best platform for the type of development I am used to and allows the greatest flexibility of all the free IDE's that I found.

Development environments

Arduino  - Current version 0018 can be had [here] 

o Very simple IDE
o Good for small projects
o Allows C++
o Can upload directly from IDE

VMLab - Current version 315 can be had [here] I mainly used this while I was waiting for my board to be delivered.

o Great tool for simulation and learning
o Allows true hardware/software co-simulation
o SPICE-like hardware description language
o Provides a scope
o Does not support ATMega1280

AVR Studio - Current version 4.18 Build 700 (SP2) can be had [here]

o Visual Studio 2005 style IDE
o Good for small to large projects.
o Can't use C++, only assembler and C but I don't find this a restriction since C++ requires more space.
o Uses GCC-AVR compiler (WinAVR get it [here])
o Use Hapsim for simulation, get it [here].
o Visual Studio style debugger, allows you to set and view port values at break point for simulation.
o Use avrdude to upload compiled code, comes with WinAVR.

Eclipse - with AVR Plugin, Eclipse [here] AVR Plugin [here]

o  Versatile IDE, very nice
o Configure to use different tool chains.
o Allows C and C++
o Able to upload to device
o Debugging - very difficult to set up and I was unable to get debugging to work.

I was extremely impressed with the Eclipse experience overall and would use it if it were not for the debugging issue.

Other Helpful software

  • AVR IO Designer - current version 2.0.12 and can be had [here] This is a nice program that I use to help in setting the ports and associated functionality of the device.  Supports a wide variety of devices and provides a good explanation of  usage. 

Reference material

  • The knockoff I bought was the "DFRobot DFRduino ATMega1280 MEGA USB Microcontroller" it was cheaper than the Arduino Mega by about $17 and according to tech support "The boards are (almost) literally identical. The Arduino MEGA has been ROHS certified, while the DFRobot MEGA has yet to be certified. Arduino MEGA has a longer warranty period.".  The schematic for this board, in PDF format can be downloaded [here].

  • ATMega1280 datasheet - this is a must and is essential to your design process when setting up the boards ports and functionality, it can be downloaded [here].

Setting up the AVR Studio environment

There are many good articles on this subject so I will give a brief overview of the steps needed to do the setup and get you going.

  1. Download the WinAVR package and install it on your system.
  2. Download and install the AVR Studio.
  3. [optional] Download and install the Hapsim simulator.  (To use Hapsim you must start AVR Studio first)

The Hello World program for Micro Controllers

To check that our environment is set up properly and to start us off on our road to glory we will start with a very simple application.  The equivalent Hello World program for Micro Controllers is getting an LED to blink.  To accomplish this we  will use AVR Studio to develop the software and Hapsim to simulate the blinking LED.

1) Start the AVR Studio application and from the menu select Project->New Project
2) On this first window in the wizard choose the AVR GCC option and enter the information as shown, or whatever you care to name it.

3) Click next to go to the 2nd wizard window
4) In the left pane select Simulator and in the right pane navigate to the ATMega1280 option and select it.

5) In the blink.c code window enter


#ifndef F_CPU
#define F_CPU 16000000
#endif

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

int main()
{
    DDRD = 0xff;

    while(1)
    {
        PORTD = 0xff;
        _delay_ms(100);
        PORTD = 0;
        _delay_ms(100);
    }
}

Code Explanation - What we have done here is set the data direction register for PortD, all pins as output.  The in the while loop we set all pins to HIGH, wait 100ms, set all pins to LOW, wait another 100ms then repeat the process forever.  Simple stuff!

6) Compile the project, either from the toolbar or the Build menu option.
7) Correct any errors as needed and re-compile
8) Once you have it run the project from the Debug menu option.  I'm not sure why yet but this is a two step process, once you run the project the program stops with the debug cursor at the start of the program and you have to hit the document looking toolbar item with the down arrow next to it?  If anyone has any input on this I would love to know why.
9) Optionally start the Hapsim application, select the LED new component and configure it as shown in the following example, click OK and you should see a blinking LED in the LED window. Note: be sure to select the ATMega1280 device in the combo box or you won't get the desired effect.  (No blinky)


10)  Or to upload the compiled hex file to your device you will need to start a command window, navigate to you code and enter the following command from the command prompt.

avrdude -v -P com3 -p m1280 -b 57600 -c avrisp -U flash:w:program-name.hex

-v  verbose
-P  Port used for download
-p  product that we are programming (ATMega1280)
-c  avrisp (Protocol used by our board.  THIS is very important, it took me a while and help from fellow enthusiasts at AVR Freaks to figure this one out)
-U  flash:w:program-name.hex write the hex file to flash memory
 
Hopefully this article will have given you enough information to get you started using the ATMega1280 board and in future articles I will share my experiences as I add new devices.  I started my career in Robotics many years ago and to see the changes in the technology since then has been an amazing experience.

I hope this tutorial has helped you and if you have any questions or comments please leave me a comment below.
back to top
Comment on this article
Name
Email