Hardware Reference
In-Depth Information
1. Keypad scanning to find out which key was pressed
2. Key switch debouncing to make sure a key is indeed pressed
3. Table lookup to find the ASCII code of the key that was pressed
7.9.1 Keypad Scanning
Keypad scanning is usually performed row by row and column by column. A 16-key keypad
can easily be interfaced with any available I/O port. Figure 7.32 shows a 16-key keypad orga-
nized into four rows with each row consisting of four switches.
For the keypad input application, the upper four pins (PA7,PA4) of Port A should be config-
ured for output, whereas the lower four pins (PA3,PA0) of Port A should be configured for input.
HCS12 MCU
PA7
PA6
PA5
PA4
PA3
3
7
B
F
PA2
2
6
A
E
PA1
1
5
9
D
PA0
0
4
8
C
10 k
V CC
Figure 7.32 Sixteen-key keypad connected to the HCS12
The rows and columns of a keypad are simply conductors. In Figure 7.32, Port A pins
PA3,PA0 are pulled up to high by pull-up resistors. Whenever a key switch is pressed, the cor-
responding row and column are shorted together. In order to distinguish the row being scanned
from those not being scanned, the row being scanned is driven low, whereas the other rows are
driven high. The row selection of the 16-key keypad is shown in Table 7.12.
PA7
PA6
PA5
PA4
Selected Keys
1
1
1
0
1
1
0
1
1
0
1
1
0
1
1
1
0, 1, 2, and 3
4, 5, 6, and 7
8, 9, A, and B
C, D, E, and F
Table 7.12 Sixteen-key keypad row selections
 
 
Search WWH ::




Custom Search