Design of control keyboard based on AT89C51

Publisher:omicron25Latest update time:2015-07-31 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Introduction 

In some automated measurement or intelligent equipment, the microcomputer acts as the control center to control and manage multiple functional units to realize the system functions of the instrument and equipment. The keyboard is the basic device for human-computer communication, and the operator uses it to control the equipment. The universal keyboard of the PC is an independent device separated from the host, and its structure and appearance are fixed, requiring a large installation space. However, in the developed product equipment, after the system is powered on, only a small number of keys in the universal keyboard are often needed to complete human-computer communication or control, such as the numeric keys O~9, →, ←, ↑, ↓, Esc and other keys. In this case, due to the limitation of the structural size, and in order to facilitate the control and simplify the equipment, it is inconvenient to use a universal keyboard, and the universal keyboard needs to be miniaturized and integrated with the product equipment. Therefore, it is necessary to develop a small integrated special keyboard. 

The use of a small integrated special keyboard can not only complete the function of the key, but also requires an integrated optimization design according to the appearance of the instrument, so that the product has a beautiful appearance and a reasonable layout. The small integrated special keyboard is not only suitable for general instrument control systems, but also can be used in military reinforced computer systems. The microcomputers in military products are mostly reinforced PC computers, which use a PC universal keyboard. This paper takes the PC universal keyboard as an example to explain the method of developing a small integrated special keyboard. 

1 Design principle 

The PC universal keyboard is connected to the host through a "PS/2" 5-core cable. The 5-core cable is the path for information and data transmission between the keyboard and the host, and is defined as follows: Terminal 1, RESET; Terminal 2, +5 V; Terminal 3, CLOCK; Terminal 4, ground; Terminal 5, key waveform. The signals at terminals 1, 2, and 4 are determined by the host; Terminal 3 is the clock signal CLOCK; Terminal 5 is the key waveform, which changes with the key pressed. 

Using the single-chip control system and software programming method introduced in this paper, the key waveform can be accurately simulated, so that the key waveform of the small special keyboard is consistent with the corresponding key waveform of the PC universal keyboard. The specific method is as follows: First, use an oscilloscope to measure the waveform of each key of the PC universal keyboard when it is pressed, and save it; then use the single-chip control system and software programming to simulate the CLOCK waveform and key waveform of each key, and ensure that the CLOCK waveform and key waveform of each key match the timing and shape, and then transmit the key information to the host through the 5-core cable. The selected keys can be installed on the panel of the product or other places that are easy to operate as needed. When the operator presses a key, the single-chip control system generates the corresponding CLOCK waveform and key waveform and sends it to the host to realize the key function. In this way, the design of the small special keyboard is completed. 

2 Hardware circuit and software 

2.1 Single-chip control circuit 

The hardware circuit of the small special keyboard is realized by using the single-chip system. As shown in Figure 1, the designed small special keyboard has 18 keys arranged in a matrix of 6 rows × 3 columns. The single-chip can be installed on the interface board inside the host as needed, and the keys are installed in the panel of the product or other places that are easy to operate. When a key is pressed, the single-chip control system transmits the generated CLOCK signal and key signal to the host through the "PS/2" 5-core cable. This hardware circuit is simple and can make full use of software programming to simulate the key waveform to realize the keyboard function. To determine whether a key is pressed, the system can use the software to query the keys in the 6-row × 3-column matrix one by one, and then output the corresponding key simulation waveform to realize the key function. 

2.2 Example 

The following uses the key "8" as an example to explain how to "take out" the required keys from the universal keyboard of a PC and keep the functions of each key to form a small special keyboard. First, use an oscilloscope to measure the waveforms at the 3rd and 5th ends of the 5-core keyboard communication cable when the "8" key is pressed on the universal keyboard of the PC. The waveform measurement waveform of the key "8" is shown in Figure 2. 

