CSEP567 PreLab 2: "One-Minute Timer"

Objectives

Create a device that will count from 00 to 59 on two 7-segment led displays at a rate of 1Hz. When the counter reaches 59 it should wrap around and start counting from the beginning. There will be an example setup in the lab that you can use as a reference.

In this lab you will learn the following:

Reading

Helpful Hints

Resources

Task: Create a BCD Counter in Assembly

Write a program in assembly that will count from 00 to 59 on two 7-segment led displays (one will be the tens digit and the other will be the ones digit). Implement a lookup table in program memory to convert a 4-bit nibble (in binary) to a decimal number.  Use this skeleton program as a starting point.

Requirements:

  1. Use a lookup table in program memory to store the constants needed to generate the 10 digits ('0'-'9') on a 7-sement LED. You should have determined these constants by the end of Lab 1. You will need to use the LPM instruction to load the constant from program memory. NOTE: The ATmega16 uses 16-bit instructions even though it is an 8-bit processor; therefore, the 256th instruction is actually located at memory address 512 and 513. Keep this in mind when declaring your constants in program memory. The code/instructions are two bytes wide (16 bits) but when the program accesses the program memory it can only access one byte (8 bits) at a time causing the number of addresses to be doubled.
  2. The decimal point segment should toggle on every change of counter value.
  3. Counting should happen at 1 Hz and should be achieved through the use of a delay loop. Your counter should count at a rate as reasonably close as possible to 1 Hz since you know how many cycles each instruction takes to execute. You can use the 'nop' instruction to fine tune where necessary.


    Question 1: Prove that you are counting at a rate of 1Hz through calculations by using the number of cycles each instruction takes. In the case of branches where a variable number of cycles may result, you may assume that the most frequent branch is always taken. Please show your work and list any assumtions you made.

Deliverables

Come to lab with:

Use the simulator in AVR Studio 4 to verify that your code is working and the timing is correct. To set the frequency/speed of the processor in the simulator goto the AVR simulator options in the debug menu. (The cyrstal we are using is not present so you will need to some math to make adjustments to get your timings to work out correctly) When simulating the I/O tab gives very useful information such as the values of the registers, I/O, etc (If you don't see the I/O tab on the left toggle the workspace window button to display the project, I/O, and info tab). The "Processor" item in the I/O tab keeps track of the cycles used and the amount of time the processor has run.