|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Did you know...
|
Serial Wombat Matrix Encoded Keypad Driver
Scanning a keypad with your Serial Wombat is easy! Just follow these simple steps:
Keypresses from the keypad are presented as the first row pin's public data. The public data can be configured to hold the last key pressed, the current key pressed (includes a code for no key pressed) or a bitmap of the first 16 keys of the keypad (1 = pressed, 0 = not pressed). Key numbers start at 0 for first-row-first-column, 1 for first-row-second-column, and so on. For example, in the picture above, the 'C' key would be key number 11. The Serial Wombat is also capable of placing keypress events in a queue. This allows the host to only query occasionally for queued information, without having to worry about missing keypresses. Data can be queued as key numbers (starting at 0x00)when a new key-press event is detected, or as ASCII text (0-9, A-Z) when a new key-press event is detected. If multiple simultaneous keypresses need to be detected, then a 16-bit bitmap can be stored which indicates each change in the first 16 keys. The software supports up to eight columns by eight rows, although only up to four columns and rows have currently been tested, due to unavailablity of larger keypads. If you know of a resonably-priced matrix encoded keypad larger than 4x4, please contact me. I anticipate creating an 8x8 keypad using 4 4x4 pads soon. When configuring the Wombat, the user provides the Wombat pin number of the first column and first row pins. Additional column and row pins are assumed to be the next pins in counting order. For instance, if a 4x4 keypad is connected with row 1 of 4 connected to Wombat pin 7, then the remaining rows are assumed to be attached to Wombat pins 8, 9, and 10. However, certain pins are likely to be used for some special purpose, such as the hardware capture/PWM pins, the SPI capable pins, the RX and TX pins, Oscillator pins, the Boot Mode pin, and, of course, the chip Power Pins. Therefore, the Wombat skips these pins when counting. For example, if pin 13 were the first column pin, then the next three pins would be 14, 15, and 19. (16 and 17 are skipped because they are hardware PWM pins, 18 is skipped because it's the SPI clock line). The following is a list of pins which can be used for the keypad, in ascending order (note that the number of A/D channels may have to be configured to allow pins to be used as digital I/O). Row pins should be directly connected to the Wombat. Column pins require a pull-up resistor to +5V. If pins 33 through 40 are used for the column rows, then pull-up resistors may be omitted, as these pins have internal pull-ups inside the Wombat. Possible Wombat Keypad Pins:2, 3, 4, 5, 7, 8, 9, 10, 15, 19, 20, 21, 22, 27, 28, 29, 30, 33, 34, 35, 36, 37, 38, 39, 40 Message format:Note! Only the first row pin should be configured for Matrix keypad mode. All other pins attached to the keypad will be automatically configured to controlled mode
Example 1 queue keypresses from a 4x4 matrix encoded keypad:
A 4x4 matrix-encoded keypad is to be scanned by the Wombat so that keypresses can be reported back to the host. We will attach the keypad rows to 21, 22, 27 and 28 (these pins are logically "next to each other" in the list above). We'll attach the columns to pins 33, 34, 35 and 36 since these pins have internal pull-up resistors. We'll define a 32 byte queue at user address 0x50, and have the keypad driver put key presses in that queue. The host can then periodically check the queue to see if any new keypresses are in it. Initialization: 0x80 0x0050 0x0020 0x00 0x55 0x55
; Initialize a queue
; At address 0x50 (0x0050)
; 32 bytes long (0x0020)
; Standard queue type (0x00)
200 21 8 33 0x0050 1 0 ; Configure pin 21 to the first row of the keypad
; Pin 33 is the first column of the keypad
; Queue address is 0x0050
; Queue the key number
; Display a 16 key bitmap as public data
201 21 8 4 4 0x55 0x55 0x55; Configure pin 21 to the first row of the keypad
; 4 rows
; 4 Columns
Checking for Keypresses: Sent: 0x82 0x0050 6 0x55 0x55 0x55 0x55
; Get up to 6 bytes from queue at address 0x0050
Response (one possible example): 0x82 2 11 2 0x55 0x55 0x55 0x55
; Two bytes were retreived from the queue
; Button 11 was pressed and released
; Button 2 was pressed and released
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Copyright Wombat Interface Products, 2005-2008. All Rights Reserved.