ECE 271 LAB 7 Spring 2012 PURPOSE: More flowcharting/programming practice, table lookups, bit operations, using the 7-segment LED display. EXERCISE: Write a stopwatch program. The count is displayed in the four 7-segment LEDs. The program will count as long as PC0 is pushed and will stop counting when PC0 is released. Counting will occur every 1/10 second, so the leftmost three digits gives the number of seconds, and the rightmost digit gives tenths of a second. Pushing PC1 will reset the count. PRELAB DUE WHEN YOU COME TO LAB: FLOWCHART AND ALL YOUR CODE (UNDEBUGGED AT THIS POINT). We will check for this at the beginning of lab. Your data area will include a double byte COUNT (the current time in 1/10ths of a second) and perhaps several other counters. The display portion of the code will require a "Display Mask", a temporary double byte value (TempVal on flowchart), and a display table indicating which segments are lit for a given digit to be displayed. Your program will operate as follows: Clear the counter and initialize register DDRD (PORTD data direction register in memory location $1009) to %00111100, making the middle four bits of this port outputs. Then in a loop do the following: 1) execute the "Display Value" code 5 times taking a total of 1/10 second (each execution of "Display Value" code takes 20 ms), 2) clear the count if PC1 is pushed, and 3) increment the count if PC0 is pushed. Displaying is complicated by the fact that the LEDs can only display one digit at any given time. The digits are therefore continuously scaned, displaying each for a short time (we'll use 5 ms) and then moving on to the next. PORTD (location $1008) controls which digit is currently displayed as follows PORTB bits PORTD pattern Displayed Digit --0-- 00111000 1 (rightmost) | | 00110100 2 (second from right) 5 1 00101100 3 (second from left) |--6--| 00011100 4 (leftmost) 4 2 | | --3-- Write the value to PORTD and then write a bit pattern to PORTB (the LEDs port you have been using) and the given segments of the specified digit will light. Delay (e.g., for 5ms), then display the next digit. Continuously cycle through the digits and all four digits will appear as if they are all lit simultaneously. NOTES: The pattern you write to PORTB indicates which LED segments will be lit for that digit. A data table for this is given on the web page. The "Display Value" flowchart is given on the back of this sheet. You must provide a flowchart for the remainder of the program. Include "Display Value" as a simple block on your flowchart. Code should follow flowcharts exactly. Program comments will reflect what is found in the flowchart. Note that your stopwatch will only count while PC0 is pushed. Such operation is worth 9 points. Ideas for a full 10 points: 1) have the stopwatch change state each time PC0 is pushed. (First press starts, second press stops, etc.) 2) blank the leading zero digits of the display.