??? 09/06/04 16:47 Read: times |
#76985 - RE: debouncing for matrix keypad ? Responding to: ???'s previous message |
Here is one approach. It is used with a 28 key keypad (1/2" square momentary switches). The micro is a PIC (no BOOs please) and had to multiplex 6 7-segment LEDs.
I choose a 2 ms ON time for each LED for approx. 83 ms refresh cycle. In the timer interrupt routine, just after one LED is turned off, and before the next it to be turned on, the Keypad routine would check the keypad matrix. The matrix was a 4 x 7; the 7 inputs (driven by a port) were set low and the 4 outputs checked for a low. If a low state were seen, then it would decrement a count of 10 for each 2 ms look. If the same code existed for the 10 counts, it was considered valid. This gave a 20 ms 'debounce' time; easily changed to much longer times. (Assumes only one key down at a time.) Once the 10 counter decremented to zero, then the row vs column was identified by setting one row low at a time and when found then read the column code and convert both row and column codes from unary to binary. Codes 00h - 0Fh for the hex keypad, and 10h - 1Bh for the 'commands'. Has been working fine for years. |