High-efficiency key detection method
A detection method and high-efficiency technology, applied in error detection/correction, detection of faulty computer hardware, instruments, etc., can solve problems such as increasing program complexity, reducing program real-time performance, and low detection efficiency, and saving MCU resources. Effect
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Publication Date
- 2018-03-30
- Estimated Expiration
- Not applicable · inactive patent
Abstract
Description
Technical field:
[0001] The invention relates to the technical field of electronic control, in particular to a high-efficiency button detection method. Background technique:
[0002] For the button detection of electronic devices with button functions, the traditional method is to detect the IO port corresponding to the button when using it. This detection method needs to be filtered and the button is debounced when it is used, and the detection efficiency is low. It improves the real-time performance of the program and increases the complexity of the program at the same time. Invention content:
[0003] The technical problem to be solved by the present invention is to provide a high-efficiency button detection method with high detection efficiency, which improves the real-time performance of the program and reduces the complexity of the program.
[0004] The technical solution of the present invention is to provide a high-efficiency button detection method,
[0005] Fir...
Examples
Embodiment 1
[0016] Provide a high-efficiency button detection method,
[0017] First define some variables, which are used to control the button scanning frequency, record the result of the last button detection PrevKeyValue, the result of this detection button KeyValue, the long press time count KeyLongCount and the long press flag KeyLongFlag;
[0018] Add one to the variable used to control the key scanning frequency every specific time, and the specific time is less than 10ms. When the accumulated time is greater than or equal to 20ms, start detecting the key and clear the variable used to control the key scanning frequency for the next time detection;
[0019] Then assign the value of the result KeyValue of this detection button to the result PrevKeyValue of the last button detection, and then clear the value of the result KeyValue of this detection button;
[0020] Then start to detect the value of the key this time, read the state of the IO port connected to the key, and then assi...