'MEL Basic and matrix keypad..'
Kevin J. Slater
Has anyone worked with MEL's Basic compiler to develop code to read the
keypresses on a
matrix keypad? I'm thinking of tackling a garage door keypad with some
additional features. I'm
not into PIC's enough to attempt ASM code for this project. Alternately, can
anyone suggest an IC
that could be used to read the keypad and present the key pressed to a PIC pin?
Any help greatly appreciated..
/* Kevin Slater */
/* Slater Programming Services */
/* Mars, Pa. 16046-3938 */
/* http://www.pobox.com/~kslater */
|On Tue, 5 Aug 1997 14:30:44 +0500 "Kevin J. Slater" <FYI.NET> kslater
>Has anyone worked with MEL's Basic compiler to develop code to read
> keypresses on a
>matrix keypad? I'm thinking of tackling a garage door keypad with some
> additional features.
Reading a matrix keyboard is not too complicated. One dimension of the
keyboard (for example, the columns) will be connected to processor
outputs. I'll call these the "scan" lines. The other dimension is
connected to processor inputs. These are the "return" lines. For
example, a telephone type keyboard could be:
S0 S1 S2
1 2 3 - R0
4 5 6 - R1
7 8 9 - R2
* 0 # - R3
The return lines need pull-up or pull-down resistors so if no keys are
pressed they will read as inactive. If it is expected that more than one
key will be pressed at a time, it is necessary to use a diode at each key
to prevent multiple paths through the matrix. To read the keyboard, make
one scan line at a time active, wait a (very) short time for the signals
to settle, and read the return lines. Repeat the process with the other
scan lines. Store each return result as an entry in an array. In this
case, the array is 3 elements of 4 bits each. If all the array elements
are 0, no keys are pressed. Any 1 bits correspond to keys that are
pressed (without diodes, multiple keypresses won't read correctly
though). The result in the array is the instantaneous "state" of the
keyboard. The scanning should be done about once every 40-50 ms. Done
too fast, keys bouncing will be interpreted as multiple presses. Too
slow, and the user will need to press each key for what seems to be a
long time before it is recognized.
Usually it is desired to act only when a key is first pressed. For
example, pressing key 3 should enter "3" in a buffer, but only once until
the 3 key is released and pressed again. To do this, the previous state
of the keyboard needs to be stored and compared to the new state. After
comparing, new would be copied into previous for next time. The
comparison looks for previous =0, and new = 1. This can be done by
bitwise complementing previous and bitwise anding it with new. If any
bits in this result are 1, they identify newly pressed keys. This result
would be 12 bits but only one bit is 1. Probably the best way to decode
this to a key number would be to shift it until the first 1 is found, and
use the number of shifts to look up in a table the key value.
Kevin J. Slater wrote:
> Alternately, can anyone suggest an IC that could be used to read the keypad
> present the key pressed to a PIC pin?
I have used the 74C922 & 74C923 chips which scan a 16-key or 20-key
keypads. They are pricey at $13.13 US for ones at Digi-Key, but drop to $5.625
hundreds. They work well handling all the scanning, rollovers, and generating
signal on keypress. Four data lines plus some control line overhead and two
I always buy the `923's as they are the same price as the `922's.
When the way of the Tao is forgotten, kindness and ethics must be taught.
Men must learn to pretend to be wise and good. -- Lao Tzu
> Kevin J. Slater wrote:
> > Alternately, can anyone suggest an IC that could be used to read the keypad
> > present the key pressed to a PIC pin?
> I have used the 74C922 & 74C923 chips which scan a 16-key or 20-key
> keypads. They are pricey at $13.13 US for ones at Digi-Key, but drop to
> hundreds. They work well handling all the scanning, rollovers, and generating
> an INT
> signal on keypress. Four data lines plus some control line overhead and two
> I always buy the `923's as they are the same price as the `922's.
You may want to check Jameco instead .., I believe they charge $5.95 for each.
More... (looser matching)
- Last day of these posts
- In 1997
, 1998 only
- New search...