First page Back Continue Last page Overview Text


After each value is sent to the keypad (data in the four byte array) and port P is read back, call a lookup table routine and check to see whether the value read back from the keypad matches an entry in the table.
The lookup table routine will return an $FF if no matching table entry is found or an index into the table with the value of the key if a key is found.
If no key press is found after all four outputs have been sent to port P and checked, then no key has been pressed during this scan and the software should start over sending the first byte of row data to port P.
If a key is detected, send the decoded key value to Port S (LEDs).
After finding that a key has been pressed, your program should delay in order to debounce the switch. A delay loop of approximately 1 ms should suffice. After this delay, read the switches again and wait for no key to be pressed (a 0xf in the lower nibble). This is easily accomplished by ANDing the upper nibble with 0 to force it low and comparing the result to 0x0f. Another delay is necessary after detecting that the key has been released.
The keypress value can be displayed with four bits. Display the first key pressed on the right four LEDs. Display the next key pressed on the left four LEDs while maintaining the previous value on the right four LEDs. The third key pressed will be written to the right four LED bits, again maintaining the second keypress on the left four LEDs. This can be accomplished using AND, OR and shift operations.

Use subroutines for the code to look up a keypress (previously completed), wait for a key to be released, debounce delays, and write keypress values to the displays.