51 Experiment 11: The 16 keys of the matrix keyboard represent 0-9, a-f respectively, and the last digit is displayed by the digital tube
#include #include typedef unsigned int u16; typedef unsigned char u8; #define GPIO_DIG P0 #define GPIO_KEY P1 //Digital Tube sbit LSA=P2^2; sbit LSB=P2^3; sbit LSC=P2^4; //Digital watch u8 code smgduan[16]={0x3f,0x06,0x5b,0x4f,0x66, 0x6d,0x7d,0x07,0x7f,0x6f, 0x77,0x7c,0x39,0x5e,0x79, 0x71}; //Store button number u8 KeyValue; //Delay function void delay(u16 i) { while(i--); } //Get the button number void KeyDown() { char a=0; GPIO_KEY=0x0f; if(GPIO_KEY!=0x0f) { // Determine the column switch(GPIO_KEY) { case(0x07):KeyValue=0;break; case(0x0b):KeyValue=1;break; case(0x0d):KeyValue=2;break; case(0x0e):KeyValue=3;break; } GPIO_KEY=0xf0; //Confirm the row 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; } while((a<50)&&(GPIO_KEY!=0xf0)) { delay(1000); a++; } } } void main() { while(1) { //Get the button number KeyDown(); //Determine the position of the digital tube LSA=0;LSB=0;LSC=0; //keyvalue determines the number GPIO_DIG=smgduan[KeyValue]; } }
Previous article:51 Experiment 12: Digital tube display 12345678
Next article:51 Experiment 10: Independent button controls a digital tube to display 0-9, and only adds 1 when pressed once.
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- 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