Design of Multi-computer Communication Based on 8250

Publisher:心愿成真Latest update time:2012-01-19 Source: 微计算机信息Keywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

There are many ways to achieve serial communication. For example, according to the requirements of the communication protocol, you can use the method of writing a program to complete the reception and transmission of data characters in serial communication, but this method is more troublesome; in order to quickly, easily and effectively achieve serial communication, the PC series and its compatible machines can use a programmable asynchronous serial communication interface chip to execute the asynchronous serial communication protocol. The core of this asynchronous communication interface chip is a large-scale integrated communication component called a universal asynchronous receiver/transmitter, or UART (Universal Asynchronous Receiver/Transmitter).

1. 8051 realizes the principle of multi-computer communication

The three control registers SCON (Serial Controller), PCON (Power Controller) and IE (Interrupted Enhanced) related to 8051 serial communication are used to set four different communication modes and define the baud rate. Its serial port working mode 3 is a 9-bit data asynchronous communication mode with variable baud rate. The sending or receiving of a frame of data is 11 bits: 1 start bit, 8 data bits, 1 additional check bit and 1 stop bit. The additional 9th ​​bit of data is programmable. Using this controllable 9th bit of data, multi-machine communication can be achieved.

2. Communication principle between PC and 8051

The core of the PC's serial communication adapter is the programmable asynchronous receiver and transmitter UART8250 chip. The 8250 has 10 addressable registers for the CPU to read/write to achieve communication with the outside world, formulate communication protocols and provide communication status information.

The serial channel of the 8051 microcontroller is a full-duplex serial communication port, which can realize both dual-machine communication and multi-machine communication. When the serial port works in mode 2 or mode 3, if the multi-machine communication control bit SM2 of the serial control register SCON is set to "1" by software, it is multi-machine mode; if SM2 is "0", it is 9-bit asynchronous communication mode.

When multiple machines communicate, the frame format sent by 8051 is 11 bits, of which the 9th bit is the send data bit TB8 in SCON, which is the flag for sending address (TB8=1) or sending data (TB8=0) during multi-machine communication. The corresponding bit of the serial frame format is automatically loaded during serial transmission. At the receiving end, the 9th bit of a frame of data is loaded into the receive data bit RB8 of SCON. The receiver determines whether to generate a serial interrupt flag based on the status of RB8 and SM2, so that it can respond or not to the serial interrupt, thus realizing the serial interrupt.

The serial communication of the PC is completed by the interface chip 8250. It is a universal asynchronous receiver/transmitter, which is specially designed for data communication of Intel's microprocessor. It receives parallel data from the CPU, then converts it into continuous serial data and sends it out through the transmitter's shift register. Although the 8250 does not have the multi-machine communication function and cannot generate TB8 or RB8, the 8250 can be used flexibly to complete the above functions with software. The 8250 can send a variety of word lengths, with a maximum of 11 bits in a frame. Compared with the frame format sent by the 8250, the difference is only in the 9th bit, that is, the 9th bit sent by the 8250 of the PC is an odd/even check bit, rather than the corresponding address/data bit flag. Software programming can be used to make the odd/even check bit of the 8250 form the correct address/data flag.

3﹒Multi-machine communication control between PC and 8051

Although the 8250 itself does not have the multi-machine communication function of the 8051 series microcontrollers, the 8250 can meet the communication requirements of the 8051 microcontroller through software.

The port address range of 8250 is 3F8H~3FEH or 2F8H~2FEH. The port addresses of its internal registers are shown in Table 1.

Table 1 Port addresses of 8250 internal registers

Serial number

name

Port Address

Input/output form

1

Data transmission holding register

3F8H

Output

2

Data receiving register

3F8H

enter

3

Baud rate factor register (low bit)

3F8H

Output

4

Baud rate factor register (high bit)

3F9H

Output

5

Interrupt Control Register

3F9H

Output

6

Interrupt Identification Register

3FAH

enter

7

Communication line control register

3FBH

Output

8

MODEM Control Register

3FCH

Output

9

Communication line status register

3F

enter

10

MODEM Status Register

3FEH

enter

8250 can send 11-bit data frames, which consist of 1 start bit, 8 data bits, 1 parity bit and 1 stop bit. Its format is as follows:

Start bit

D0

D1

D2

D3

D4

D5

D6

D7

Parity bit

Stop bits

The typical data format of 8051 microcontroller communication is:

Start bit

D0

D1

D2

D3

D4

D5

D6

D7

TB8

Stop bits

