Key jitter
There is a sound when a key is pressed. Although some key press sounds are very slight, these are all vibrations caused by the collision of metal conductors; this phenomenon is called: key jitter.
If the jitter of the keys is not dealt with, the keys will cause unexpected interference to the system circuit or program. Therefore, we need to "de-bounce" the keys.
The key is effective after being pressed and lifted
Using the delay function, the key1 is pressed and then released to control the LED to flash;
#include sbit key1 = P1^4; //key1 on the experimental board sbit LED0 = P0^0; unsigned char key1_down; void delay(unsigned int delay_time) { unsigned int j = 0; for(;delay_time > 0;delay_time --) { for(j = 0;j < 125;j ++); } } void key_pressed(void) //key scan function { if(key1 == 1); //If the key is pressed { delay(20); //eliminate keyboard jitter if(key1 == 1) //If the key is pressed key1_down = 1; //Memory key1 pressed state } if((key1 == 0) && (key1_down == 1)) //key1 was pressed before and is now lifted { LED0 = !LED0; //LED flashes key1_down = 0; //The button pressed status is cleared } } void main(void) { P0 = 0x00; // Turn off all LEDs driven by P0 while(1) key_pressed(); //Call function } The button is effective when pressed It takes effect when the confirmation button is really pressed /* Software debounce */ if (0 == K1) //If a key is pressed { delay_ms(8); //delay for a while to debounce if (0 == K1) //If a key is pressed, it is detected to be in a stable closed state { //Statement block; //What needs to be done after pressing the button } while (!K1); // Release detection, if you hold down the button, the loop will continue }
Previous article:C51 MCU LCD1602 Driver
Next article:Buzzer (HC6800-EM3 V2.2 development board)
Recommended ReadingLatest update time:2024-11-23 04:57
- 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)
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- Inside the DLP NIRscan Nano Evaluation Module
- How to process the current transformer signal with a single chip microcomputer
- 【2022 Digi-Key Innovation Design Competition】Material Unboxing
- Develop good programming style
- DCDC isolated voltage regulated power supply module supports electric vehicle transmission and conversion, and configures high power supply system!
- Programmable linear constant current source circuit leakage current type: based on PAC chip GP8102, GP8202
- [Repost] Popular Science of Components: NAND Flash Memory
- 1.2 PB Raspberry Pi Disk Array
- Resistive tap monitors and sets W-CDMA power levels
- TI's GaN high-efficiency 1MHz CrM totem-pole PFC converter reference design