Searching \ for '[PIC]: CHALLENGE: 4x4 keyboard and LCD with 1 port' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/io/lcd/pic.htm?key=lcd
Search entire site for: 'CHALLENGE: 4x4 keyboard and LCD with 1 port'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: CHALLENGE: 4x4 keyboard and LCD with 1 port'
2002\02\09@140945 by dpharris

picon face
Hi-

I was hoping that I could do both a 4x4 kb and an LCD with only one register.
However, I do not think it is possible - although I wouldn't put it past some of
the people on this list comig up with a solution.  You need 4 outputs to scan
the kb, and 4 inputs to read the kb.  The LCD needs 4 bits data, a register
select bit, and a control bit.  As I see it, you start messing up the display if
you try to multiple use the pins.  Best I can do is  one port and one extra
line, so...

CHALLENGE: can you scna a keyboard, and run an LCD display with only 8 pins/bits
= 1 port -- without extra active hardware?

David H

Edson Brusque wrote:

{Quote hidden}

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservKILLspamspam@spam@mitvma.mit.edu with SET PICList DIGEST in the body


2002\02\09@154701 by Dave Dilatush

picon face
David Harris wrote...

>CHALLENGE: can you scan a keyboard, and run an LCD display with only 8 pins/bits
>= 1 port -- without extra active hardware?

How about operating a keypad with nothing more than a single PIC A/D
input pin?  
The diagram below shows how this can be done, by connecting the
row/column lines of the keypad to resistors so that each key (the X's in
the diagram below) results in a different resistance value.  This
resistance is connected, along with a load resistor (the 22K shown
below), in a voltage divider between Vcc and ground; each key gives a
different voltage, thus a different A/D reading.

I didn't dream this up on my own, BTW, so I can't take "challenge"
credit for it; I saw it about a year ago in the Design Ideas column in
one of the electronics rags (either EDN or Electronic Design, I forget
which).  It should work, even if it is a little unusual...


    X-------X-------X-------X----------+--Vcc          |       |       |       |          |              |       |       |       |          |              X-------X-------X-------X---4.7K---+               |       |       |       |          |              |       |       |       |          |              X-------X-------X-------X---10K----+               |       |       |       |          |              |       |       |       |          |              X-------X-------X-------X---15K----+             |       |       |       |                         |     1.2K    2.4K    3.6K                        |       |       |       |                         +-------+-------+-------+--> To PIC A/D Input                               |                                                22K                                                |                                                GND                                                                  Hope this helps...

Dave

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservspamKILLspammitvma.mit.edu with SET PICList DIGEST in the body


2002\02\09@155112 by dpharris

picon face
Hi-
Hey this is great!  Can you push multiple keys?  That should be possible, but we
would need a 16 bit A/D.
David H

Dave Dilatush wrote:

{Quote hidden}

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email EraseMElistservspam_OUTspamTakeThisOuTmitvma.mit.edu with SET PICList DIGEST in the body


2002\02\09@164421 by Dave Dilatush

picon face
David Harris wrote...

>Hey this is great!  Can you push multiple keys?  That should be possible, but we
>would need a 16 bit A/D.

Multiple keys pressed simultaneously is a problem with this design.  
For example, if you press the top left key in the diagram I posted then
the output of the voltage divider is Vcc no matter what other keys you
push.  Pushing other combinations of keys together will give you odd
voltage levels that could be misinterpreted, and I don't think any
amount of A/D resolution could fix that, especially since the resistors
themselves have tolerances and an allowance has to be made for that.

But hey, you can't get much simpler...

Dave

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservspamspam_OUTmitvma.mit.edu with SET PICList DIGEST in the body


2002\02\09@165136 by Jinx

face picon face
> How about operating a keypad with nothing more than a
> single PIC A/D input pin?

Dave, I was thinking along similar lines last night for multiple
toggle switches, so thanks for bringing it up

http://home.clear.net.nz/pages/joecolquitt/mixer.html

One function of the PIC is to produce two pairs of antiphase PWM,
the properties of which are set by the pots and switches

As you can see, there are just four switches as part of a voltage
divider. Although the number of switches can be increased, the
resolution of the ADC would eventually need to be increased
also. The reason is because this is slighly different to the 4x4
question, as I need to detect any combination of switches from
"all off" to "all on", ie 16 clear and distinct values (as David
Harris has mentioned). If they were 0x10 apart coming from the
ADC that would be wonderful. I've done similar work before so
not expecting any major problems

