Key microcontroller key jitter

Publisher:悠闲时光Latest update time:2024-04-10 Source: elecfansKeywords:key Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1 //write by:cyt

2 //Time:2017-2-10

3 //Porject Name:key shake_destory

4 #include

5 #define GPIO_KEY P0 ///

6 void Delay1ms(unsigned char n);

7 unsigned char Key_Scan() // GPIO_KEY is a global variable, input here

8 {

9 unsigned char i=0,Key_Value=0;

10 if(GPIO_KEY!=0xff)

11 {

12 Delay1ms(10);

13 if(GPIO_KEY!=0xff)

14 Key_Value = GPIO_KEY;

15 while(GPIO_KEY!=0xff&&i<50)

16 {

17 Delay1ms(10);

18 i++;

19 }

20 }

21 return Key_Value;

twenty two }


Why does the key jitter?

The switch used for common buttons is a mechanical elastic switch. When the mechanical contacts are opened and closed, due to the elastic effect of the mechanical contacts, a button switch will not be immediately and stably connected when closed, nor will it be disconnected all at once when disconnected. Therefore, there will be a series of jitters at the moment of closing and disconnecting. The measure to avoid this phenomenon is to eliminate the jitter of the button.


Jitter Time

The length of the jitter time is determined by the mechanical characteristics of the key, generally 5ms to 10ms. This is a very important time parameter and is used in many occasions. Click to view the picture The length of the key stable closing time is determined by the operator's key action, generally a few tenths of a second to several seconds. Key jitter can cause a key to be misread multiple times. To ensure that the CPU processes a key closure only once, key jitter must be removed. Read the key status when the key is closed stably, and it must be determined that the key is released stably before processing.


Key debounce

To debounce a key, you can use either hardware or software.


Hardware debounce

When the number of keys is small, key jitter can be eliminated using hardware methods.

Two NAND gates form an RS flip-flop.

When the key is not pressed, the output is 0; when the key is pressed, the output is 1. At this time, the mechanical properties of the key are used to make the key disconnected instantly due to elastic jitter (jitter jump B). The key does not return to the original state A, the state of the bistable circuit does not change, the output remains 0, and no jittering waveform is generated. In other words, even if the voltage waveform at point B is jittering, after passing through the bistable circuit, its output is a regular rectangular wave. This can be easily verified by analyzing the working process of the RS trigger.


Software debounce

There are many buttons, and software methods are commonly used to debounce

That is, after detecting that the key is closed, a delay program is executed, with a delay of 5ms to 10ms, so that the leading edge jitter disappears and the key state is detected again. If the closed state level is still maintained, it is confirmed that the key is really pressed. When the key is released, a delay of 5ms to 10ms is also given, and the key processing program can only be transferred after the trailing edge jitter disappears.


Keywords:key Reference address:Key microcontroller key jitter

Previous article:51 single chip microcomputer dynamic digital tube
Next article:51 MCU delay calculation method

Recommended ReadingLatest update time:2024-11-15 02:31

Digi-Key and Truphone Collaborate to Democratize IoT Connectivity with the Touch of a Button
Digi-Key Electronics, a global electronic components distributor, has announced a partnership with Truphone to provide cellular IoT connectivity services to manufacturers around the world. The partnership will bring connected cellular devices and a fully managed service to customers.   Digi-Key will leverage Truphone'
[Internet of Things]
Digi-Key and Truphone Collaborate to Democratize IoT Connectivity with the Touch of a Button
Digi-Key Electronics Announces Global Distribution Partnership with ArkX Laboratories
Digi-Key Electronics, the world's broadest and fastest-stock electronic components distributor, has announced a strong global distribution partnership with ArkX Laboratories for its advanced far-field voice acquisition AFE modules and voice-enabled IoT product development kits. This advanced far-field voice capture
[Analog Electronics]
Digi-Key Electronics Announces Global Distribution Partnership with ArkX Laboratories
SK Hynix to acquire 8-inch wafer foundry Key Foundry for $492 million
SK Hynix, the world's second-largest memory chipmaker, said on Friday it would acquire South Korean foundry Key Foundry for 576 billion won ($492 million). Reuters reported that SK Hynix said in a statement that the 8-inch wafer foundry mainly produces chips such as power management, display driver and microcontroll
[Mobile phone portable]
[bsp layer][nrf52832][nrf52840][nrf52810][nrf52820][bsp_key] KEY configuration and use
The code will explain how to implement the key scanning function and register key events (single click/double click/long press/long long press/press/release) /******************************************************************************** * @file    bsp_key.c * @author jianqiang.xue * @version V1.0.0 * @date    202
[Microcontroller]
Digi-Key Announces Global Distribution Agreement with SPARK Microsystems
Digi-Key Electronics, the global distributor of the broadest selection of electronic components with the fastest shipping, today announced a global distribution agreement with SPARK Microsystems to provide ultra-low power wireless communication devices for high-performance personal area networks and Internet of Things
[Internet of Things]
Digi-Key Announces Global Distribution Agreement with SPARK Microsystems
STM8L151C8 study notes 2: KEY driver
Function: Use the button to turn the LED light on and off. The high and low levels of the button are determined by an external circuit. If the button is not pressed, the default is a high level; if the button is pressed, it is a low level. Key detection mainly generates key signals based on the level state of the I/
[Microcontroller]
STM8L151C8 study notes 2: KEY driver
Digi-Key Electronics Launches New Scheme-it Capabilities
New features include Ultra Librarian® symbol integration, custom symbol editor, and math markup Digi-Key Electronics, a global distributor of the broadest selection of in-stock electronic components with the fastest shipping, has released new features for its popular Scheme-it tool, a free online schematic and diagr
[Microcontroller]
Digi-Key Electronics Launches New Scheme-it Capabilities
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号