The circuit diagram of the single-key circuit is shown in Figure 1. It can be seen from the figure that one end of each key is directly connected to a pin of a PC port of 8255 as an input pin, and this port pin is only connected to one key. This connection method is a single-key connection method. The single-key connection method requires that one end of the key is connected to a pull-up resistor, and the other end of the key is directly grounded, so that the input pin can always be kept at a high level when the key is not closed. If the program detects that this pin is at a high level, it will be considered that the key of the pin is not pressed, and after the key is closed, the level of the input pin will become a low level. In this way, when the program detects that the input pin is at a low level, it will be considered that the key is pressed.
Single-key circuit
Figure 1 Single-key circuit
Keys, especially mechanical keys, will have a certain degree of jitter after being pressed, and this jitter will last for a very short time. This jitter will cause the program to be abnormal, because the program is likely to think that the key has been pressed many times in such a short time. Many materials specifically mention the anti-shake circuit. Practice has proved that this circuit can be completely ignored and can be completely replaced by a program.
Some materials also use programs to replace the anti-shake circuit, but use a delay circuit of tens of milliseconds. Such a program will undoubtedly increase the program time overhead and is not conducive to the rapid response of the program.
We can use program processing to turn the key into a so-called differential key. The so-called differential actually means that we only process the changes of the key, and we do not process the key information that has not changed. Since the differential key only processes the information of the first change, short-term key jitter will not cause misoperation.
The corresponding key program is given below and analyzed.
In this program, the so-called single-key input is actually reading the information of the PC port of 8255.
The program first checks whether a key is pressed. If not, the key feature variable ktz is set to 0 and the function is exited at the same time, which reduces the running time of useless programs. If a key is pressed and ktz is equal to 0 (indicating that it is the first press), it will enter the key processing part. Key processing mainly defines key codes, because the key values read from the input port usually need to be processed in order to filter out unnecessary information or interference, and at the same time, the input values are regularized into key codes that are easy for us to process. The key codes here are 1, 2, 3, 4, 5, 6, 7, 8, and these 8 numbers correspond to 8 keys. The flowchart of the single-key input function is shown in Figure 2, and the corresponding program is as follows:
Flowchart of the single-key input function
Figure 2 Flowchart of the single-key input function
Figure 2 Flowchart of the single-key input function
Previous article:A portable magnetic memory detector based on PIC microcontroller
Next article:Interfacing the MAX1169 ADC to a PIC Microcontroller
- Popular Resources
- Popular amplifiers
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