??? 07/26/06 06:01 Read: times Msg Score: +1 +1 Good Answer/Helpful |
#121054 - In minute detail Responding to: ???'s previous message |
Richard Erlacher said:
You have 16 switches in the cited example, organized as four rows and four columns. Here's the picture again: ![]() Note that the rows are connected to the high nibble (most-significant 4 bits) of P1, and the columns to the low nibble. Note also that each column has a pull-up resistor. ... writing all '1's (0FF in hexadecimal) to, in this case, P1. Remember that a standard 8051 port pin has an open-drain driver, so wiriting 1 to a port pin turns the driver off; and writing 0xFF to the whole port turns all the drivers off. ... you write a '0' to one, and only one, of the rows, wiriting 0 to a port pin turns the driver on, which pulls the line down to 0V in sequence, e.g. 0EFh, followed by 0DFh, followed by 0BFh, followed by 07Fh It may be easier to see if we write those numbers in binary: 0EFh = 1110 1111 0DFh = 1101 1111 0BFh = 1011 1111 07Fh = 0111 1111See how the zero "scans" across the top nibble? ... read the value on P1 after the next timeout, you'll only see the value you've written, unless a switch is closed When a switch is closed, it connects a row to a column: As Steve said initially, because only one row is ever at zero at any given time, you know which row it is! And you know which column it is. Only one switch exists at the intersection of each row & column - so knowing the row & column identifies which individual switch is pressed! If it appears in more than one row, then you've probably struck more than one key. |