The circuit diagram is very simple so I won't draw it. The circuit connection is that port p1 is connected to the matrix keyboard, port p3 is connected to the independent keyboard, and 8 LED lights are connected to port p0.
Reference address:Easily handle independent keyboard control and 4*4 matrix keyboard scanning
#include#define uchar unsigned char #define uint unsigned int #define on 0 #define off 1 sbit led1=P0^0; sbit led2=P0^1; sbit led3=P0^2; sbit led4=P0^3; sbit led5=P0^4; sbit led6=P0^5; sbit led7=P0^6; sbit led8=P0^7; sbit key1=P3^0; sbit key2=P3^1; sbit key3=P3^2; sbit key4=P3^3; sbit key5=P3^4; sbit key6=P3^5; sbit key7=P3^6; sbit key8=P3^7; void delay_ms(uchar time) { flying i,j; for(i=time;i>0;i--) { for(j=85;j>0;j++) {;} } } uchar scan_key() { //fly i,j; //P3=0xff; if((P3&0xff)!=0xff) { delay_ms(30); if((P3&0xff)!=0xff) { if(key1==0) return(1); if(key2==0) return(2); if(key3==0) return(3); if(key4==0) return(4); if(key5==0) return(5); if(key6==0) return(6); if(key7==0) return(7); if(key8==0) return(8); } } return 0; } void main(void) { uchar key_value; key_value=scan_key(); switch(key_value) { case 1:led1=on;break; case 2:led2=on;break; case 3:led3=on;break; case 4:led4=on;break; case 5:led5=on;break; case 6:led6=on;break; case 7:led7=on;break; case 8:led8=on;break; default:P0=0xff; } } 4*4 matrix keyboard #include sbit led1 =P0^0 ; sbit led2 = P0^1 ; sbit led3 = P0^2 ; sbit led4 =P0^3 ; sbit led5 =P0^4 ; sbit led6 =P0^5 ; sbit led7 = P0^6 ; sbit led8 = P0^7 ; #define on 0 #define off 1 #define uchar unsigned char #define uint unsigned int void delay_ms(uint time) { uint i,j; for(i=time;i>0;i--) for(j=112;j>0;j--) {} } //d/* uchar s_scan(void) { uchar scan_code,temp; P1=0xf0; if((P1&0xf0)!=0x0f) { delay_ms(30); if((P1&0xf0)!=0xf0) { scan_code=0xfe; while((scan_code&0x10)!=0) { P1=scan_code; if((P1&0xf0)!=0xf0) { temp=(P1&0xf0)|0x0f; while((P1&0xf0)!=0xf0) return ((~scan_code)+(~temp)); } else scan_code=(scan_code<<1)|0x01; } } } return 0; } //*/ /* uchar s_scan(void) { flying scanh,scanl; P1=0xf0; if((P1&0xf0)!=0xf0) { P1=0xf0; delay_ms(30); if((P1&0xf0)!=0xf0) { P1=0xfe ; //P1=scan; if((P1&0xf0)!=0xf0) { P1&=0xf0; if(P1==0xe0) return(1); if(P1==0xd0) return(2); if(P1==0xb0) return(3); if(P1==0x70) return(4); } P1=0xfd; if((P1&0xf0)!=0xf0) { P1&=0xf0; if(P1==0xe0) return(5); if(P1==0xd0) return(6); if(P1==0xb0) return(7); if(P1==0x70) return(8); } P1=0xfb; if((P1&0xf0)!=0xf0) { P1&=0xf0; if(P1==0xe0) return(9); if(P1==0xd0) return(10); if(P1==0xb0) return(11); if(P1==0x70) return(12); } P1=0xf7; if((P1&0xf0)!=0xf0) { P1&=0xf0; if(P1==0xe0) return(13); if(P1==0xd0) return(14); if(P1==0xb0) return(15); if(P1==0x70) return(16); } } } return 0; } */ void main(void) { uchar key_code; while(1) { key_code=s_scan(); if(key_code) P0=key_code; /* delay_ms(300); led1=~led1; delay_ms(300); switch(key_code) { case 1:led1=on;break; case 2:led2=on;break; case 3:led3=on;break; case 4:led4=on;break; case 5:led5=on;break; case 6:led6=on;break; case 7:led7=on;break; case 8:led8=on;break; default:P0=0xff; } */ } }
Previous article:LCD12232 Serial Display C51 Program
Next article:C0851F410 and 12864 LCD display
- Popular Resources
- Popular amplifiers
Recommended Content
Latest Microcontroller Articles
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- 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
MoreDaily News
- 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
Guess you like
- 【Smart network desk lamp】9. Maix bit driver serial port
- [N32L43X Review] 3. Debugging tools JlinkRTT&Shell
- From getting started with Linux to doubting your life?
- How to accelerate the discharge of capacitors
- How to choose between mobile phone and tablet
- During electrical inspection, Warning Unconnected Power Object On Net GND appears
- How to understand the parameters of the second bus chip PB620?
- Trinocular Stereo Vision Epipolar Line Correction and Its FPGA Implementation
- TE Award-winning Event | How to effectively respond to current challenges in the field of test and measurement
- Questions about the design of the power supply system of the weighing instrument