Docsity

AVR Studio 4: Assembler and Simulator Tutorial for Electronics Lab IV, Lab Reports of Electrical and Electronics Engineering

Toggle sidebar
bg1
AVR Studio Assembler/Simulator Tutorial
ETEE๎˜ƒ2201๎˜ƒ
Electronics๎˜ƒLab๎˜ƒIV๎˜ƒ
AVR๎˜ƒStudio๎˜ƒver๎˜ƒ4.13Assembler๎˜ƒand๎˜ƒSimulator๎˜ƒ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 to:
1. Execute the AVR Studio 4 Integrated Development Environment (IDE),
2. Type in a program,
3. Assemble the program, and
4. Simulate 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.
Figure 1: LED On Program
Last Updated: January 2008
pf3
pf4
pf5
pf8

Partial preview of the text

Download AVR Studio 4: Assembler and Simulator Tutorial for Electronics Lab IV and more Lab Reports Electrical and Electronics Engineering in PDF only on Docsity!

ETEE 2201

Electronics Lab IV

AVR Studio ver 4.13Assembler and Simulator 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 to:

  1. Execute the AVR Studio 4 Integrated Development Environment (IDE),
  2. Type in a program,
  3. Assemble the program, and
  4. Simulate 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.

Figure 1: LED On Program

Step 1: Open AVR Studio 4 IDE. You should see the program banner shown below:

Figure 2: AVR Studio 4 Banner

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?

Figure 3: AVR Studio IDE

Step 3: Click on the โ€œNew Projectโ€ button:

Figure 4: Welcome Dialog Box

Step 7: Choose AVR Simulator for the Debug Platform and then scroll down the right window to choose the ATmega128 AVR processor as the device

Figure 7: Choose Simulator and ATmega

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):

Figure 8: AVR Studio 4 IDE

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.

Figure 9: Typed Program

Step 10: Save the program. When you save a program, use the Save All button. You are actually saving the complete project when you click Save All. It is also good practice to periodically save your program as you type.

Step 11: Assemble your program. You may do this by selecting Build -> Build (from the โ€œBuild Menuโ€) or by striking the [F7] key:

Figure 10: Program Assembled

Step 15: Single step through your program by striking the [F11] key:

Figure 13: FF sent to Data Direction Register B (all pins outputs)

Figure 14: bit 0 set

Note: The โ€œsbi PortB,0โ€ (sbi is the โ€œset bitโ€) instruction has been executed, although the pointer is pointing at the next instruction. So, bit 0 in PortB is set (equal to 1). It is important to note 2 things:

  1. Pin 0 (PinB0) on PortB has not gone high yet, even though bit 0 in PortB is set. PinB0 will go high as the next instruction is executed
  2. The instruction: โ€œcbi PortB,0โ€ has not been executed yet even though the arrow is pointing to it.

The arrow always points to the next instruction to be executed.

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:

Figure 15: PinB0 is high

Figure 16: PinB0 is low