The independent keys will be regrouped.
There are pull-up resistors in front of the button IO ports.
Scanning principle:
method one:
Line-by-line scanning: The matrix keyboard is scanned 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, the key that is pressed is determined by which bit of the received data is 0.
Method Two:
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.
From matrix buttons to independent buttons:
Make one line connecting the four buttons output low level continuously, and the others output high level (avoid affecting the used lines)
The last digit of the digital tube is controlled by the matrix button to display the number corresponding to the matrix button. The program is as follows:
The horizontal order is 0123, 4567, 89AB, CDEF:
#include typedef unsigned char u8; typedef unsigned int u16; sbit LSA=P2^2; sbit LSB=P2^3; sbit LSC=P2^4; #define GPIO_KEY P1 //Define the matrix key IO port as P1 #define GPIO_DIG P0 //Define the static digital tube IO port as P0 u8 KeyValue; //Each key is represented by a KeyValue u8 a; //Prepare for the following press time detection u8 code smgduanxuan[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; void delay(u16 i) { while(i--); } void KeyDown() { GPIO_KEY=0x0f; //First give the upper four bits a low level, then the lower four bits a high level, and then determine which column it is based on which of the lower four bits is not a high level if(GPIO_KEY!=0x0f) { delay(1000); //debounce if(GPIO_KEY!=0x0f) { GPIO_KEY=0x0f; //Reassign value switch(GPIO_KEY) { case 0x07: KeyValue=0;break; case 0x0b: KeyValue=1;break; case 0x0d: KeyValue=2;break; case 0x0e: KeyValue=3;break; }//Remember the following numbers, 0123 GPIO_KEY=0xf0; //Give the upper four bits a high level and the lower four bits a high level, and determine which row it is based on which of the upper four bits is not a high level switch(GPIO_KEY) { case 0x70: KeyValue=KeyValue;break; case 0xb0: KeyValue=KeyValue+4;break; case 0xd0: KeyValue=KeyValue+8;break; case 0xe0: KeyValue=KeyValue+12;break; }//Remember the number of lines, +0+4+8+12 while((a<50)&&(GPIO_KEY!=0xf0)) { delay(1000); a++; }//The condition for the program to jump out of the loop is to release or press it for a long enough time (to avoid continuous CPU occupation) } } } void main() { LSA=0; LSB=0; LSC=0; //Select static digital tube display while(1) { KeyDown(); GPIO_DIG=smgduanxuan[KeyValue]; //Give the static digital tube a displayed value } } #You can achieve verticality by modifying the assignment of KeyValuede. How to test the effect of hands-free detection When using the matrix buttons, the buzzer will sound at the same time. Analyze the reasons in detail. Remember to be rigorous in programming to avoid wasting time due to errors in program input. In this programming process, a semicolon was added at the end of #define, causing the program to keep reporting errors!!!
Previous article:11.8*8LED dot matrix
Next article:9. Independent buttons
- Popular Resources
- Popular amplifiers
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- Europe's three largest chip giants re-examine their supply chains
- Breaking through the intelligent competition, Changan Automobile opens the "God's perspective"
- The world's first fully digital chassis, looking forward to the debut of the U7 PHEV and EV versions
- Design of automotive LIN communication simulator based on Renesas MCU
- When will solid-state batteries become popular?
- Adding solid-state batteries, CATL wants to continue to be the "King of Ning"
- The agency predicts that my country's public electric vehicle charging piles will reach 3.6 million this year, accounting for nearly 70% of the world
- U.S. senators urge NHTSA to issue new vehicle safety rules
- Giants step up investment, accelerating the application of solid-state batteries
- Guangzhou Auto Show: End-to-end competition accelerates, autonomous driving fully impacts luxury...
- Very funny single chip microcomputer music playing experiment
- Happy Knowledge: How is the CPU made?
- MY-8188EUS Linux-3.0.35 Host-AP User Guide
- Can the highest main frequency of DSP be obtained from the chip model?
- Is there a 24-bit AD chip with a gain of 256?
- Semiconductor Industry News
- Transferred from IC Crawler-bananaPi M3 Full Version OPENCV3 Installation Tutorial
- How to choose the packaging form of resistors and capacitors? Are there any principles?
- Smart Power Switches: Applications in the Automotive Environment
- EEWORLD University Hall----Microelectronics Technology (Harbin Institute of Technology)