Matrix keyboard, Proteus provides a variety of matrix keyboards, including calculators, telephones, and custom layouts. Encapsulating multiple keys is more vivid. In order to clarify the internal wiring diagram, it is still built using keys.
Before talking about the principle of matrix keyboard, let’s talk about why we use matrix keyboard?
When there are a large number of keys, in order to save IO resources, the keys are usually arranged in a matrix form, and each key is identified by rows and columns. For example, 8 IOs can identify 4*4=16 keys, which is twice as many as directly driving 8 keys.
Principle 1-Reversal scanning method:
In the default state, P10-7 all output high level 1;
First, P1=0x0F, the row line output is 0. If key 7 is pressed, P10=P14=0, then read the row value & 0x0F=0x0E; then read the column value & 0xF0=0xE0, the sum of the two values = 0xEE, and it can be detected that one of the 16 keys is pressed.
KeyPort=0x0f; //Line output is all 0
cord_h=KeyPort&0x0f; //Read column line value
if(cord_h!=0x0f) //First check if any button is pressed
{
DelayMs(10); //debounce
if((KeyPort&0x0f)!=0x0f)
{
cord_h=KeyPort&0x0f; //Read column line value
KeyPort=cord_h|0xf0; //Output current column line value
cord_l=KeyPort&0xf0; //Read line value
while((KeyPort&0xf0)!=0xf0);//Wait for release and output
return(cord_h+cord_l); //Last combination code value of keyboard
}
}
return(0xff); //Return the value
Principle 2 - Line-by-line scanning method:
In the default state, P10-7 all output high level 1;
Then rows P10-P17 output 0xFE=1111 1110, that is, P10=0. So after key 7 is pressed, P14=0, and continue to detect P10-P17=1110 1110=0xEE, so key 7 is pressed.
Then output 0xFD=1111 1101...
KeyPort=0xf0; //The upper four bits are high, and the lower four bits are low
if(KeyPort!=0xf0) // indicates a key is pressed
{
DelayMs(10); //debounce
if(KeyPort!=0xf0)
{ //Indicates that a key is pressed
KeyPort=0xfe; //Detect the first line
if(KeyPort!=0xfe)
{
Val=KeyPort&0xf0;
Val+=0x0e;
while(KeyPort!=0xfe);
DelayMs(10); //debounce
while(KeyPort!=0xfe);
return Val;
}
KeyPort=0xfd; //Detect the second line
if(KeyPort!=0xfd)
{
Val=KeyPort&0xf0;
Val+=0x0d;
while(KeyPort!=0xfd);
DelayMs(10); //debounce
while(KeyPort!=0xfd);
return Val;
}
KeyPort=0xfb; //Detect the third line
if(KeyPort!=0xfb)
{
Val=KeyPort&0xf0;
Val+=0x0b;
while(KeyPort!=0xfb);
DelayMs(10); //debounce
while(KeyPort!=0xfb);
return Val;
}
KeyPort=0xf7; //Detect the fourth line
if(KeyPort!=0xf7)
{
Val=KeyPort&0xf0;
Val+=0x07;
while(KeyPort!=0xf7);
DelayMs(10); //debounce
while(KeyPort!=0xf7);
return Val;
}
}
}
The two principles are actually very similar, one is round-robin training, and the other is direct row and column reversal detection, which is easy to understand. If you are doing a physical object, it is best to add pull-up resistors and capacitors, so that the hardware can play a certain anti-shake function, and coupled with the software's anti-shake function, the detection will be more reliable.
Previous article:Proteus C51 simulation learning board 9——IIC
Next article:Proteus C51 simulation learning board 7——LCD1602
Recommended ReadingLatest update time:2024-11-16 20:59
- Popular Resources
- Popular amplifiers
- 西门子S7-12001500 PLC SCL语言编程从入门到精通 (北岛李工)
- Siemens Motion Control Technology and Engineering Applications (Tongxue, edited by Wu Xiaojun)
- How to read electrical control circuit diagrams (Classic best-selling books on electronics and electrical engineering) (Zheng Fengyi)
- MCU C language programming and Proteus simulation technology (Xu Aijun)
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
- Introduction to DSP GPIO
- Comparison of TI DSP internal structures
- About DM64X interrupt response delay problem
- Does anyone have the pin definition of the 20pin of the E2 emulator used to program the Renesas RH850 MCU?
- MSP430F4XX series LCD display universal driver
- Examples of embedded system security issues
- What does inductance 10t mean?
- How to Improve Heat Dissipation Using PCB Design
- Does anyone know which layers of AltiumDesigner the PCB production file suffixes correspond to?
- Commonly used PCB software on the market and corresponding common file suffixes