Although it's not needed for this job, I did wonder how many
switches (or keys) could be used if that spare 4051 input was
employed. I may have put this up as a challenge at some time,
so now seems a good opportunity. As yet I've not tested any
values for the 5 resistors in the circuit

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email @spam@listservKILLspamspammitvma.mit.edu with SET PICList DIGEST in the body


2002\02\09@185259 by Jinx

face picon face
> David Harris wrote...

>CHALLENGE: can you scan a keyboard, and run an LCD
> display with only 8 pins/bits = 1 port -- without extra active
> hardware?

Yes, with a 4-bit LCD (7 i/o lines needed) and a k/b matrix
of 4 rows as o/p (ie driven) and 4 columns as i/p. Flip between
port as o/p for the LCD and port as mixed i/o for the k/b. If the
4 row drivers are also the LCD data lines, the s/w should be
able to avoid any unwanted writes to the LCD because of
unwanted conditions on RS, R/W and E caused by key presses.
Might take a little work to idiot-proof but I'm sure it could be done

A routine for a scanned 4x4 is at http://www.piclist.com and has been
discussed on the list some time ago (18 months ?)

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email KILLspamlistservKILLspamspammitvma.mit.edu with SET PICList DIGEST in the body


2002\02\09@194901 by Jinx

face picon face
> 4 row drivers are also the LCD data lines

After a little extra thought, that may not be necessary. For
once the fussiness of an LCD may actually be an advantage

As long as the conditions for a data write to the LCD don't
occur (by choosing which i/o lines are alternately assigned
to the LCD or k/b matrix and how the k/b is scanned), it should
be possible to avoid such a condition for any predicted key
press combination

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email RemoveMElistservTakeThisOuTspammitvma.mit.edu with SET PICList DIGEST in the body


2002\02\09@195329 by Dave Dilatush

picon face
Jinx wrote...

>> David Harris wrote...
>
>>CHALLENGE: can you scan a keyboard, and run an LCD
>> display with only 8 pins/bits = 1 port -- without extra active
>> hardware?
>
>Yes, with a 4-bit LCD (7 i/o lines needed) and a k/b matrix
>of 4 rows as o/p (ie driven) and 4 columns as i/p. Flip between
>port as o/p for the LCD and port as mixed i/o for the k/b. If the
>4 row drivers are also the LCD data lines, the s/w should be
>able to avoid any unwanted writes to the LCD because of
>unwanted conditions on RS, R/W and E caused by key presses.
>Might take a little work to idiot-proof but I'm sure it could be done

I briefly considered an arrangement like this on one of my projects but
rejected it because of three problems which appeared insoluble:

First is the possibility of LCD data corruption if a key happens to get
pressed while an LCD write operation is in progress.  
Second, under the same circumstances two PIC output pins will end up
getting shorted together (by the depressed key) while they're both
outputs, and if they are in opposite states a large I/O pin current will
flow.  While this probably won't damage the PIC it will cause a high
drain on the power supply, which isn't acceptable in my applications.  
The third problem is that the LCD E line can end up getting toggled
during keypad scanning, leading to a false LCD write.

There seemed no way to absolutely, positively prevent these three
problems from occurring, so I gave up on this approach.

Dave

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spamBeGonelistservspamBeGonespammitvma.mit.edu with SET PICList DIGEST in the body


2002\02\09@204319 by Jinx

face picon face
> There seemed no way to absolutely, positively prevent
> these three problems from occurring, so I gave up on
> this approach

Well, I'll defer to your investigations. Personally I think I'd
keep the two functions separate and use either a shift
register for the LCD to free up more lines for the k/b, or
use k/b decoding h/w to free up more lines for the LCD.
The other alternative would be to keep RS R/W and E
entirely separate from any k/b lines. There will be many
ways to accomplish this using h/w and s/w permutations

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email TakeThisOuTlistservEraseMEspamspam_OUTmitvma.mit.edu with SET PICList DIGEST in the body


2002\02\09@211903 by Dave Dilatush

picon face
Jinx wrote...

