Application of keyboard interface in communication between microcontroller system and PC

Publisher:chinalisaLatest update time:2006-05-07 Source: 电子技术应用 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

    Abstract: This paper proposes a new solution for realizing communication between microcontroller system and PC using keyboard interface, introduces the principle of communication between keyboard and PC, and successfully applies it to actual systems. This solution provides an effective way for the external microcontroller system to communicate with the PC.

    Keywords: keyboard interface microcontroller system timing command words

In industrial control systems, the communication between the microcontroller application system and the PC mainly uses asynchronous serial communication, which is realized through the RS-232C, RS-422, RS-423 or RS-499 standard interface. This causes each communication method to stipulate its own electrical standards, and none of them can directly meet the transmission requirements of TTL level. In order to communicate through these standard interfaces, a level conversion chip must be added to the microcontroller application system to realize the conversion of TTL levels to standard interface levels [1].

The keyboard interface is an inherent interface of the PC. In many industrial control systems, the keyboard of the industrial PC is easily damaged due to high temperature and dust, so only the mouse is used as a tool for human-machine dialogue, and the keyboard interface is in an idle state [2]. Using the keyboard interface as the communication interface between the microcontroller application system and the PC has the following advantages: ① The electrical standard of the keyboard interface can meet the transmission requirements of TTL levels without level conversion; ② The operating system kernel of the PC can interpret the microcontroller application system The data transmitted through the keyboard interface eliminates the need to write a serial data receiving program; ③The PC can provide +5V power supply.

1 Principle of communication between keyboard and PC

1.1 Keyboard interface structure

PC keyboards are divided into three types: PC/XT, PC/AT and PS/2. PC/XT and PC/AT keyboards are connected to the PC via a 6-pin DIN plug. The three keyboard interfaces have similar structures. When they are used to communicate with external microcontroller application systems and PCs, the effective interface pins are 4. Their numbers and definitions on the interface are: 1. Keyboard clock, 2. Keyboard data; 4, ground; 5, +5V.

1.2 Communication timing between keyboard and PC

When the keyboard is powered on for the first time, the keyboard logic circuit generates a power-on reset signal and the keyboard begins self-test. During self-test, any signals on the data and clock lines are invalid. If the self-test is correct, the keyboard sends 0AAH to the PC, and then starts the keyboard scan.

In the communication between the keyboard and the CP computer, there are two transmission protocols: XT transmission protocol and AT transmission protocol. In the transmission mode using the XT protocol, the keyboard can only receive reset instructions from the PC and send data to the PC, which has no great application value. Only in the transmission mode using the AT protocol, the keyboard can receive instructions from an AT-PS/2 compatible PC and send data to the PC. The data frame length is 11 bits, consisting of a start bit (low level), 8-bit data (low bit first, high bit last), parity bit (odd parity) and stop bit (high level). Figure 1 is a timing diagram of communication between the keyboard and PC using AT transmission protocol.

When there is no data transmission, the keyboard interface data line and clock line are both high level. The interface clock signal is provided by the keyboard, and its frequency should be at least 733.33Hz to ensure accurate transmission and reception of data. Before the keyboard sends data, the keyboard detects the level of the interface clock line and data line. If the clock line is low, the host prohibits the keyboard from sending data. The keystroke codes on the keyboard are sent to the cache for buffering. The keyboard is allowed to send data only when both the data line and the clock line are high. At this time the keyboard sends data and clock signals to the host. When the keyboard sends data, it first pulls the data line low to send the start bit, then sends 8-bit data in sequence, and finally sends the parity bit and stop bit. Each bit of data is valid on the falling edge of the clock pulse and changes during the high level of the clock pulse. If the computer pulls down the clock line for at least 60 μs before the 10th bit (the parity bit) is sent, the keyboard stops sending and stores the fault data in the output buffer. After the data is sent, keep the data line and clock line high. After the PC receives the data, if there is an error, the keyboard is required to resend it. When the PC requests to send data, the PC pulls the data line low, and the keyboard enters the data receiving state and sends a clock signal. Each bit of data is valid on the rising edge of the clock pulse and changes during the low level of the clock pulse. After the keyboard receives 11 bits of data, it pulls the stop bit low as a response signal, indicating that the data reception is complete. The keyboard judges the received data, and if there is an error, the PC is asked to resend it.

