ECE 271 LAB 8 Spring 2012 PURPOSE: More flowcharting/programming practice, using a keypad, subroutines. EXERCISE: Write a password entry program. A 4x4 keypad will be connected to the EVBU board. Your program will wait for a sequence of four keys to be pressed and will then display one of two patterns on the LEDs for two seconds, one meaning "correct entry" and one meaning "incorrect entry". It will then loop back and wait for a new password. "Scanning" the keypad will be done in a subroutine called "KEYSCAN". This routine will return the key pressed (see numbering below) or zero if no key is currently pressed. A flowchart for the subroutine is given on the back of this page. See the book and class notes for further information on using subroutines. The keypad is hooked up to "PORTG". Unlike PORTA through PORTE, this port is not actually on the HC11 chip, but is on an external chip. Whereas, PORTA through PORTE are at addresses around $1000, PORTG is at $6200 and its data direction register, DDRG, is at $6202. PORTG is hooked up to the keypad as follows: Output Key Bits Number 0 | 1 2 3 4 1 | 5 6 7 8 2 | 9 10 11 12 3 | 13 14 15 16 ------------ 4 5 6 7 Input Bits BITS 0 through 3 will be outputs which select a row to scan. We will drive them one at a time. Bits 4 through 7 are inputs. For each row, we will scan the inputs to see if the key at a given row/column is pressed. See class notes for further information. Data for your main program will include: the password string (four bytes - you can use "fcb" to define the password during download), "Current" (a double byte pointer to the current password digit being checked), and an error flag. Your data area for the subroutine will include: a ScanPattern, ThisKey, CurrentKey, RowNum, ColNum, and ThisRow (all are single bytes). The main program will first initialize the stack pointer ($DFFF) and set the data direction register for PORTG (%00001111). Then in an infinite loop it will do the following: Set "Current" to point to the first entry of the password, clear the error flag, wait for all keys to be released (continuously call "KEYSCAN" until it returns zero), then wait for a key to be pressed (continuously call "KEYSCAN" until it returns a nonzero value), compare the returned key to the value pointed to by "Current", set the error flag if there is a mismatch, increment "Current" (to point to the next password entry, if "Current" is not yet past the end of the password table, then branch back to the "Wait for key release", otherwise display one of two patterns for two seconds depending on if the error flag is set. Branch back to the beginning of the infinite loop when done in order to wait for a new password. Doing the above will get you 9 points. For 10 points do at least 10% more... 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.