3x3 matrix keyboard scanning principle and scanning procedure

Publisher:JoyfulExplorerLatest update time:2024-06-26 Source: elecfans Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

3x3 Matrix Keyboard Introduction

Matrix keyboard, 3×3 matrix keyboard, digital tube display corresponding keys, dynamic scanning, interrupt realization.

3x3 matrix keyboard scanning principle and scanning procedure

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.

3x3 matrix keyboard scanning principle and scanning procedure

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


Reference address:3x3 matrix keyboard scanning principle and scanning procedure

Previous article:How to use sbit in single chip C voice development··
Next article:Design of FM Radio Based on Single Chip Microcomputer

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号