The circuit diagram of the development board matrix button module is as follows:
The circuit diagram of the digital tube module of the development board is as follows:
Matrix key scanning principle:
Method 1: Line-by-line scanning: We can scan the matrix keyboard line by line by outputting low level in turn through the upper four bits. When the data received by the lower four bits are not all 1, it means that a key is pressed. Then, we can determine which key is pressed by which bit of the received data is 0.
Method 2: Row and column scanning: We can output low level by all the high four bits and high level by the low four bits. When the low four bits of the received data are not all high level, it means that a key has been pressed. Then, we can judge which column has been pressed by the received data value. Then, we can judge which row has been pressed by the high four bits and low four bits. Then, we can judge which row has been pressed by the received high four bits. In this way, we can determine which key has been pressed.
In this program, the matrix buttons are scanned using row and column scanning!
In this program, the matrix buttons are scanned using row and column scanning!
Program purpose: Assign values of 0, 1, ..., 15 to the 16 buttons in the matrix respectively. When pressed, the label will be displayed on the first digital tube.
Notice:
The value represents the key pressed. To find out the row and column relationship between the keys, only a one-dimensional value is needed to determine the position of the key without finding the row/column numbers separately.
Waiting for the key release statement: while() is different from the while() in the independent key experiment program, so pay attention to the difference!
New tips: Before programming, you can assign new variable names to registers such as IO ports in time to facilitate program modification and other operations, increasing program readability!
#include #define uc unsigned char #define dig P0 #define key P1 sbit lsa=P2^2; sbit lsb=P2^3; sbit lsc=P2^4; int value; uc code x[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f, 0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; void delay(uc x) { uc i,j; for(i=1;i<=x;i++) for(j=1;j<=110;j++); } void keypros() { uc a=0; key=0x0f; if(key!=0x0f) { delay(10); if(key!=0x0f) { key=0x0f; switch(key) { case(0x07): value=0;break; case(0x0b): value=1;break; case(0x0d): value=2;break; case(0x0e): value=3;break; } key=0xf0; switch(key) { case(0x70): value=value; break; case(0xb0): value=value+4; break; case(0xd0): value=value+8; break; case(0xe0): value=value+12; break; } } while((key!=0xf0)&&(a<50)) { a++; delay(10); } /*while(key!=0xf0);*/ } } void main() { lsa=lsb=lsc=0; while(1) { keypros(); dig=x[value]; } }
Previous article:STC89C52 series MCU internal resources - timers and counters
Next article:STC89C52 series microcontroller internal resources - serial communication
- Popular Resources
- Popular amplifiers
- Multi-channel pressure measuring instrument based on C8051F020 single chip microcomputer
- Key matrix scan code for HT48R10
- Design of automatic player for work and rest signal based on 51 single chip microcomputer
- Friends who are looking for thermistors please come in (resistance values that are hard to buy in China)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- GD32 Competition - Motor Control - Hardware Design
- Guo Tianxiang's New Concept 51 MCU C language tutorial. Getting started, improving, and developing
- Power supply obstacle "+comp pin capacitor
- Design and Verification: Verilog HDL
- EEWORLD University - How Semiconductors Change the World
- 【GD32450I-EVAL】+10SD card test
- 3232 Unable to communicate
- Question about current amplifier
- How to send data packets larger than 255Bytes using CC131
- Why is negative feedback introduced in the amplifier circuit?