>Well, I'll defer to your investigations. Personally I think I'd
>keep the two functions separate and use either a shift
>register for the LCD to free up more lines for the k/b, or
>use k/b decoding h/w to free up more lines for the LCD.

That's what I concluded, too.  I ended up using a 74HC138 3-to-8 decoder
to generate my strobe lines (in my case, I needed six of them); they're
pretty cheap parts, about US$0.35 in hundreds.

>The other alternative would be to keep RS R/W and E
>entirely separate from any k/b lines. There will be many
>ways to accomplish this using h/w and s/w permutations

The only one which is critical is E.  RS and R/W can flail away with
reckless abandon all day long, so long is E isn't strobed.

Dave

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email RemoveMElistservspamTakeThisOuTmitvma.mit.edu with SET PICList DIGEST in the body


2002\02\09@214019 by Jinx

face picon face
> The only one which is critical is E.  RS and R/W can flail
> away with reckless abandon all day long, so long is E isn't
> strobed

True, with the proviso that you don't want any interference
to RS and/or R/W from an unpredictable key press at the
time E is strobed, so you'd have to be careful that the i/o
conditions are checked, eg disabling as much as possible
the s/w's k/b functions, before doing so.

But we agree that a h/w solution is probably more sensible
than what could turn out to be a fruitless academic exercise

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservEraseMEspam.....mitvma.mit.edu with SET PICList DIGEST in the body


2002\02\10@001605 by M. Adam Davis

flavicon
face
You'd need to add at least one more resistor to have it recognize
multiple keypresses, and even then you'd have to carefully choose your
resistor values.

Also keep in mind that the A/D shouldn't see more than 10k resistance,
or you won't get fast accurate readings.

-Adam

David Harris wrote:

{Quote hidden}

--
http://www.piclist.com hint: To leave the PICList
RemoveMEpiclist-unsubscribe-requestspam_OUTspamKILLspammitvma.mit.edu


2002\02\10@044006 by uter van ooijen & floortje hanneman

picon face
I might be blind but I don't see the big problem. The high nibble drives the
control lines, and (via D+R) the key rows. The low nibble drives the LCD
data pins and reads the key columns (use pull up or down R's). The only
snatch is that to scan one row you'll have to toggle E, which can cause an
operation on the LCD. To get around this problem:

- make sure the operation is a no-op, like reading, or writing to a location
that does not matter (maybe one of the user-defined characters)
- reverse the operation immediately afterwards (for instance erase the char
just written)
- you have a pin 'left over' (or two, when you don't read). Use them all to
drive E in and-fashion (you can use a D-R and gate, I think that does not
count as active?)

It is a pity I have no time to try this (one-hand typing with a baby in the
other arm is difficult enough).

Wouter van Ooijen

Van Ooijen Technische Informatica: http://www.voti.nl
Jal compiler for PIC uC's:  http://www.voti.nl/jal
PICs kopen? http://www.voti.nl/shop

--
http://www.piclist.com hint: To leave the PICList
RemoveMEpiclist-unsubscribe-requestTakeThisOuTspamspammitvma.mit.edu


2002\02\10@110226 by Edson Brusque

face
flavicon
face
part 1 1707 bytes content-type:text/plain; (decoded 7bit)

Hello Wouter,

> - you have a pin 'left over' (or two, when you don't read). Use them all
to
> drive E in and-fashion (you can use a D-R and gate, I think that does not
> count as active?)

   This gave me an idea, just wait... I need to elaborate it:

   Well, here we go. Sorry for attaching a 33KB bitmap on this email, but
it's small. :)

   When you're scanning the keyboard, RB3:RB0 are outputs and RB7:RB4 are
inputs. You'll need the external pull-downs (about 10K). As we'll see below,
the internal pull-ups wouldn't work.

   Just do the keyboard scanning as usual positive-logic. When you have a
key pressed, the corresponding input pin will go high when you put the
corresponding output pin high.

   As you can see, the LCD will ignore these signals, because you need to
have RB1 AND RB2 HIGH for it to see a HIGH on the enable line.

   I think R1-R8 can be 1K and R9 10K. The diodes can be 1N4148. This will
make the LCD-ENA line LOW when RB1 OR RB2 are LOW. This is the normal
keyboard scanning situation, where you turn RB0=HI, read ROW1 on RB7:RB4,
turn RB0=LO RB1=HI, read ROW2 on RB7:RB4 and so on. You never will have both
RB1 and RB2 HIGH when scanning the keyboard.

   You can use negative logic for the keys if you invert the LCD-ENA signal
with a transistor, but then it's not a only passive circuit anymore.

   Have I won the award? So I want divide the price with Wouter. ;^)

   Best regards,

   Brusque

-----------------------------------
Edson Brusque
Research and Development
C.I.Tronics Lighting Designers Ltda
Blumenau  -  SC  -  Brazil
http://www.citronics.com.br
Say NO to HTML mail
-----------------------------------




part 2 33111 bytes content-type:image/bmp; (decode)


part 3 105 bytes
--
http://www.piclist.com hint: To leave the PICList
EraseMEpiclist-unsubscribe-requestspamspamspamBeGonemitvma.mit.edu


2002\02\10@121224 by Dave Dilatush

picon face
part 1 5035 bytes content-type:text/plain; charset=us-ascii (decoded quoted-printable)

David Harris wrote...

>CHALLENGE: can you scan a keyboard, and run an LCD display with only >8 pins/bits = 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.  
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.  
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;
d) All multiple keypresses must be resolved correctly;
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.  
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



part 2 5434 bytes content-type:image/gif; name=keypad.gif (decode)


part 3 105 bytes
--
http://www.piclist.com hint: To leave the PICList
RemoveMEpiclist-unsubscribe-requestKILLspamspammitvma.mit.edu


2002\02\10@132155 by Edson Brusque

face
flavicon
face
Hello Dave,

>The attached diagram shows another possible solution.
   <SNIP>

   your method is very interesting. Do you have it actually built and
tested?

   Just a question. Does the 44780 based LCDs have pull-ups on the inputs?
If not, I don't think this will work.

>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.

   Let's say no keys are pressed. You've charged all the caps with current
passing through the diodes, then you havn't discharged any caps because no
key are pressed when you turned RD4 LOW. Then you have RD7:RD4 as inputs
reading LOW, because no current passes from the cap to the port by the keys.
No current also passes through the (now reversed) diodes.

   How can this work?

   Thanks,

   Brusque

-----------------------------------
Edson Brusque
Research and Development
C.I.Tronics Lighting Designers Ltda
Blumenau  -  SC  -  Brazil
http://www.citronics.com.br
Say NO to HTML mail
-----------------------------------

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestSTOPspamspamspam_OUTmitvma.mit.edu


2002\02\10@133714 by Dave Dilatush

picon face
part 1 822 bytes content-type:text/plain; charset=us-ascii (decoded quoted-printable)

Edson Brusque wrote...

>    Let's say no keys are pressed. You've charged all the caps with current
>passing through the diodes, then you havn't discharged any caps because no
>key are pressed when you turned RD4 LOW. Then you have RD7:RD4 as inputs
>reading LOW, because no current passes from the cap to the port by the keys.
>No current also passes through the (now reversed) diodes.
>
>    How can this work?

It doesn't.

Darn it, I had pullup resistors on the port pins in this design when I
went to bed last night.  But when I got up this morning I couldn't
remember what the heck I'd put them in there for.  So I took them out.

Now I know why they were there in the first place.

Attached is the corrected design, with pullups included.

Dave


part 2 5916 bytes content-type:image/gif; name=keypad2.gif (decode)


part 3 105 bytes
--
http://www.piclist.com hint: To leave the PICList
spamBeGonepiclist-unsubscribe-requestSTOPspamspamEraseMEmitvma.mit.edu


2002\02\11@033821 by Michael Rigby-Jones

flavicon
face
I did something like this ages ago using diodes to multiplex lines.  Take a
look at http://www.mikerj.clara.net/keypad.html  The design is for a 3x4
keypad but is easily extendable to 4x4.  The code is shockingly bad (first
PIC assembler I ever wrote to be honest), but it has been used by a couple
of people.  Somewhere I have an updated version, and a HiTech C version.
I'll try to dig them out if there is any interest.

Mike

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\02\11@063152 by Alan B. Pearce

face picon face
>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.

With surface mount resistors being 1% tolerance, and E24 ranges available, I
suspect that with an hour or so of calculating it should be possible to make
this arrangement reasonably foolproof.

Another trick to do is to have the resistors set up as an R/2R network like
is used inside many A/D converters, and then each switch represents one
particular bit of the A/D inside the chip. Then for a 10 bit A/D converter
one could probably get 9 switches reliably :)

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\02\11@080907 by Al Williams

flavicon
face
One thing that is common on a Basic Stamp is to use the same arrangement
but instead of a voltage divider you make the varying resistance connect
to a capacitor. Then you can measure the time required to charge the
capacitor. Now you can just use a general-purpose I/O pin. You pick your
resistors so the values are far enough apart that you can't go wrong.
Still can't really press more than one (or could you? -- maybe you could
select values smart enough that any two would still be unique?).

I agree, I wouldn't tie up an A/D just for that, but the RC arrangement
is great -- I've used it myself.

Al Williams
AWC
* Floating point A/D
http://www.al-williams.com/awce/pak9.htm




> {Original Message removed}

2002\02\11@103950 by Edson Brusque

face
flavicon
face
part 1 2453 bytes content-type:text/plain; (decoded 7bit)

Hello Michael,

> I did something like this ages ago using diodes to multiplex lines.  Take
a
> look at http://www.mikerj.clara.net/keypad.html  The design is for a 3x4
> keypad but is easily extendable to 4x4.  The code is shockingly bad (first
> PIC assembler I ever wrote to be honest), but it has been used by a couple
> of people.  Somewhere I have an updated version, and a HiTech C version.
> I'll try to dig them out if there is any interest.

   your arrangement is great and I don't think the code have to be so bad.
The beuty of it is that it's purelly digital and you don't have to deal with
ADC or external caps to make the scanning routine slow.

   I've designed it with 16 keys using only 4 lines and here's what I got:

   Key         SET PORT B TO                READ PORT B AS
          RB3  RB2  RB1  RB0     |     RB3   RB2   RB1   RB0
   SW1     HiZ  HiZ  HiZ   0      |      0     0     1     X
   SW2     HiZ  HiZ  HiZ   0      |      0     1     0     X
   SW3     HiZ  HiZ  HiZ   0      |      0     1     1     X
   SW4     HiZ  HiZ  HiZ   0      |      1     0     0     X
   SW5     HiZ  HiZ   0   HiZ     |      0     0     X     1
   SW6     HiZ  HiZ   0   HiZ     |      0     1     X     1
   SW7     HiZ  HiZ   0   HiZ     |      0     1     X     0
   SW8     HiZ  HiZ   0   HiZ     |      1     0     X     1
   SW9     HiZ   0   HiZ  HiZ     |      0     X     1     1
   SW10    HiZ   0   HiZ  HiZ     |      0     X     0     1
   SW11    HiZ   0   HiZ  HiZ     |      0     X     1     0
   SW12    HiZ   0   HiZ  HiZ     |      1     X     0     1
   SW13     0   HiZ  HiZ  HiZ     |      X     0     1     1
   SW14     0   HiZ  HiZ  HiZ     |      X     1     0     1
   SW15     0   HiZ  HiZ  HiZ     |      X     1     1     0
   SW16     0   HiZ  HiZ  HiZ     |      X     0     0     1

   The circuit is attached below.

   Maybe some of the Algorithmic Brains on this list could think of a
cutier version with easier (re: fast) to track results.

   I think it's probably to extend this version to 24 keys.

   Oh my, I think we have a winner! You have the Sword of Camelot!!!

   Best regards,

   Brusque

-----------------------------------
Edson Brusque
Research and Development
C.I.Tronics Lighting Designers Ltda
Blumenau  -  SC  -  Brazil
http://www.citronics.com.br
Say NO to HTML mail
-----------------------------------



part 2 21771 bytes content-type:image/bmp; (decode)


part 3 154 bytes
--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\02\11@124224 by Dwayne Reid

flavicon
face
Repost with some additions: don't think the 1st version made it to the list.

David Harris wrote...

>CHALLENGE: can you scan a keyboard, and run an LCD display with only 8
pins/bits
>= 1 port -- without extra active hardware?

The minimum component solution requires 9 pins unless you drop to a 4x3 (12
button) keypad.  But if you don't mind some extra passive components
(including 4 small signal diodes), I think you can do a LCD plus 4x4 keypad
PLUS 1 more input with only 6 pins.

You will want to read the inputs as active LO because of the weak pullups
present on the data lines of most LCD controllers.  Thats kind of sucky
because you would have more tolerance with input logic thresholds if you
were reading inputs as logic HI but thats life, I guess.

PIC lines 3..0 connect to LCD data lines 7..4.  PIC lines 3..0 also connect
to keypad rows with 4k7 series resistors.  PIC lines 3..0 also connect to
keypad columns via 4 diode-capacitor networks: cathode to PIC pin, anode to
keypad column and .001uF cap to GND.  You also need 100k resistor pullups
to the keypad columns and may want to add them to the rows as well (the
pullups in the LCD module vary quite radically).

2 more PIC lines connect to LCD RS and E lines as usual.  Line RS can also
be used as another input to the PIC by resistively coupling with a 4k7 or
10k resistor.  Line E must be dedicated to that function only.

Talk to LCD as normal.  You may want to pre-discharge the caps (set lines
3..0 LO for a few uS) before talking to the LCD but it shouldn't really be
necessary.

To read keypad, set PIC lines 3..0 HI for a few uS, then tri-state lines
3..1 and set line 0 low for a few more uS, then tri-state it as well.  Wait
a few more uS, then read the port.  Go off and do something useful for a
couple of hundred uS, then set line 1 low for a few uS, then tri-state
it.  Wait for a few uS and read the port.  Repeat with lines 2 & 3.

The important thing is to ensure the un-selected hold capacitors have a
chance to charge well above 3V or 4V before trying to read the desired column.

Total component count: 1- 10 pin bussed SIP (100k), 1- 8 pin iso SIP (4k7),
4- 1n4148 diodes, 4- 1n0 mono caps.

I do something similar to this in several of my products - some of those
have been in current production for the past 7 years or so.  The technique
is relatively easy to implement.

The version that I'll put together (sometime this week) will be identical
to the above except that I'll use 10n capacitors - the background routine
on most of my projects executes every millisecond.  Since its no effort for
me to poll the keypad at 1 ms intervals, I can afford the extra charge time
that 10n caps require.  I'll post code when I'm done.

dwayne


Dwayne Reid   <KILLspamdwaynerspamBeGonespamplanet.eon.net>
Trinity Electronics Systems Ltd    Edmonton, AB, CANADA
(780) 489-3199 voice          (780) 487-6397 fax

Celebrating 18 years of Engineering Innovation (1984 - 2002)
 .-.   .-.   .-.   .-.   .-.   .-.   .-.   .-.   .-.   .-
    `-'   `-'   `-'   `-'   `-'   `-'   `-'   `-'   `-'
Do NOT send unsolicited commercial email to this email address.
This message neither grants consent to receive unsolicited
commercial email nor is intended to solicit commercial email.

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\02\12@073615 by dpharris

picon face
Hi Edson-
Yes, that's doable.  However, you can also use negative logic, if you reverse
the diodes.
David

Edson Brusque wrote:

{Quote hidden}

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2002\02\12@120705 by Dwayne Reid

flavicon
face
David Harris wrote...

>CHALLENGE: can you scan a keyboard, and run an LCD display with only 8
pins/bits
>= 1 port -- without extra active hardware?

The minimum component solution requires 9 pins.  But if you don't mind a
whole bunch of passive components (including 4 small signal diodes), I
think you can do it with 6 pins.

You will want to read the inputs as active LO because of the weak pullups
present on the data lines of most LCD controllers.  Thats kind of sucky
because you would have more tolerance with input logic thresholds if you
were reading inputs as logic HI but thats life, I guess.

PIC lines 3..0 connect to LCD data lines 7..5.  PIC lines 3..0 also connect
to keypad rows with 4k7 series resistors.  PIC lines 3..0 also connect to
keypad columns via 4 diode-capacitor networks: cathode to PIC pin, anode to
keypad column and .001uF cap to GND.  You also need 100k resistor pullups
to the keypad columns and may want to add them to the rows as well (the
pullups in the LCD module vary quite radically).

2 more PIC lines connect to LCD RS and E lines as usual.

Talk to LCD as normal.  You may want to pre-discharge the caps (set lines
3..0 LO for a few uS) before talking to the LCD but it shouldn't really be
necessary.

