Single-key circuit design and corresponding program based on single-chip microcomputer

Publisher:北极星小鹏Latest update time:2014-03-09 Source: 21IC Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Single key means that each key occupies one pin of the microcontroller. The characteristics of this connection method are that the circuit and program are very simple, but the disadvantage is that it occupies many pins of the microcontroller and consumes a lot of hardware resources. This connection method is generally suitable for 6 or no more than 6 keys.

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 the PC port of 8255 as an input pin, and this port pin is only connected to one key. This connection method is the 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.

 

 

Figure 1 Single-key circuit

When a key, especially a mechanical key, is pressed, there will be a certain amount of jitter, which will last for a 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 instead of anti-shake circuits, but they use delay circuits of tens of milliseconds. Such programs will undoubtedly increase the time overhead of the program and are not conducive to the rapid response of the program.

We can use program processing to turn the keys into so-called differential keys. The so-called differential actually means that we only process the changes in the keys, 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 and analysis are given below.

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 characteristic variable ktz is set to 0 and the function is exited, 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 time it is pressed), it will enter the key processing part. Key processing mainly defines the key coding, 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, and 8. 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:

 

 

Figure 2 Flowchart of the single-key input function

 

 

 

 

Reference address:Single-key circuit design and corresponding program based on single-chip microcomputer

Previous article:Secondary Active Clamp Circuit of DC-DC Forward Converter
Next article:Stepper Motor Control Based on 8XC196MC Waveform Generator

Latest Power Management 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号