TB8 is a programmable bit that distinguishes data frames from address frames by setting it to 0 or 1.

Comparing the above two data formats, we can see that their data bit lengths are the same, and the only difference is the parity bit and TB8. If the parity bit of 8250 can be programmed by software so that it is "1" when sending addresses and "0" when sending data, then the parity bit of 8250 completely simulates the TB8 bit of multi-machine communication of single-chip microcomputers. The method is to write a specific control word into the communication line control register of 8250.

A careful study of the DS bit function of the serial card's communication line control register 3FBH shows that when the serial port is initialized, D5=1 and D3=1 of 3FB are set, while D4=0 is set when sending addresses and D4=1 is set when sending data. This implements the function of TB8 in 8051 without having to adjust it every time. This method not only saves software expenses but also improves communication speed.

By setting the line control register (LCR) of 8250, 8250 can be made very flexible. To achieve multi-machine communication between 8250 and 8051, the key is to control its line status so that its data transmission format is consistent with that of 8051. According to the structural characteristics of the line control register of 8250, the following options can be made in programming:

If the parity bit of the frame sent by 8250 is required to be 1, just execute

MOV DX, 3FBH

MOV AL, 2BH

OUT DX,AL

These three statements, the frame format is:

Start bit

D0

D1

D2

D3

D4

D5

D6

D7

1

Stop bits

If you want the parity bit of 8250 to be 0, just execute

MOV DX, 3FBH

MOV AL, 3BH

OUT DX,AL

These three statements, the frame format is:

Start bit

D0

D1

D2

D3

D4

D5

D6

D7

0

Stop bits

Obviously, the former can be used as an address frame in multi-machine communication, while the latter can be used as a data frame.

4﹒ Setting non-standard baud rate of PC

In most cases, the 8051 microcontroller system clock uses a 6MHz quartz crystal oscillator. The baud rate of its serial port is determined by its internal timer TH1 (8 bits). The specific calculation formula is:

Baud=(fosc﹡2SMOD)/(32﹡12﹡(256-TH1))=(15625﹡2SMOD)/(256-TH1)

Where SMOD is programmable, and different values ​​of TH1 determine different baud rates.

If you use BASIC or directly call ROM BIOS INT14 (serial port interrupt), you can only set a few standard baud rates. Under this standard baud rate, it is difficult for 8051 to achieve, such as a baud rate of 4800, which cannot be achieved for a microcontroller using a 6MHz crystal oscillator. However, in actual applications, it is unlikely to select a crystal oscillator just to meet the standard baud rate requirements. On the other hand, under the premise of ensuring reliable communication, it is always hoped that the communication speed is as fast as possible. Therefore, non-standard baud rates can be obtained by directly programming the divisor latch of 8250.

Assume that the calculated baud rate for multi-machine communication is 2400. Since it cannot be realized by a single-chip microcomputer, it can be designed as 1953. Set TH1=248 and SMOD=0 on the single-chip microcomputer, and set the divisor equal to 59 on the PC. In this way, multi-machine communication can be realized.

5. Programming of 8250

For 8250 only, the steps for asynchronous serial communication programming are as follows:

Step 1: Set the communication protocol, such as baud rate, parity check mode, data format, data byte length, etc.

Step 2: Read the status of the communication line (or MODEM) to determine whether communication is possible;

step3: send (or receive) a byte;

step4: Repeat step2 and step3 until the communication is completed.

When interrupts are enabled, after the CPU sends (or receives) a byte, it does not need to constantly query the controller status, but can turn to perform other tasks. When the interrupt signal INT4 occurs and responds, the third step of step 2 and step 3 above can be processed.

When using 8250 for serial communication, it must first be initialized, that is, the baud rate, the data format used for communication, whether to use interrupts, whether to perform self-test operations, etc. After initialization, communication can be carried out in program query mode or interrupt mode.

The initialization of 8250 is generally divided into three steps:

Step 1: Set the baud rate (assuming it is 1200)

MOV AL, 80H

MOV DX, 3FBH

OUT DX, AL

MOV AL, 60H

MOV DX, 3FBH

OUT DX,AL

MOV AL, 00H

MOV DX,3F9H

OUT DX,AL

Step 2: Set the communication data format (assuming 7 data bits, 1 stop bit, even parity)

MOV AL, 1AH

MOV DX, 3FBH

OUT DX,AL

Step 3: Set the operation mode

MOV AL, 03H

MOV DX, 3FCH

OUT DX, AL; interrupt output is not allowed

MOV DX, 3FCH

MOV AL, OBH

