3x3 Matrix Keyboard Introduction
Matrix keyboard, 3×3 matrix keyboard, digital tube display corresponding keys, dynamic scanning, interrupt realization.
The pull-up resistor attribute must be set to "digital".
3x3 matrix keyboard scanning principle and scanning procedure
Arrange the 9 keys into 3 rows and 3 columns. Connect one end of each key together in the first row to form a row line, and connect the other end of each key together in the first column to form a column line. In this way, there are 3 rows and 3 columns, a total of 6 wires. We connect these six wires to the 6 IO ports of STM32, and the 9 keys can be detected by scanning the keyboard through the program.
Whether it is an independent keyboard or a matrix keyboard, the principle of the microcontroller detecting whether it is pressed is the same, that is, detecting whether the I/O port corresponding to the key is at a low level. One end of the independent key is fixed at a low level, which is convenient for the microcontroller to write a program for detection. Both ends of the matrix keyboard are connected to the I/O port of the microcontroller, so it is necessary to manually send a low level through the I/O port of the microcontroller during detection. During detection, first send one column to a low level, and the remaining columns to a high level (at this time we have determined the number of columns), and then immediately check each row in turn to see if there is a low level. If a row is detected to be at a low level (at this time we have determined the number of rows), we can confirm which row and column the currently pressed key belongs to. Use the same method to send each column at a low level in turn, and then check each row in turn to see if it becomes a low level. In this way, all the keys can be detected. Of course, we can also set the row line to a low level and scan the column to see if there is a low level. This is the detection principle and method of the matrix keyboard.
SETB P1.0; First, everyone should set
SETB P1.1
SETB P1.2
SETB P1.3
SETB P1.4
SETB P1.5
KEY: CLR P1.0; all lines are cleared
CLR P1.1 CLR P1.2
JNB P1.3, KEY0; Determine whether a key is pressed
JNB P1.4, KEY0
JNB P1.5, KEY0
SJMP KEY ; if no key is pressed, return to KEY and continue to query if any key is pressed
KEY0: LCALL DELAY; call delay function
CLR P1.0; P1.0 is cleared, P1.1 and P1.2 are set
SETB P1.1
SETB P1.2
JNB P1.3, KEY1; if P1.3 is zero, key 1 is pressed and jumps to key 1 KEY1
JNB P1.4, KEY2
JNB P1.5, KEY3
SETB P1.0; P1.1 is cleared, P1.0 and P1.2 are set to 1CLR P1.1
SETB P1.2
JNB P1.3, KEY4
JNB P1.4, KEY5
JNB P1.5, KEY6
SETB P1.0; P1.2 is cleared, P1.0 and P1.1 are set
SETB P1.1
CLR P1.2
JNB P1.3, KEY7
JNB P1.4, KEY8
JNB P1.5, KEY9
SJMP KEY ; If no key is pressed, jump back to the key query program
KEY1: LCALL PRO1; call the processing subroutine of key 1
LJMP KEY ; Return to continue checking whether the key is pressed
KEY2: LCALL PRO2
LJMP KEY
KEY3: LCALL PRO3
LJMP KEY
KEY4: LCALL PRO4
LJMP KEY
KEY5: LCALL PRO5
LJMP KEY
KEY6: LCALL PRO6
LJMP KEY
KEY7: LCALL PRO7
LJMP KEY
KEY8: LCALL PRO8
LJMP KEY
KEY9: LCALL PRO9
LJMP KEY
PRO1: . ;Subroutine for key 1 processing
RET ; Subroutine return
PRO2:
.RET
PRO3:
RET
PRO4:
RET
PRO5:
RET
PRO6:
RET
PRO7:
RET
PRO8:
RET
PRO9:
RET
Previous article:How to use sbit in single chip C voice development··
Next article:Design of FM Radio Based on Single Chip Microcomputer
- Popular Resources
- Popular amplifiers
- 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
- Pins 2 and 4 are missing from the schematic and package of the BNX016-01 device
- SIMetrix-SIMPLIS ~1~
- What is the difference between a vector signal source and an RF signal source?
- I don't have enough download points. Is there any good way to earn points?
- Commonly used algorithms for drones - Kalman filter (VIII)
- Recruitment of electronic system engineers BMS direction
- Using simple components such as diodes, we can distinguish between resistance and inductance
- Understanding the static electricity problems in the field of microelectronics manufacturing from the perspective of integrated circuit back-end manufacturing (chip packaging and testing)
- Today's Fujitsu Live Topic 2: Watch 3D movies without glasses, learn about German-quality naked-eye 3D technology
- Brightsign core board HS124, HS144 hardware and software development. Brightsign player