To read keypad, set PIC lines 3..0 HI for a few uS, then tri-state lines
3..1 and set line 0 low for a few more uS, then tri-state it as well.  Wait
a few more uS, then read the port.  Go off and do something useful for a
couple of hundred uS, then set line 1 low for a few uS, then tri-state
it.  Wait for a few uS and read the port.  Repeat with lines 2 & 3.

The important thing is to ensure the un-selected hold capacitors have a
chance to charge well above 3V or 4V before trying to read the desired column.

Total component count: 1- 10 pin bussed SIP (100k), 1- 8 pin iso SIP (4k7),
4- 1n4148 diodes, 4- 1n0 mono caps.

dwayne


Dwayne Reid   <EraseMEdwaynerspamEraseMEplanet.eon.net>
Trinity Electronics Systems Ltd    Edmonton, AB, CANADA
(780) 489-3199 voice          (780) 487-6397 fax

Celebrating 18 years of Engineering Innovation (1984 - 2002)
 .-.   .-.   .-.   .-.   .-.   .-.   .-.   .-.   .-.   .-
    `-'   `-'   `-'   `-'   `-'   `-'   `-'   `-'   `-'
Do NOT send unsolicited commercial email to this email address.
This message neither grants consent to receive unsolicited
commercial email nor is intended to solicit commercial email.

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2002\02\13@173511 by Dwayne Reid

flavicon
face
At 06:34 PM 2/10/02 +0000, Dave Dilatush wrote:
{Quote hidden}

Close, except turn the diodes around.

dwayne



Dwayne Reid   <@spam@dwayner@spam@spamspam_OUTplanet.eon.net>
Trinity Electronics Systems Ltd    Edmonton, AB, CANADA
(780) 489-3199 voice          (780) 487-6397 fax

Celebrating 18 years of Engineering Innovation (1984 - 2002)
 .-.   .-.   .-.   .-.   .-.   .-.   .-.   .-.   .-.   .-
    `-'   `-'   `-'   `-'   `-'   `-'   `-'   `-'   `-'
Do NOT send unsolicited commercial email to this email address.
This message neither grants consent to receive unsolicited
commercial email nor is intended to solicit commercial email.

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2002\02\13@181228 by Dave Dilatush

picon face
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.  The function of the
diodes is to isolate the column lines from the row lines, so that the
storage capacitors can be forcibly pre-charged to a HIGH directly by the
PIC, but can only be discharged through an activated key.  
There's more to it than that (see the step-by-step operating sequence),
but that's the diode function in a nutshell.

Dave

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2002\02\13@192202 by Dwayne Reid

flavicon
face
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.

dwayne



Dwayne Reid   <spamBeGonedwaynerspamKILLspamplanet.eon.net>
Trinity Electronics Systems Ltd    Edmonton, AB, CANADA
(780) 489-3199 voice          (780) 487-6397 fax

Celebrating 18 years of Engineering Innovation (1984 - 2002)
 .-.   .-.   .-.   .-.   .-.   .-.   .-.   .-.   .-.   .-
    `-'   `-'   `-'   `-'   `-'   `-'   `-'   `-'   `-'
Do NOT send unsolicited commercial email to this email address.
This message neither grants consent to receive unsolicited
commercial email nor is intended to solicit commercial email.

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2002\02\13@194509 by Dave Dilatush

picon face
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: .....PICLISTspam_OUTspamMITVMA.MIT.EDU
Subject: Re: [PIC]: CHALLENGE: 4x4 keyboard and LCD with 1 port = 8 bits
From: Dave Dilatush <TakeThisOuTdilatush.....spamTakeThisOuTHOME.COM>
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
>8 pins/bits = 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.  
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.  
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;
d) All multiple keypresses must be resolved correctly;
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.  
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.


2002\02\14@220541 by dpharris

picon face
Good idea - AND the outputs through a diode/resitor AND gate.  As the key-scan
routine only uses one line at a time, there should be no conflict.

David

wouter van ooijen & floortje hanneman wrote:

{Quote hidden}

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservspamRemoveMEmitvma.mit.edu with SET PICList DIGEST in the body


More... (looser matching)
- Last day of these posts
- In 2002 , 2003 only
- Today
- New search...