AVR Studio Tutorial
AVR Studio Tutorial
AVR Studio Tutorial
Tutorial
AVR Studio 4 is a professional Integrated Development Environment (IDE) for writing and
debugging AVR applications in Windows 9x/NT/2000/XP environments. This tutorial assumes
that you have installed AVR Studio 4 on your computer. If you do not have AVR Studio yet, you
may obtain a copy of AVR Studio 4 from one of 3 places:
1. Atmel Corporation: http://www.atmel.com
2. AVR Freaks: http://www.avrfreaks.net
3. Borrow a CD from your instructor
This tutorial will guide you through the steps required for:
1. Executing the AVR Studio 4 Integrated Development Environment (IDE),
2. Typing in a program,
3. Assembling the program, and
4. Simulating a program
The first program you will enter is shown below (Figure 1). This program will initialize the B
and D ports on the ATMega128 AVR processor and then turn on a single LED connected to
PortB, pin 0.
;========================================================
;Project #1
;Written by: Steve Kuyath
;Date: 5/21/2007
;ver: 1.0
;file: C:\Documents and Settings\Stephen Kuyath\My Documents\AVR\Pr1
;Device: ATMega128
;========================================================
.nolist
.include "C:\Program Files\Atmel\AVR Tools\AvrAssembler2\Appnotes\m128def.inc"
.list
;===========================
; Declarations
;===========================
; Start Program
rjmp Init
;============================
Init: ser temp
out DDRB,temp
out DDRD,temp
clr temp
out PortB,temp
out PortD,temp
;============================
Start:
sbi PortB,0
cbi PortB,0
rjmp Start
Step 1: Open AVR Studio 4 IDE. You should see the program banner shown below:
Step 2: When IDE opens, you will see the programming and simulator environment as well as a
dialog box (Figure 3) requesting information: are you starting a new project or opening a saved
project?
Step 4: In the next dialog box, choose the Atmel AVR Assembler as the project type:
Step 7: Choose “AVR Simulator” for the Debug Platform and then scroll down the right window
to choose the ATmega128 AVR processor
Step 8: Click on the “Finish” button. You should then see the IDE (you may have to maximize
the editing window to see the same thing as shown in Figure 8):
Step 9: Type in the program as shown in Figure 1. Note the color-coded text. This is done
automatically by the IDE and helps you to make corrections as you go.
Step 11: Assemble your program. You may do this by selecting “Build” from the “Build Menu”
or by striking the [F7] key:
Step 12: Continue assembling and correcting errors until the program assembles without error
(note the green dot in the lower window and the comment that states: “Assembly complete, 0
errors, 0 warnings”) you are ready to simulate.
Step 13: Simulate the program. To start the simulator you may choose “Start Debugging” from
the “Debug Menu” or you may click on the arrow button as shown below:
Step 15: Single step through your program by striking the [F11] key:
Step 16: Continue stepping through the program until you are sure that the program is executing
as designed.
Note: The next few screens may be a little confusing because the program sets bit 0 in PortB and
then immediately clears bit 0 in PortB. The simulators shows this, but shows that bit 0 on PinB
(the actual pin on the Atmega128) is one cycle behind bit 0 in PortB: