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.
Create a project (e.g. lab1) in AVR Studio. Make sure you select the appropriate type of project when you run the Project Wizard:
Select Assembler Options from the Project menu and check Create List File as shown below:
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:
Following this coding convention, create a program that does the following:
.asm file similar to those at the beginning of the Lab 0 example code..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. program_start to the value 0x2a. This symbol represents where your program actually starts in Flash memory. .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). .org and the program_start symbol to define your program's starting location in Flash memory. counter for register R20; use this symbol instead of R20 everywhere in your program. Initialize the value of counter to 0. one for register R21. Initialize the value of one to 1. m32def.inc file, so you don't have define it yourself. 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. 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.
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.
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.
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).
You should follow your instructor's instructions for your lab submission.
If you have any questions, consult your instructor.