By Lam Phung Version 1.0 Created on May 14, 2008. Last updated January 15, 2010. Latest version of this document is available at: http://www.elec.uow.edu.au/avr
© University Of Wollongong, 2008.
Table of Contents
1. 2. 3. Introduction Installing tools for C programming Using AVR Studio for C programming Creating an AVR Studio project Compiling C code to HEX file Debugging C program using the simulator Downloading and running HEX file on AVR board 2 2 3 3 5 6 8
3.1 3.2 3.3 3.4
1. Introduction
This tutorial provides information on the tools and the basic steps that are involved in using the C programming language for the Atmel AVR microcontrollers. It is aimed at people who are new to this family of microcontrollers. The Atmel STK500 development board and the ATMEGA16 chip are used in this tutorial; however, it is easy to adopt the information given here for other AVR chips. This tutorial requires the following: • the AVR Studio produced by Atmel, • the WinAVR package by Sourgeforge WinAVR project, and • an STK500 development board produced by Atmel.
2. Installing tools for C programming
To work with the Atmel AVR microcontroller using the C programming language, you will need two tools: AVR Studio and WinAVR. Both tools are free at the links given below. • AVR Studio is an integrated development environment that includes an editor, the assembler, HEX file downloader and a microcontroller emulator. AVR Studio setup file and service packs are available at http://www.atmel.com/dyn/products/tools_card.asp?tool_id=2725 • WinAVR is for a GCC-based compiler for AVR. It appears in AVR Studio as a plug-in. WinAVR also includes a program called Programmer’s Notepad that can be used to edit and compile C programs, independently of AVR Studio. WinAVR setup file is available at http://winavr.sourceforge.net/ Installing these tools is easy: just download and run the setup files, and accept