----=_3c66a92e16275121046c3949.MFSBCHJLHS Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable David Harris wrote... >CHALLENGE: can you scan a keyboard, and run an LCD display with only=20 >8 pins/bits =3D 1 port -- without extra active hardware? The "matrix voltage divider" method I posted yesterday may have been cute, but it's awfully cheap 'n dirty: it doesn't resolve multiple simultaneous keypresses; it requires a PIC with at least a 10-bit A/D converter; the voltage levels it outputs for each keypress cannot be known precisely at design time because of resistor tolerances; and the voltage levels aren't distributed evenly over the A/D converter's input range. In sum, this voltage divider scheme makes extremely efficient use of hardware but it's awfully inconvenient to use. The attached diagram shows another possible solution. =20 This one scans a 4x4 matrix keypad with only four PIC digital I/O lines, while allowing use of those same 4 lines to carry LCD data during display operations. =20 In coming up with this scheme, I set the following requirements to force an absolutely "clean" solution: a) No external active components (transistors or ICs) are allowed. b) Keypresses (even multiple simultaneous keypresses) during LCD operations must not interfere in any way with the LCD; c) Multiple simultaneous keypresses must not cause direct shorts between PIC port pins while the pins are being used as outputs;=20 d) All multiple keypresses must be resolved correctly;=20 e) No PIC special functions can be used, allowing the method to be used on any PIC with enough I/O pins; and f) The method must not place any restrictions on which port pins can be used for the keypad and LCD, nor may it require any special programming "tricks" to keep the keypad and LCD from interfering with one another. To summarize, the method I'm proposing makes dual use of the PIC port pins during keypad processing: they're used as outputs when strobing the keypad row lines, and as inputs when reading the keypad column lines. During the turnaround period in each scan, between strobing and reading, capacitors are used to store the keypress state. This scheme requires four PIC pins for the keypad, 4 small capacitors, 4 signal diodes, and 4 resistors. I usually use Port D for interfacing my LCDs, so I chose RD4 through RD7 to use for the keypad and for LCD data lines D4-D7; but this is an arbitrary choice and any other convenient arrangement will work just as well. The arrangement I chose leaves RD0 through RD3 for the LCD's R/W, RS and E lines, plus one Port D pin left over for other uses. Actually, I don't normally read from the LCD; I just tie the R/W line low permanently. So for me, this arrangement allows a 4 x 4 keypad and a character LCD module to operate from only 6 PIC I/O pins with no external chips. Referring to the attached diagram, here's how the scanning process for each keypad row line works. For this example, assume we want to check the keys connected to matrix keypad row line X1: 1. First, set RD7:4 as outputs and drive them HIGH to pre-charge column storage capacitors C1-C4. 2. Wait about 10 microseconds, then set RD7:5 as inputs, leaving RD4 as an output. 3. Output a LOW on pin RD4; this discharges the storage capacitors associated with any keys that are pressed along keypad row X1, while leaving the remaining capacitors charged. 4. Wait about 40 microseconds, then set pin RD4 as an input. 5. Read Port D to obtain the key states. Any keys pressed along the X1 row line will be indicated by 0's in the Port D bit positions corresponding to their associated column lines Y1 through Y4; unpressed keys will be indicated by 1's in their respective bit positions. 6. Save the Port D key row data in memory somewhere. 7. Go back to Step 1 and repeat for the next keypad row line. Repeat until all four keypad row lines are done. The secret to this scheme's success is that in between Step 4 and Step 5 above, storage capacitors C1 through C4 hold the key states. =20 The only programming precaution needed with this scheme is to take care not to allow too much time to elapse between Step 4 and Step 5; otherwise the voltage on capacitors C1 through C4 might change enough from port pin and diode leakage currents to affect the results. So if interrupts are used, they are best disabled during keypad scanning. The only precaution needed in arranging the hardware is to refrain from using any of the keypad lines for the LCD's E strobe. Component functions are: R1 through R4 isolate the LCD from the keypad, and also prevent multiple keypresses during LCD operations from shorting any of the PIC outputs together. Fault current in that condition is limited to under 1 milliampere. C1 through C4 store key state, as described above. D1 through D4 isolate the keypad row lines from the column lines; a PIC port pin can charge its associated storage capacitor through the intervening diode, but it can discharge the capacitor only through a pressed key. Hope this wins... Dave Dilatush ----=_3c66a92e16275121046c3949.MFSBCHJLHS Content-Type: image/gif; name=keypad.gif Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename=keypad.gif R0lGODlhpgGMAYAAAAAAAP///ywAAAAApgGMAQAC/oyPqcvtD6OctNqLs968+w+G4kiW5omm6sq2 7gvH8kzX9o3n+s73/g8MCofEovGITCqXzKbzCY1Kp9Sq9YrNardIgNebAD8Aje/hS+aq1+xMGpF+ M+Tws+FNb+v3fLo8X6cA+MdXaLjmFzi3MKh4+AgplWhXxmhJGZmpqZQXN7Z4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5O3sskjd3k0uwR681nJX5XFz5W4j5VvO5V0Oni3t5RMCcv5d2iR8sClu1Wj+ drpph48b5oP9Kx4ev0sj5z1N587BiFX6OkhL4G/ubOJz45KdNfkF6LYh6MQA30Dq55gtPDwDl47e /ugYWzEjvo9kbtuuLdodC+AwvuhB+M7Pvd6d/kefbuR6LeqeruRRvuSn7odPPtqZzuobC85gzOSx DsquTuvYbev0Kcq5fuS7bplFztywDuyjnursjezFjupBPuyhruyVSerNXuvPDrrH3tzJTu2BOutB Ld7ZLuyr/uvB7e0Jy8/SruvjHt7XHe5nie7BXu7gburt/u6qTu/YLu/pHtrOru/3Xtjibu/Tzu+W 9u31fu0Bjz9UPsx288JWnvB4ZfAPD/ER7x9YbrhmXvFnbcsYL/Ebz/EdnxMWf/BgrrJqHlfT7PEn j/Ipn691voiz6fIqD/MxL/MzT/M1b/M3j/M5Ca/zO8/zKl8AAAA7 ----=_3c66a92e16275121046c3949.MFSBCHJLHS-- -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu