This page has resources to get started on using the Atmel ATmega128 microcontroller. You
will find a sample schematic, board layout, and source code, as well as
information about the free software tools you can use to create your
own board.
The ATmega128 is a popular microcontroller for its
generous program memory and RAM, as well as the typical hardware
features you'd expect from an advanced microcontroller. The ATmega128
is also more expensive than your typical microcontroller, and is best
suited for more advanced tasks such as a robot controller or an
embedded webserver. If you don't
need all of the features of the ATmega128, I recommend you check out
the ATmega8.
Your first stop should be the ATmega128 product
datasheet (found on Atmel's website). Download it and make friends with
it. Then navigate to BDMICRO's
website and check out the MAVRIC-IIB. I highly
recommend that board for any project it will fit in. Of course, you can
design your own board (possibly for less), but the MAVRIC-IIB board
also makes a great starting point when deciding what features you would
like to include on your board. BDMICRO provides great documentation on
their website, as well as excellent code samples. Finally, browse to www.avrfreaks.net to get the
software and other resources for programming the Atmel series.
You have some sample code now, but how do you compile
it?
How do you get the compiled program into your Atmel? You'll find plenty
of options at the avrfreaks website,
possibly too many. I recommend you
start with the gcc-avr compiler. You can get it as part of the WinAVR package. WinAVR
combines the most useful programming tools in a package for Windows. On
Linux, you can use crossdev along with avr-libc to build for the
AVR
series, just as you would use the standard gcc tools to build
applications
for your computer. Be sure to check with your distribution to see if
there's already a prepackaged solution for you. For example, Gentoo
users emerge crossdev, then
crossdev --target avr to build the avr environment.
Linux users usually already have a prefered coding environment that
they use for gcc. That same environment (vim, emacs, etc) will work
just
fine when coding for the AVR series. Commercial compilers also exist,
but I think you'll
find the gcc-avr compiler more than adequate.
The Atmega128 is usually programmed by In-System
Programming (ISP) or with the JTAG interface.
ISP is a great low cost solution to programming your microcontroller.
You can get an ISP programming cable around $12 from Spark Fun Electronics that works
with the free program, PonyProg2000,
available on Windows and Linux.
Both serial and parallel versions are available. If you don't have a
serial port on your computer, don't bother with a USB to serial adapter
- more than likely it won't work! With the ISP programmer you can read,
program, and change fuse (config) bits on your microcontroller. The ISP
cable, however, does not allow for debugging. For debugging your code
interactively, you'll need to use the JTAG interface. Spark
Fun also has JTAG programmers. JTAG programmers do everything ISP
programmers can do, and also
allow stepping through your code. The JTAG programmers start at around
$50, but some work on USB in case you have a laptop without those
precious ports. I recommend you start with the ISP cable, because it's
inexpensive. Output to an LCD screen for debugging. An LCD screen is
more useful on a robot where your controller board cannot always be
tethered to your computer for debugging:
LCD screens are inexpensive, you can find them for
less than $10 with a nice backlight. Look for Hitachi
HD44780
compatibles with an LED backlight, positive contrast voltage, STN type
display. Those work and look the best. Here is some source code for a
Hitachi compatible display:
lcd.c source file
lcd.h source file
The source files can be included in your projects and
compiled by the gcc-avr compiler. Please read the source carefully and
change the PORTA define statement to the port your display is attached
to on your ATmega128.
June 18, 2005 William Summerfield Dubel IV