Oscilloscope channel 1 indicates the CLOCK waveform at the end 3 of the signal cable, and channel 2 indicates the waveform of the key "8" at the end 5 of the cable. Use the single-chip microcomputer software to program and simulate the waveform shown in Figure 2. According to the hardware circuit shown in Figure 1, program the P2.4 end of the single-chip microcomputer 89C51 to generate a CLOCK waveform and the P2.6 end to generate a key waveform; the P2.4 end is connected to the 3 end of the 5-core keyboard cable, and the P2.6 end is connected to the 5 end of the cable. When the operator presses the "8" key on the product panel, the program executes the subroutine to simulate the waveform of the "8" key and transmits the simulated waveform to the host, thus completing the design of the key "8". In the same way, other keys on a small special keyboard can be designed. [page]

3 Issues to be noted in the design 

3.1 Accurately simulate the key waveform 

The waveform of each key includes the CLOCK waveform at the end 3 of the cable and the key waveform at the end 5 of the cable. The CLOCK waveform of each key is the same. As shown in Figure 2, the waveform of channel 1 is formed by 10 pulses with a pulse width of 40μs and an interval of 40μs and 1 pulse with a pulse width of 500μs. The key waveforms at terminal 5 vary depending on the key. To accurately simulate the key waveform and match the timing, that is, to accurately calculate the width of the pulse, the time constant must be accurately calculated and the delay program must be prepared. If the microcontroller control circuit uses a 12 MHz crystal oscillator, then a machine cycle is 1μs, and the calculation formula for the time constant X is: 

(Number of loop bytes) × machine cycle × time constant X = delay time 

In the above formula, the number of loop bytes, machine cycle, and delay time are all known, so the time constant x is easy to obtain. For example, the delay program for 1 ms is as follows: 

Using the above formula, we can get: (1+1+2)×1×X-1 000 μs, then X=250μs. Substitute it into the above program segment and execute this program segment to achieve a precise delay of 1 ms. Accurately calculating the time constant and accurately achieving the delay can ensure the accuracy of the analog waveform. 3.2 Key jitter problem For 

any system with key operation, key debounce should generally be considered in the design. Since the mechanical contact of the key has elasticity, there is a jitter process at the moment of closing and opening. The length of the jitter is related to the mechanical characteristics of the switch, generally 5 to 10 ms. In order to ensure that a key closure is only processed as a key input, the impact of key jitter on the system must be eliminated. 

The method of eliminating the impact of key jitter using software programming is: when a key is detected to be pressed, after executing the corresponding subroutine to simulate the key waveform, it should be determined whether the key bounces up. If not, wait until the key bounces up; after the key bounces up, delay 20 ms before continuing to execute the following program to eliminate the key jitter phenomenon. 

3.3 The problem of multiple keys in the same row being valid at the same time 

When there is a key operation, when a key is pressed, it is possible that multiple other keys in the same row of the key are valid at the same time. This problem can be solved by shielding the non-current column line: when detecting whether a key is pressed, the column line and the row line must be scanned in sequence. When scanning to a certain column line, the column line is set to "0" and the other column lines are set to "1". In this way, the non-current column line is shielded, so as to accurately determine whether a key is pressed. 

3.4 The problem of key waveform being eaten up 

Some keys have only one waveform segment, such as the waveform of the "8" key shown in Figure 2; while some keys have two or more waveform segments, such as the waveform of the "ten" up key shown in Figure 3. The interval between the two waveform segments is 1.6 μs. When the key waveform is simulated with a single-chip microcomputer, it can be seen that after the first waveform segment is formed, the clock CLOCK remains at a low level for the next 3 ms, resulting in the second waveform segment of the key being eaten up. In order to solve this problem, when simulating a key with more than two waveforms, a 3 ms delay should be added between the two waveforms to make the second waveform of the key out of the low level area of ​​the clock CLOCK. In this way, the second waveform of the key will not be eaten up, thus ensuring the integrity of the key waveform and realizing the key function. 

Conclusion 

The small integrated special keyboard for reinforcement machine made by the design method introduced in this paper has been applied to the product, and its function is stable and reliable, and has achieved good results. In actual work, this design method can be applied to develop small integrated special keyboards according to the structural characteristics and needs of the product, which has promotion significance.
Reference address:Design of control keyboard based on AT89C51

Previous article:Design and implementation of intelligent fast charger control system based on AT89S52
Next article:Design of electronic therapeutic instrument based on embedded device AT89C51SND1C

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号