/******************************************************** * * 4*3 matrix key read and write function * ********************************************************/ //Button reading and writing program //Row 1 P65 //Row 2 P62 //Row 3 P51 //Row 4 P67 P5:1 P6:257 //Column 1 P63 //Column 2 P64 //Column 3 P66 //Key decoding //Row 4: 0,1,2;Row 1: 3,4,5;Row 3: 6,7,8;Row 2: 9,10,11; //*0# 123 789 456 const uchar key_rel[]={0x0a,0x00,0x0b,0x01,0x02, 0x03,0x07,0x08,0x09,0x04,0x05,0x06}; void scan_key(void) { fly i; keybuf=0xff; get_bit=0; /*Method 1: row output, column input, affects AT24C02, LED flashes //The port direction of sleep wake-up, undervoltage detection, and sound and light indication does not need to be changed //Line output 0 //P5CR&=0x0d; //0000 1101 initialize P5 to all output ports P5CR=0xf0; P6CR&=0x5b;//0101 1011 // Column input 1 P6CR|=0x58;//0101 1000/ //Method 2: Column output, row input, column 1 string 10K, if low level cannot be output, it may not be recognized // Will not affect AT24C02, LED indication, other operations require redefining the port direction //Output column 0 P6CR&=0xa7;//1010 0111 //Line input 1 P5CR|=0x02;//0000 0010 P6CR|=0xa4;//1010 1000*/ /*Method 3: Use method 2 to scan the columns first, and then read and write column 1 separately //Column 1 reading and writing experiment P5CR=0xf0; P6CR&=0x5b;//0101 1011 // Column input 1 P6CR|=0x58;//0101 1000/ KH1=0;KH2=0;KH3=0;KH4=0; if(KL1==0)keybuf=0x01;//A key is pressed in column 1 while(KL1==0); // Column 23, read and write */ // Final version of the key reading and writing program, low level scan line 2, all lines are pulled low //Line output 0 P6CR&=0x5b;//0101 1011 // Column input 1 P6CR|=0x58;//0101 1000/ for(i=0;i<4;i++) {switch(i) {//No AT24C02 operation, try not to open KH4 to power AT24C02 case 0:KH1=1;KH2=1;KH3=1;KH4=0;break;//Scan line 4 case 1:KH1=0;KH2=1;KH3=1;KH4=0;break;//Scan line 1 case 2:KH1=1;KH2=1;KH3=0;KH4=0;break;//Scan line 3 //Finally scan the red and green LED common terminals, pull them all low, and no LED lights up during full scan case 3:KH1=0;KH2=0;KH3=0;KH4=0;break;//Scan line 2 } delay(200); if(KL1==0){keybuf=0x00;get_bit=1;break;} if(KL2==0){keybuf=0x01;get_bit=1;break;} if(KL3==0){keybuf=0x02;get_bit=1;break;} } if(get_bit==1) //Get the key value {get_bit=0; //Delay to remove jitter //delay(250);// //The scan status has been saved switch(keybuf) {case 0x00:if(KL1==0)get_bit=1;;break; case 0x01:if(KL2==0)get_bit=1;;break; case 0x02:if(KL3==0)get_bit=1;;break; default:keybuf=0xff; } if(get_bit==1) {keybuf=i+i+i+keybuf; //decode key i=key_rel[keybuf];//decode key keybuf=i; //Get the key value //Button sound and light indication buzzer(); //Wait for the button to pop up KH1=0;KH2=0;KH3=0;KH4=0; delay(80); while((KL1&&KL2&&KL3)==0); } else keybuf=0xff; } else keybuf=0xff;//Invalid key //Line 2 invalid reading and writing analysis //TCC pin CONT instruction 0x0* } /******************************************************** * * END key_scan * ********************************************************/
Previous article:A large collection of microcontroller LED running lights and flashing lights programs
Next article:TLC5620 generates frequency-adjustable three-phase sinusoidal signals
Recommended ReadingLatest update time:2024-11-16 15:57
- Popular Resources
- Popular amplifiers
- Network Operating System (Edited by Li Zhixi)
- Microgrid Stability Analysis and Control Microgrid Modeling Stability Analysis and Control to Improve Power Distribution and Power Flow Control (
- MATLAB and FPGA implementation of wireless communication
- Introduction to Internet of Things Engineering 2nd Edition (Gongyi Wu)
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
- Qorvo Boosts Performance with Powerful New Multi-Time Programmable PMIC
- TMS320F28335 Interrupt Management Module PIE
- CC2640R2: How to use the chip's internal Bootloader to burn the program
- Proteus emulation of micropython method
- What is the principle of the reading pen? How does it improve the accuracy of reading?
- Where is the lucky star? ——"Keysight Technology Double 11 Instrument Flash Sale"
- My design is equivalent to changing the original manual control to automatic control. The overall design idea is as follows, but at this stage it is still...
- Play with the Internet of Things and make a smart greenhouse model!
- I used the AD18STM32 library to import the chip, but the chip pins are incomplete
- MSP430 interrupt nesting mechanism