The following is the circuit diagram:
The keyboard scanning function of the 51 single-chip microcomputer + 8255 chip only does simple input and output, and uses the P1 port to control the light-emitting diode. If the key value is 7, the key code is 0x07;
Source program:
#include#include #define uchar unsigned char #define uint unsigned int #define LScan XBYTE[0x7f00] //column scan address #define HScan XBYTE[0x7f02] //row scan address //Delay function void delay(uint i) {uint j; for(j=i;j>0;j--) { ; } } //Function to detect whether a key is pressed uchar CheckKey() //Returns 0xff if a key is pressed, otherwise returns 0 { uchar i; LScan = 0x00; i=(HScan & 0x0f); if(i==0x0f) return(0); else return(0xff); } //********Keyboard scanning subfunction*********** uchar KeyScan() { //If no key is pressed, return oxff; if yes, return the key code uchar ScanCode; uchar CodeValue; uchar k; uchar i,j; if(CheckKey()==0) return(0xff); //No key pressed, return 0xff else { delay(200); //delay if(CheckKey()==0) return(0xff); //No key pressed, return 0xff else { ScanCode=0x01; //Set the column scan code, the initial value of the lowest bit is 0 for(i=0;i<8;i++) // Scan column by column 8 times { k=0x01; //Assign initial value to row scan code LScan=~ScanCode; //Send column scan code CodeValue=i; //The key code is the value of i. The key code of each column in the zeroth row is 0, 1, 2, ... 7, which is consistent with the value of i for(j=0;j<4;j++) { if((HScan & k) ==0) //Is it in the current column? { while(CheckKey()!=0); //If yes, wait for the key to be released return(CodeValue); //Return key code } else //Otherwise, the key code is increased by 8, and the key codes on each row of the same column differ by exactly 8 { // Shift column scan code k right one position and scan the next row CodeValue+=8; k<<=1; } } ScanCode<<=1; //After scanning each row, the column scan code is shifted right by one position and the next column is scanned } } } } main() { uchar Key; P1=0x00; //Initialize, turn off the digital tube first XBYTE[0x7f03]=0x81; //8255 initialization, set port A output, port C low 4 bits input while(1) {Key=KeyScan(); if(Key!=0xff) P1=Key; } }
Previous article:12864-ST7920 LCD Graphics Introduction
Next article:Design of electronic speed and mileage anti-theft alarm
Recommended ReadingLatest update time:2024-11-16 19:56
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
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
- Xiaomi Mi 10 makes GaN popular! Learn about GaN simulation modeling in 10 minutes
- Has the United States loosened its grip? TSMC has obtained permission to supply Huawei, and the NBA can also be watched!
- Getting Started with CC256x
- Today at 10 am, there will be a prize live broadcast | Explore the high technology of network cameras with Infineon
- GA and CAN controller MCP2515 design inertial navigation system CAN bus interface.pdf
- GD32L233C-START Development Board Evaluation: Introduction to the Development Board (I)
- Help, DC motor driver chip selection
- Does anyone know which chip can be used to replace the ISM330DLC or other brands? I look forward to your replies!
- LSM6DS3TR-C related information
- Strengthen physical exercise after work