OUT DX, AL; Enable interrupt output

MOV AL, 13H

MOV DX, 3FCH

OUT DX, AL; self-test working mode

Step 4: Set the interrupt enable register

MOV AL, 00H

MOV DX,3F9H

OUT DX,AL

6. Innovation of this paper

The innovations of this paper are: first, using a programmable asynchronous serial communication interface chip to execute the asynchronous serial communication protocol to achieve communication; second, directly programming the divisor latch of 8250 to obtain a non-standard baud rate.

References:

[1] Hong Jiaping. Communication between PC and MCU under Windows environment. Beijing: Microcomputer Information, No. 3, 2005, pp. 70-73.

[2] Li Chaoqing. PC and MCU Data Communication Technology. Beijing: Beijing University of Aeronautics and Astronautics Press, 2002.12

[3] Yao Zhijiang et al. A complete implementation of a synthesizable VHDL model of 8051 MCU. Beijing: Computer Applications, 2000 (20)

[4] Li Guangdi. Fundamentals of Single Chip Microcomputers. Beijing: Beijing University of Aeronautics and Astronautics Press, 2002.12

Keywords:MCU Reference address:Design of Multi-computer Communication Based on 8250

Previous article:Research on PLC Based on AT89C55 Single Chip Microcomputer
Next article:How to perform co-simulation of SPICE models and 8051 MCU in NI Multisim

Recommended ReadingLatest update time:2024-11-16 17:45

51 microcontroller learning: matrix button experiment
Experiment name: Matrix button experiment wiring instructions: Experimental phenomenon: After downloading the program, press the S1-S16 keys in the "matrix button" module, and the leftmost side of the corresponding digital tube displays 0-F. Notes: ********* *************************************************** ********
[Microcontroller]
The single chip microcomputer (AT89C51) button controls the LED light to realize the running light and flashing running light
Preface  It's been a long time since I wrote about the microcontroller series. Without further ado, let's get straight to the point! The experiment I'm going to explain and share this time is a famous running light experiment, but this experiment is to achieve "running water" by clicking a button yourself, which is di
[Microcontroller]
The single chip microcomputer (AT89C51) button controls the LED light to realize the running light and flashing running light
Study on Watchdog Timer in MSP430 MCU
  introduction   Software reliability has always been a key issue. Anyone who uses software may experience computer crashes or program errors, and this also happens in embedded systems. Due to the limited anti-interference ability of microcontrollers, instrumentation in industrial sites often crashes due to voltage
[Microcontroller]
Study on Watchdog Timer in MSP430 MCU
Keil C51 cracked version (c language microcontroller programming software) v9.0 free Chinese version
Software Introduction The keil c51 Chinese package is designed to bring various programming operations of the microcontroller, allowing you to easily perform the required editing services. It has C language programming auxiliary functions and brings you various free operating effects! Official Introduction It is a
[Microcontroller]
Keil C51 cracked version (c language microcontroller programming software) v9.0 free Chinese version
Playing PID control with a single-chip microcomputer - from ideal PID control to advanced PID control_13
3.5 Composite fuzzy control Compound fuzzy control means that fuzzy control is used when the deviation is large, and PID control is used when the deviation is small, thereby overcoming the shortcoming of fuzzy control with deviation. Its principle is shown in Figure 1. 3.5.1 Fuzzy Control The working principle o
[Microcontroller]
Playing PID control with a single-chip microcomputer - from ideal PID control to advanced PID control_13
Design of intelligent combined control of kitchen equipment based on PIC microcontroller
With the continuous development of smart home appliance control technology, multifunctional and intelligent kitchen controllers have become the mainstream of kitchen appliance development. Compared with traditional single kitchen equipment controllers, multifunctional kitchen controllers have the advantages of small f
[Microcontroller]
Design of intelligent combined control of kitchen equipment based on PIC microcontroller
How to quickly get started with 51 microcontroller from scratch (3)
Introduction to single-chip microcomputer Single-chip microcomputer: A microprocessor (CPU), memory (ROM and RAM), I/O interface, timer, interrupt system and other circuits are integrated on an integrated circuit chip, thus forming a single-chip microcomputer, that is, a single-chip microcomputer (single-chip microcom
[Microcontroller]
A wireless remote control technology based on single chip microcomputer system
1 Introduction With the rapid development of integrated circuit technology, new remote controls based on various chips continue to emerge. The central control components of remote control devices have gradually developed from early discrete components and integrated circuits to current single-chip microcomputer
[Microcontroller]
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号