Dwayne Reid wrote... >At 11:09 PM 2/13/02 +0000, Dave Dilatush wrote: >>Dwayne Reid wrote... >> >> >Close, except turn the diodes around. >> >>The diodes are connected properly. >> >>If you go back and read my earlier post, which explains in detail how >>the circuit operates, that should clarify things. > >Hmm - I don't seem to have received that post. I had assumed your post = was >in response to the posts I made on the 9th and 11th - almost the same >circuit, except that the diodes in my version are reversed with respect = to >yours, and I have pullups on both the rows and columns. No, the post I was referring to was from the day before, in reply to the OP. Here's the text: To: PICLIST@MITVMA.MIT.EDU Subject: Re: [PIC]: CHALLENGE: 4x4 keyboard and LCD with 1 port =3D 8 = bits =46rom: Dave Dilatush Date: Sun, 10 Feb 2002 17:09:02 GMT 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. -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.