MICROCHIP TECHNOLOGY’S MICROSOLUTIONS eNEWSLETTER - November 2005
Tips ‘n Tricks - LCD PICmicro ? Microcontrollers
TIP 4. 4 x 4 Keypad Interface that Conserves Pins for LCD
Segment Drivers
A typical digital interface to a 4 x 4 keypad uses 8 digital I/O pins. But using eight pins as digital
I/Os can take away from the number of segment driver pins available to interface to an LCD.
By using 2 digital I/O pins and 2 analog input pins, it is possible to add a 4 x 4 keypad to the
PIC ? microcontroller without sacrifi cing any of its LCD segment driver pins. The schematic
for keypad hook-up is shown in Figure 4-1 . This example uses the PIC18F8490, but the
technique could be used on any of the LCD PIC microcontrollers.
The two digital I/O pins that are used are RB0 and RB5, but any two digital I/O pins could
work. The two analog pins used are AN0 and AN1.
5. Perform two successive A/D conversions; fi rst on AN0, then on AN1.
6. Save the conversion results to their respective variables; for example, RB5_AN0_RESULT
and RB5_AN1_RESULT .
7. There are now 4 variables that represent a key press in each quadrant of the 4 x 4
keypad:
- RB0_AN0_RESULT . denotes key press of 1, 2, 4 or 5
- RB0_AN1_RESULT . denotes key press of 7, 8, A or 0
- RB5_AN0_RESULT . denotes key press of 3, C, 6 or D
- RB5_AN1_RESULT . denotes key press of 9, E, B or F
8. Finally, check each value against the matching column of Table 4-1 . If it is within ±10% of a
value, then it can be taken to indicate that the corresponding key has been pressed.
9. This loop should be repeated about once every 20 ms or so. Don’t forget a debounce
outline. For example, require the above steps (with 20 ms delay between) to return the
same key value twice in a row for that key to be considered pressed. Also, require a no key
press to be returned at least twice before looking for the next key press.
When keys within the same quadrant are pressed simultaneously, voltages other than the
four valid levels shown in the table may be generated. These levels can either be ignored,
or if you want to use simultaneous key presses to enable certain functions, you can add
decoding for those levels as well.
Value ±10%
<V DD /10
V DD /5.2
V DD /4.2
V DD /3
V DD /2
RB0_AN0
2
1
5
4
RB0_AN1
8
7
0
A
RB5_AN0
C
3
D
6
RB5_AN1
E
9
F
B
Table 4-1: Keypad Values
Figure 4-1: Keypad Hook-up Schematic
To read the keypad, follow the steps below:
1. First, make RB0 an output high and RB5 an input (to present a high impedance).
2. Perform two successive A/D conversions; fi rst on AN0, then on AN1.
3. Save the conversion results to their respective variables; for example, RB0_AN0_RESULT
and RB0_AN1_RESULT .
4. Next, make RB5 an output high and RB0 an input (to present a high impedance).
Microcontrollers ? Digital Signal Controllers ? Analog ? Serial EEPROMs
9
相关PDF资料
MA180021 MODULE PLUG-IN 18F87J50 FS USB
MA180024 MODULE PLUG-IN 18F46J50 FS USB
MA180028 MOD PLUG-IN PIC18F87K22 PIM
MA2-4-34-625-2-A32-7C CIRCUIT BREAKER MAG 25A PANEL MT
MA240013 MODULE PLUG-IN PIC24 44-PIN
MA240017 MODULE PLUG-IN PIC24F16KA102 PIM
MA240021 MOD PLUG-IN PIC24FJ256GB210
MA240025-1 MOD PIM PIC24EP512GU810 GP
相关代理商/技术参数
MA160012 功能描述:子卡和OEM板 PIC16F193x 44P PIM For PIC18 Explorer RoHS:否 制造商:BeagleBoard by CircuitCo 产品:BeagleBone LCD4 Boards 用于:BeagleBone - BB-Bone - Open Source Development Kit
MA160012 制造商:Microchip Technology Inc 功能描述:PIC16F1937 Plug-in Module for PICDEM PIC
MA160014 功能描述:子卡和OEM板 PIC18LF45K22 Plug-In Module RoHS:否 制造商:BeagleBoard by CircuitCo 产品:BeagleBone LCD4 Boards 用于:BeagleBone - BB-Bone - Open Source Development Kit
MA160015 功能描述:子卡和OEM板 PIC16LF1947 PIM RoHS:否 制造商:BeagleBoard by CircuitCo 产品:BeagleBone LCD4 Boards 用于:BeagleBone - BB-Bone - Open Source Development Kit
MA160016 功能描述:子卡和OEM板 PIC16F1947 PIM RoHS:否 制造商:BeagleBoard by CircuitCo 产品:BeagleBone LCD4 Boards 用于:BeagleBone - BB-Bone - Open Source Development Kit
MA161 制造商:Panasonic Industrial Company 功能描述:DIODE
MA16101BAN 制造商:MURATA 制造商全称:Murata Manufacturing Co., Ltd. 功能描述:HIGH FREQUENCY CERAMIC CAPACITORS
MA16101BBN 制造商:MURATA 制造商全称:Murata Manufacturing Co., Ltd. 功能描述:HIGH FREQUENCY CERAMIC CAPACITORS