0% found this document useful (0 votes)
72 views13 pages

00 - Getting Started

This document provides instructions for installing and using AVR Studio software to develop and debug programs for AVR microcontrollers. It explains how to [1] download and install AVR Studio 4.19, [2] create a new project for an ATmega2560 microcontroller, and [3] use the simulator to build, load, and debug simple assembly programs by single-stepping or using breakpoints.

Uploaded by

Victor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views13 pages

00 - Getting Started

This document provides instructions for installing and using AVR Studio software to develop and debug programs for AVR microcontrollers. It explains how to [1] download and install AVR Studio 4.19, [2] create a new project for an ATmega2560 microcontroller, and [3] use the simulator to build, load, and debug simple assembly programs by single-stepping or using breakpoints.

Uploaded by

Victor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Getting Started

Installing AVR Studio


This is the software we will use to develop and compile AVR programs. It includes an IDE, an
assembler, and a simulator.

AVR Studio 4.19 can be downloaded from


http://www.cse.unsw.edu.au/~cs2121/AVR/AvrStudio4Setup.exe

Earlier or later versions of AVR Studio or Atmel Studio may not work with the Atmega2560 chip, so
use them at your own risk.

Building and Debugging

Once installed, launch AVR Studio from the “AVR Studio 4” shortcut.
On the welcome screen, click the “New Project” button.

Choose “Atmel AVR Assembler” as the project type and enter a name for the project, then click
“Next”.

On the lab machines, the new project is created in program files by default and gives a permission
error. Instead, click the “…” next to the location box and select the “Z:” drive or the desktop to
create your project.
Choose “AVR Simulator 2” as the Debug Platform and “ATmega2560” as the Device, then click
“Finish”.

The lab machines have an older version of AVR Studio installed, and give an error when
you select “AVR Simulator 2”. Instead select “AVR Simulator” and “ATmega2560”.

Now that you’ve created the project, enter the following program into the text editor window.
.include "m2560def.inc"

start:
ldi r16, 8
ldi r17, 9

halt:
jmp halt

The “.include” works the same way as C’s “#include”. “m2560def.inc” contains port and register
definitions for the Atmega2560 chip, and should be included at the top of every assembler program.

Next, build the program by pressing “F7” or selecting Build->Build from the menu.
When the build succeeds, it will display an “Assembly Complete” message in the build window.

Next, start the simulator by pressing “Ctrl+Shift+Alt+F5” or selecting Debug->Start Debugging from
the menu.
A yellow arrow will appear next to the first instruction, and the Processor toolbar will appear on the
left. The Processor toolbar contains information about the processor’s internal state, including
register contents.

Click on the “+” next to “Registers” in the Processor toolbar and scroll down to r16. All register
values should be 0x00 initially.
Press “F10” or select Debug -> Step Over in the menu to execute the first instruction.

The yellow arrow will move to the next instruction, and the value of r16 will change to 0x08, and will
be coloured red. Press “F10” again to run the next instruction.
Now r17 has changed value to 0x09 and is coloured red.

End the debugging session by pressing “Ctrl+Shift+F5” or selecting Debug -> Stop Debugging from
the menu.
Breakpoints and the status register
First, enter the following assembly program into the editor.

.include "m2560def.inc"

start:
ldi r16, 200
ldi r17, 100
add r16, r17

halt:
jmp halt

When debugging, the simulator can be told to stop only on specific instructions using breakpoints.
We are going to put a breakpoint on the add instruction.
To add a breakpoint, move the cursor to the instruction you want to stop on and press “F9”, or
select Debug -> Toggle Breakpoint in the menu.

A brown dot will appear in the left margin to show where the breakpoint is. Breakpoints can also be
added by right-clicking the margin where the dot is and selecting “Toggle Breakpoint”.
Start the simulator again by pressing “Ctrl+Shift+Alt+F5”.

Instead of single-stepping, press “F5” or select Debug -> Run from the menu to run until the
breakpoint.
The debugger will stop on the ‘add’ line, instead of stopping on the next instruction.

The state of the status register is visible on the left. At this point, all the boxes are white, indicating
that none of the flags are set. Press “F10” to execute the ‘add’ instruction.
The ‘C’ flag is now black, showing that the carry flag has been set. This happened because the
addition overflowed.

You might also like