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

Publisher:科技舞者Latest update time:2011-11-12 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Single-key means that each key occupies a pin of a single-chip microcomputer. 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 single-chip microcomputer 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 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
One-touch 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

Flowchart of single key input function

Figure 2 Flowchart of the single-key input function [page]




Figure 2 Flowchart of the single-key input function

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

Previous article:A multifunctional AC voltage-stabilized power supply controlled by a single-chip microcomputer
Next article:A high-speed communication implementation scheme based on DSP and single-chip microcomputer

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号