First page Back Continue Last page Overview Text
Reading the keypad is a two step process. The first step is to send a hex value to Port P. The second step is to read the resulting hex value from port P. Port P must be set up with the upper four bits as output and the lower four bits as inputs (send $F0 to Port P direction register at address $57). You also need to enable the pull up resisters of port P by sending $2 to port P control register at address $54.
You need to write to Port P (Port P address = $56) four times (one for each row of keys). Port P should be read back each time that data is written to it in order check the state of all 4 columns.
To read the keypad, first send a hex ‘7’ (since you must output 8 bits, send 70 hex) to the upper four bits of the port, and then read the lower four bits of the port. Writing a ‘7’ puts a zero in the “1 2 3 C" row (see keypad diagram on the next slide). If any of these keys are pressed, a corresponding 0 will be found on one of the Key 4 to Key 1 outputs. To read the "1 2 3 C" row, send the value $70 out on port P (The lower nibble of the value sent out is a don't care since the lower nibble of the port is configured as an input-see notice at end of the laboratory). If the ‘1’ key is pressed, the value read from the port will be a $77. If no key is pressed a 0xf will be read back from the lower nibble. To scan the entire keypad, the values $70, $b0, $d0, and $e0 should be sent out successively on the upper nibble. Put these values in an array and send them to port P one at a time.