The purpose gain experience with the hardware interrupt and timer/counter subsystems.
In this lab, you will design, code, assemble, simulate, download and run a program. Your program should make it appear as if two programs are running simultaneously on our board:
You should use your code from lab 3 to implement the functionality for the first program.
The functionality for the second program should be implemented by making use of the interrupt and timer/counter0 subsystems. The LCD should display a decimal value between 0 and 99. A 0 should appear approximately one second after a 99 (counter value wraps around at 99).
Note that your program should count up from 0 to 99 in decimal. This means that you must display "10" and not "A" (the hexadecimal equivalent). The count value should be Binary Coded Decimal (BCD). Basically we need to ensure that if we add 1 to 9 we get "10" and not "A". We can do this using the following fairly involved algorithm:
Many CPUs have an instruction called Decimal Adjust for Addition (DDA) that does this for us. However, the ATmega32 has a RISC (Reduced Instruction Set Computer) type architecture and doesn't provide this instruction. For this assignment, you may use this function to handle the correction for BCD.
You must use the Timer/Counter0 to provide a delay of approximately 1 second between counter increments. (Your program should take between 97 and 103 seconds to count from 0 to 99.) Recall from lecture that the maximum time between overflows (counting from 0 to 255 in TCNT0) is 32.768ms. As a result, the ISR for the timer overflow interrupt will be called every 32.768ms. Within the ISR you'll need to keep track of when to actually implement the count that is displayed on the LCD (and then display it). To do this, you'll need to keep track of two counts: a) counter for how many times to run the ISR without incrementing the LCD counter and b) the LCD counter. Keep in mind that you'll need to store these values in SRAM so that they are available to you the next time you enter the ISR.
Most of the code for this lab should already be written. You'll need to write code to configure the interrupt and timer/counter subsystems. You'll then need to write the ovf0ISR function that handles the overflow timer interrupt.
Prior to entering the room, you must submit a documented lab7.lst file using the online submission form. The file should contain a complete solution for this lab assignment except that your ovf0ISR function can just have a return from interrupt instruction. The program that you submit as part of the pre-lab should run on your board but will not show the updates to the LCD.
You must demonstrate your program working on your board.
You should submit the documented .lst file for your program using the online submission form.
In addition to the standard documentation, your source file should contain a couple of sentences that describe one thing that you discovered about the interrupt and/or timer/counter subsystems that you learned but didn't need to know in order to complete the assignment.
Also, you must log the time you spent on this assignment (including the pre-laboratory activity) in FAST (in the week 8 column).
This assignment is based on a similar assignment developed by Prof. Bill Barnekow.
© 2001-2007 Dr. Christopher C. Taylor | Office: L-343 | Phone: 277-7339 |