EmbeddedRelated.com
Forums

Looking for 4x4 keypad scan routine for 8052 family chip.

Started by Art K6KFH April 12, 2004
Greetings,
 I'm looking for a basic 4x4 matrix keboard scan routine for the 8052
family of chips.  I want to use one port with 1 nibble as outputs and
the other as inputs and periodically scan for keypresses.  I've done
this many times in the past but it's waaaay past and there isn't much
need to reinvent the wheel.  If someone could point me to a source I'd
appreciate it.  I looked all over 8052.com but couldn't come up with
much.

Thanks,

Art 
> I'm looking for a basic 4x4 matrix keboard scan routine for the 8052 >family of chips. I want to use one port with 1 nibble as outputs and >the other as inputs and periodically scan for keypresses.
Not much to it. Say your outputs are on the columns. Set all outputs to 1, set one to 0, then read the inputs. Walk the 0 through the outputs, reading the inputs (rows) each time. You get a 0 on the inputs if a key was pressed in that column. You have to have pull-up resistors on the inputs. Don't know if the 8052 provides them built-in or not. Then you get to do debouncing. Basically wait a few milliseconds then scan the keypad again. If the results are the same, then take them as valid. If not, start over again.
On 13 Apr 2004 01:58:49 GMT, garykato@aol.com (Gary Kato) wrote:

>> I'm looking for a basic 4x4 matrix keboard scan routine for the 8052 >>family of chips. I want to use one port with 1 nibble as outputs and >>the other as inputs and periodically scan for keypresses. > >Not much to it. Say your outputs are on the columns. Set all outputs to 1, set >one to 0, then read the inputs. Walk the 0 through the outputs, reading the >inputs (rows) each time. You get a 0 on the inputs if a key was pressed in that >column. You have to have pull-up resistors on the inputs. Don't know if the >8052 provides them built-in or not. > >Then you get to do debouncing. Basically wait a few milliseconds then scan the >keypad again. If the results are the same, then take them as valid. > >If not, start over again.
Easier to set all the outputs to 0 and check the inputs to see if any is a 0 (or nibble is not 1111), then do the scanning if required. Or, alternatively, use the "any 0" to trigger an interrupt (don't know if you can do this with the 8052?) maybe even with an diode OR gate tied onto the interrupt line. Alan ++++++++++++++++++++++++++++++++++++++++++ Jenal Communications Manufacturers and Suppliers of HF Selcall P O Box 1108, Morley, WA, 6943 Tel: +61 8 9370 5533 Fax +61 8 9370 5106 Web Site: http://www.jenal.com e-mail: http://www.jenal.com/contact.php ++++++++++++++++++++++++++++++++++++++++++