1.3 Command words for communication between keyboard and PC

There are many command words for communication between the keyboard and the PC. Only the command words related to the communication between the microcontroller system and the PC are introduced below. Table 1 shows the command words sent by the PC and keyboard and their corresponding hexadecimal values.

Table 1 Command words sent by PC and keyboard and their hexadecimal values

Command word sent by PC Hexadecimal value Command words sent by keyboard Hexadecimal value
Set/reset mode indicates
ECHO
allows
Resend
Reset
ED
EE
F4
FE
FE
Self-test completion code
Self-test error code
ECHO
confirmation
Resend
AA
FC
EE
FA
FE

At any time the PC can send command words to the keyboard. Except for the following two situations, the keyboard must generally respond to the confirmation command word 0FAH within 20ms: (1) When the PC sends the ECHO command (0EEH), the keyboard responds with ECHO (0EEH), indicating that the communication is normal; (2) When the PC When requested to resend data, the keyboard resends the last data sent.

2 Concept and examples of communication between microcontroller application system and PC through keyboard interface

2.1 The concept of microcontroller application system communicating with PC through keyboard interface

The microcontroller application system communicates with the PC through the keyboard interface and must strictly follow the timing requirements for communication between the keyboard and the PC and respond according to the command words. When the system is powered on and reset, the microcontroller application system sends 0AAH through the keyboard interface to simulate the keyboard self-test completion information. After that, the MCU application system detects the level of the data line of the keyboard interface. If the data line level is pulled down by the PC, the MCU system enters the data receiving state and receives command information or data information according to the timing sequence in Figure 1. The MCU system receives the data according to Table 1. Information is explained. When the microcontroller system wants to send data or commands, the information is sent according to the timing in Figure 1, and the command words are sent according to the timing in Table 1. The PC operating system can recognize these keyboard commands and perform corresponding operations. The data sent simulates the encoding of each key on the keyboard, and the PC operating system can interpret the encoding as the corresponding keyboard characters. In the PC-side communication program, corresponding operations are performed according to the received strings, thus eliminating the need to write a program that interprets the binary stream received by the PC-side into corresponding characters.

2.2 Examples

In a temperature measurement microcontroller application system, the measured temperature information is required to be displayed on the PC regularly. The system consists of 3 parts: temperature detection part, signal conversion part, and signal processing part. The external temperature is measured through the integrated temperature measuring element AD590. AD590 is a current-mode component with a temperature measurement range of -55°C to 100°C and a resolution of 1 μA/ °C. After the signal conversion part (composed of standard operational amplifier circuit and A/D components), the current signal is converted into a digital signal. The output result is sent to the I/O port of 89C51. After being processed by the program, the temperature information is converted into string information and sent to the PC through the keyboard interface. The data line and clock line of the keyboard interface are connected to pins 7 and 8 (P0.6, P0.7) of the P0 port of the 89C51 respectively. The measuring system's power supply is taken directly from the keyboard interface.

The communication program between the temperature measurement system and the PC through the keyboard interface includes two parts: the PC communication program and the microcontroller application system communication program. The PC communication program is very simple: under C language conditions, use the getchar function to receive data, and what is received are characters interpreted by the operating system. Use the outport function to write data to the keyboard port (60H). In contrast, the communication program of the single-chip microcomputer application system is more complicated. Figure 2 is a partial flow chart of the communication program of the single-chip microcomputer application system.

Reference address:Application of keyboard interface in communication between microcontroller system and PC

Previous article:RS-485 communication card and its application
Next article:Simplified interface for communication between microcontroller and PC

Latest Industrial Control 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号