Lab 1: Basic Assembly Programming and Debugging using AVR Studio and ATmon

Outcomes

  • Become familiar with the AVR Studio and ATmon development environment for the Atmel ATmega32 system.
  • Learn the steps involved in creating, assembling, loading, running/simulating, and debugging programs for the Atmel system.

Overview

The purpose of this lab is for you become more familiar with the embedded software development tools that you will be using throughout the quarter - specifically, the AVR Studio IDE and the ATmon downloader/debugger.

In this lab, you'll reinforce your knowledge of the steps involved in creating, assembling, loading, running/simulating, and debugging programs for the Atmel system.

Each student must work independently on this project.

Lab activity

Create a project (e.g. lab1) in AVR Studio. Make sure you select the appropriate type of project when you run the Project Wizard:

Project Wizard

Debug Platform and Device

Select Assembler Options from the Project menu and check Create List File as shown below:

Assembler Options

You'll have an empty .asm file to begin with. You may use the program demonstrated in lecture as a starting point. Observe the following assembly language coding conventions when writing your program in order to avoid a mangled mess of code:

  • Directives and labels begin in the left-most column.
  • Instructions begin in a second column; use the dialog under Tools/Options/Editor to set the tab width to 10 (the default is 4).
  • Operands begin in a third column
  • Instruction comments begin in a fourth column; assembly language programs must be heavily commented.

Following this coding convention, create a program that does the following:

  1. Place comments at the top of your .asm file similar to those at the beginning of the Lab 0 example code.
  2. .include the file m32def.inc for symbolic definitions that you will use subsequently in your program; surround this directive with .nolist and .list to suppress it from appearing in the lab1.lst file.
  3. Equate a symbol program_start to the value 0x2a. This symbol represents where your program actually starts in Flash memory.
  4. Use .cseg and .org directives along with the RJMP instruction to set the value of the Reset Vector to program_start (via the symbol, not the actual value 0x2a).
  5. Use .org and the program_start symbol to define your program's starting location in Flash memory.
  6. Define a symbol named counter for register R20; use this symbol instead of R20 everywhere in your program. Initialize the value of counter to 0.
  7. Define a symbol named one for register R21. Initialize the value of one to 1.
  8. Set the DDRB to configure PORTB as a digital output port. The symbol DDRB is defined in the m32def.inc file, so you don't have define it yourself.
  9. The tricky part: Create instructions that repeatedly add one to counter, and then output the value of counter to PORTB in order to illuminate the LEDs. Use a label named repeat to form the jump destination for beginning of the loop (but don't loop back all the way to the beginning of the program). This loop should execute forever.

Simulation and Debugging in AVR Studio

Build the project in AVR Studio. Once built successfully, set a breakpoint on the first instruction in your program. Next, select the “Start Debugging” command from the Debug menu; the program will start to execute, but will stop on the breakpoint you just set. Before continuing, set the clock frequency of the simulator by selecting “AVR Simulator Options” from the Debug menu. In the dialog that appears (below), select 8MHz as the clock frequency since the simulator does not permit you to select 16MHz. Note that the simulator will run only half as fast as the actual 16MHz processor on your development board.

Simulator Clock Frequency

Test-run your program in AVR Studio debugger in order to verify that it runs as expected. Demonstrate the program to your instructor, or ask for help if you're having difficulty.

Once your program is running correctly, examine the generated list file (lab1.lst) to answer the following questions for your report.

1) How many instruction words does your program comprise?
2) What is the address the Assembler assigned to the repeat label?

Use the built-in debugger to single-step your program. In the I/O View, expand the Processor icon to display the Stop Watch. Determine the answer to the following questions for your report:

3) How many CPU cycles does your loop take to execute?
4) How many microseconds does your loop take to execute?

Examine SREG in the I/O View. The SREG display can be expanded to show each of its individual bits. Single-step your program to answer the following questions:

5) What is the value of counter when the “H” bit of SREG is first set?
6) What is the value of counter when the “V” bit is first set?
7) What is the value of counter when the “N” bit is first set?
8) What is the value of counter when the “Z” bit is first set?
9) What is the value of counter when the “C” bit is first set?

Note: The counter referred to in questions 5-9 refer to the label defined in your program, not the cycle or program counter.

Execution and Debugging using ATmon

Download your program to the microcontroller using ATmon with the commands learned about in Lab 0. The program should begin running immediately. Observe the LEDs.

10) Why do the LEDs all appear to be lit continuously?

At the ATmon prompt, type the following command:

FD 0 100 - this displays the first 100 bytes (not words) of Flash memory beginning at address 0.

BRK 0xnn, where nn is an instruction address in the middle of your loop. The BRK command sets a breakpoint in your program at that address. You should now be able to press F5 to single-step the program. Observe the LEDs.

At the ATmon prompt, type the following command:

OE PORTB - this opens a small window containing the bit values of PORTB

OE SREG - this opens a similar window containing the bit values of SREG

E R20 - this displays a window showing R20's contents.

For more on ATmon is located in the ATmon User Guide.

Demonstrate the single-stepping program and the output windows to your instructor.

FAST Data

You should indicate how much time (in minutes) you spend on this assignment in the FAST database. You are encouraged to log your activity as you work on the project. At a minimum, you should log all of the time spent on this assignment before the due date given above. All time spent on this assignment should be entered into the week 2 column (even if you worked on it in week 1 or 3).

Lab Deliverables

You should follow your instructor's instructions for your lab submission.

Taylor

If you have any questions, consult your instructor.

ce2800labs/lab1.txt · Last modified: 2009/06/03 11:22 (external edit)
 

This website is not owned or managed by the Milwaukee School of Engineering.

© 2003-2010 Dr. Christopher C. Taylor, et. al. • Office: L-343 • Phone: 277-7339 • npǝ˙ǝosɯ@ɹolʎɐʇ • -> RSS <-