AN-660: XY-Matrix Keypad Interface to MicroConverter®
Introduction
Using a keypad input in a MicroConverter application is sometimes required for specific operations. It may be used to input data following a request from the MicroConverter or simply to trigger the MicroConverter to initiate a particular operation. The MicroConverter can be configured to poll the keypad continuously for an input, or the keypad interface can be configured in an interrupt driven system, depending on the system requirements.
Keypad
The keypad used for this application is a 16-way XY-Matrix hexadecimal keypad (www.eaoswitch.com, Mfgr. No. ECO 16250 06, Farnell order code: 467-212). This keypad has eight connections at the rear—four columns (X1–X4) and four rows (Y1–Y4). Figure 1 and Figure 2 show the front and rear of the keypad.
Operation
There are two methods of operation: continuous polling, where the MicroConverter spends most or all of its time checking the keypad for a key press; and interrupt driven, where the MicroConverter is free to perform whatever other tasks are required and checks the keypad only when a key is pressed.
Continuous Polling Operations
In this mode of operation, the MicroConverter continuously polls the keypad for a key press. This operation is used where the MicroConverter has completed a task and is now waiting for input before proceeding. In this mode, the keypad is connected to one port of the MicroConverter, Port 2 in this example. Figure 3 shows the connectivity. The output from the MicroConverter, following a key press, is viewed using HyperTerminal running on a PC. The MicroConverter is connected to the PC via the COM1 port. This is the reason for showing the RS-232 connection.
As can be seen in Figure 3, the four columns (X1 to X4) are pulled up to VDD and are also connected to four of the MicroConverter port pins (P2.4 to P2.7). The four rows (Y1 to Y2) are connected to the other four port pins (P2.0 to P2.3). The MicroConverter outputs 0 or drives low the keypad rows (P2.0 to P2.3) one at a time and checks the columns (P2.4 to P2.7) for a low condition.
For example, the following is the sequence of events up to a switch press detection (Switch 5 in this case). The MicroConverter outputs a low on P2.0 (Y1) and checks for a low on P2.4 to P2.7. In this case, no low is found and so it returns P2.0 (Y1) to high and moves on to P2.1 (Y2). The MicroConverter now drives P2.1 (Y2) low and again checks P2.4 to P2.7 for a low condition. This time it finds that P2.5 (X2) is low, due to Switch 5 being pressed. The MicroConverter now knows that the interconnect of Y2 and X2 has been shorted, therefore, this is 5. The code to perform this operation is given in the accompanying KEYSPOLL.ASM file.
Interrupt Driven Operations
The basic operation of an interrupt driven scheme is similar to the polling scheme except the MicroConverter does not continuously poll the keypad. Instead, it polls the keypad only when a key is pressed. This operation requires some external circuitry, as shown in Figure 4. The objective of this logic is to produce a negative-going edge for each key press (see the truth table below). This negative edge triggers the INT1 interrupt service routine, which in turn runs the keypad software. Once the keypad software routine has run and no additional key presses have been detected, the MicroConverter resumes executing whatever other code it was running before the key was pressed. The code for this application is given in the accompanying KEYSINT.ASM file.
NOTE: In both circuit diagrams, inherent circuitry critical to the operation of the MicroConverter is omitted for clarity, i.e., EA, PSEN, decoupling, and detailed RST. This circuitry should not be omitted in practice.
X1 | X2 | OUT1 |
0 | 0 | 1 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 0 |
X3 | X4 | OUT2 |
0 | 0 | 1 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 0 |
OUT1 | OUT2 | OUT3 | INT1 |
0 | 0 | 0 | 1 |
0 | 1 | 1 | 0 |
1 | 0 | 1 | 0 |
1 | 1 | 0 | 1 |