A typical digital interface for a 4×4 keypad uses 8 digital I/O pins. But using 8 pins as digital I/O takes up the number of segment driver pins that can be used to connect to the LCD.
By using 2 digital I/O pins and 2 analog input pins, a 4×4 keypad can be added to a PIC microcontroller without sacrificing any of its LCD segment driver pins.
The following figure shows the keypad connections. A PIC18F8490 is used in the example, but the technique can be used with any LCDPIC MCU.
The two digital I/O pins used in the diagram are RBO and RB5, but any other two digital I/O pins can be used. The two analog pins used are ANO and AN1.
To read the keypad, follow these steps:
1. First, design RBO to output high level and RB5 to input (high impedance).
2. Perform two consecutive A/D conversions, first converting ANO and then converting AN1.
3. Save the conversion results into their respective variables: for example, RBO-ANO-Result and RBO-ANl-Result.
4. Then, set RB5 to output high level and RBO to input (high impedance).
5. Perform two consecutive A/D conversions, first converting ANO and then converting AN1.
6. Save the conversion results into their respective variables: for example, RB5-ANO-Result and RB5-ANl-Result.
7. Now, there are 4 variables, representing a key press in each quadrant of the 4×4 keypad:
8. Finally, check each value against the corresponding column in the table below. If it is within +/-10% of a certain value, the corresponding key can be considered to have been pressed.
9. This loop should be repeated approximately every 20ms. Do not forget to execute the key pop-up handler. For example, the key is considered pressed only when the above steps return the same key value twice in a row (with a 20ms delay in between). It is also required that the next key operation can only be started when no key is pressed at least twice. When several keys in the same quadrant are pressed at the same time, voltages other than the four valid levels shown in Table 3 may be generated. These levels can be ignored, or if you want to enable certain functions by using simultaneous key presses, you can also add a decoding process for these levels.
Previous article:PIC24FV16KM204 Series General Purpose 16-bit Flash MCU Data Sheet
Next article:Analysis of I/O Control Operations of PIC Microcontroller
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- How to migrate FreeRTOS applications to secure SAFERTOS
- LED Timer Keychain
- RF2051 chip
- MSP430G2 LaunchPad, how to play music with buzzer
- Disassemble a WSN node device and see how to select materials?
- Allwinner V853 heterogeneous multi-core AI intelligent vision development board review - V853 YOLO V3 test
- Development board CC3200-LAUNCHXL,
- TMS320F28335 Study Notes——DMA
- RISC-V MCU Development (Part 2): Project Creation and Management
- MSP430 analog-to-digital conversion module--ADC12