A serial communication method between 8098 single chip microcomputer and PC

Publisher:SparklingEyesLatest update time:2012-02-04 Source: 微处理机 Keywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1 Introduction
With the rapid development and wide application of computer technology, the master-slave working mode of the upper computer and the lower computer is more adopted by the data acquisition system. Since the microcomputer has strong analysis and processing capabilities and faster processing speed, and the single-chip microcomputer is flexible and convenient to use, the host generally uses a microcomputer and the slave uses a single-chip microcomputer to form a master-slave multi-machine working mode.
The 8098 single-chip microcomputer is a quasi-16-bit microprocessor launched by Intel in the late 1980s. It has a simple structure, easy programming, few peripheral circuits, convenient interface, and high data acquisition accuracy; the 256 byte registers in the chip all have the function of accumulators, which can enable the CPU to quickly exchange the data of the operator; and provide high-speed data processing and frequent input and output functions. The handshake between the 8098 single-chip microcomputer and the upper computer is also very friendly, and the signal transmission between them is accurate and reliable, becoming another popular single-chip microcomputer after the MCS-51 series single-chip microcomputer.
I have conducted special research on the torque test of the gear hobbing process, in which the data acquisition system uses the 8098 single-chip microcomputer, and the collected data is sent to the microcomputer for processing via serial communication. This article gives a detailed introduction to the serial communication between 8098 single-chip microcomputer and microcomputer.

2 Serial Communication of 8098 MCU
Data communication methods can be divided into two types: parallel transmission and serial transmission. Parallel transmission is fast and efficient, but the transmission reliability is poor and it is not suitable for long-distance transmission; serial transmission moves data in bit order, which is slow and inefficient, but the transmission is reliable and can save hardware investment in the communication subsystem. In this article, the microcontroller works asynchronously with the host computer through the serial port 1, and achieves: ① Before communication, the sender and receiver reach an agreement to clearly define the contact signals and data transmission methods of each other. The agreement is strict and easy to implement. ② In order to enhance the anti-interference ability during data transmission, a level converter needs to be configured.
When using the 8098 microcontroller for serial communication, the relevant registers must be set. The registers related to serial communication are: ① IOC1 control register: In serial applications, this register is used to select the multiplexing function of the TXD/P2.0 pin end. When set to 1, the TXD function is selected. ②SP_CON register (11H, write-only) and SP_STAT register (11H, read-only): The lower 5 bits of the register are used as control registers, and the upper 3 bits are used as status registers. ③INT_MASK interrupt mask register: INTMAS.6 is set to 1 to allow serial port interrupts. ④BAUD_RATE register (0EH, write-only): It is a 16-bit register. To set the baud rate of serial communication, it is necessary to write to 0EH twice in succession, first sending the low byte and then the high byte. The highest bit of the baud rate register should be set to 1 to select the XTAL1 frequency, that is, the system clock oscillation frequency. In the system designed by the author, the clock of the 8098 microcontroller used is 6MHz, and the baud rate is set to 9600, then the value sent to the RAUD_RATE register is 8013H.

3 Serial port connection between 8098 microcontroller and host computer
The serial port of the host computer (386 or above PC) uses the standard RS-232C interface. Since the serial port level of the 8098 microcontroller is TTL level, but the TTL level characteristics do not match the electrical characteristics of RS232, in order to enable the serial port of the 8098 microcontroller to communicate with the RS-232C interface, the input/output level of the serial port must be converted. The most commonly used chips 1488 and 1489 are used to realize the level conversion between RS-232C and TTL. Figure 1 is a connection diagram.

59.gif (1729 bytes)

Figure 1 Connection diagram

The 8098 single-chip CPU and the serial port transmit data through the SBUF_TX transmit register and the SBUF_RX receive register. The CPU writes the data to be sent into SBUFTX and reads the data received by the serial port from SBUFRX. Once the last data bit in a frame of information is written into or read from the buffer, the corresponding transmit and receive interrupts are generated. [page]

4 8098 MCU and host computer communication program writing
After the above analysis, first write the 8098 MCU communication program. The following is part of the serial communication program:
ORG 2080H
LD SP,#00C0H
DI
LDB TEMP,#20H ; TEMP initialization, set TI to 1
ORB IOC1,#20H ; Select TXD function
LDB TEMP,#20H ; Preset to receive end
LDB BAUDRA,#13H ; Set the baud rate to 9600
LDB BAUDRA,#80H
LDB SPCON,#09H ; Mode 1, allow reception
...
GET_CHR: ORB TEMP,SPSTAT ; Receive data from the serial port
JBC TEMP,6,GET_CHR
ANDB TEMP,#0BFH ; Clear the RI flag in TEMP
LDB CHAR_I,SBUF
...
PUT_CHR: ORB TEMP,SPSTAT ; Send data through the serial port
JBC TEMP,5,PUT_CHR
LDB SBUF,CHAR_O
ANDB TEMP,#0DFH ; Clear the TI flag in TEMP
...
The main program first turns off interrupts (in order to use the query method), sets the TI position of the test register TEMP (used to copy the content in SP_STAT) to 1, and initializes the program to the receiving state. Test the RI bit in the GET_CHR subroutine. If it is 0, it means that the SBUF_RX buffer has not received the information. If it is 1, read the received information into the CHAR_I register; the TI bit should be tested in the PUT_CHR subroutine.
All programs of the host computer (386 or above PC) are compiled in the BORLAND C++ environment, so the serial communication program can directly apply the I/O communication library function bioscom(), which performs RS-232 communication operations on the I/O port specified by port. Before communication, set the serial port, number of data bits, number of stop bits, and baud rate according to the communication protocol with the 8098 microcontroller. Since the host computer clock is 12MHz, the corresponding baud rate should be set to 4800. The following is a partial program for serial communication of the upper computer:
#define COM1 0 //Select serial port 1
#define DATA_READY 0x100
#define TRUE 1
#define FALSE 0
#define SETTINGS (0xc0| 0x00 | 0x00 | 0x03)
// 4800 baud, no parity, 1 stop bit, 8 data bits
main()
{
FILE *fp;
if((fp=fopen("c:\\dch\\data","wb"))==NULL)
{
cout<<"cannot open the file"<<"\n";
exit(0);
}
int in,out, status=0, DONE = FALSE;
bioscom(0, SETTINGS, COM1); //Initialize the serial port
while (!DONE)
{
status=bioscom(3,0,COM1); //Return the current status of the serial port
if (status & DATA_READY)
if ((out=bioscom(2, 0, COM1)&0x7F) != 0)
{
… //Receive data from the communication line
}
if (kbhit())
{
if ((in =getch()) == '\x1B')
{DONE = TRUE;break;}
bioscom(1, in, COM1); //Send data to the communication line
}
}

}
Experiments have proved that the above communication program is readable and easy to write, and makes the communication between the upper and lower computers intuitive and simple, while the data transmission is accurate.

5 Conclusion
The method proposed in this paper has been successfully applied in the author's project "Torque test and analysis of gear hobbing cutting process". This method has nothing to do with the amount of data collected. It is just because of the use of serial port communication that when the amount of data is large, the acquisition time is slightly longer, but the collected data is accurate and reliable, and has no effect on the operation of the entire system. This method is not only suitable for microcomputers above 386, but also for communication between PC/XT and its compatible machines and 8098.

6 References
[1] Liu Fuhua. 8098 single-chip microcomputer and its application system design. Beijing: Tsinghua University Press, 1993, 6
[2] Liu Zhenan. MCS-96 series single-chip microcomputer principle and practice. Hefei: University of Science and Technology of China Press, 1992: 141-150
[3] Liu Luyuan. 8098 single-chip microcomputer experimental tutorial. Tianjin: Tianjin University Press, 1992: 30-41
[4] Ye Xin. TURBO C reference manual. Beijing: Chinese Academy of Sciences Hope Advanced Computer Technology Company. 1990, 5

Keywords:MCU Reference address:A serial communication method between 8098 single chip microcomputer and PC

Previous article:Improving the multiplication operation of single chip computer by using overlapping scanning method
Next article:Features and Applications of High-Speed ​​Single-Chip Microcomputer W77E58

Recommended ReadingLatest update time:2024-11-16 16:18

How to use a general purpose microcontroller to make a MIDI keyboard
MIDI is the language of electronic musical instruments. With the birth of MIDI, there are more and more digital electronic musical instruments, and the application of MIDI is becoming more and more common. It plays an increasingly important role in various fields such as electronic band performance and electronic musi
[Microcontroller]
How to use a general purpose microcontroller to make a MIDI keyboard
What should I do if the microcontroller cannot learn? Where to start learning about microcontroller?
What should I do if I can’t learn the microcontroller? It reminds me of some of my own bitter learning history. I have been developing microcontrollers for more than 10 years, and I am naturally very skilled in microcontroller hardware and software development. But I don’t know anything about other jobs. When I was wo
[Microcontroller]
51 MCU【Part 3】Static and dynamic driving digital tube
Digital tube structure and classification The digital tube is one of the light-emitting devices. It is composed of seven strip-shaped light-emitting diodes (a, b, c, d, e, f, g) and a small dot light-emitting diode (dp). The 51 single-chip microcomputer development board has eight-segment digital tubes, as shown in
[Microcontroller]
51 MCU【Part 3】Static and dynamic driving digital tube
Development of anti-interference measures for single chip microcomputer
  In order to improve the reliability of the MCU itself, in recent years, MCU manufacturers have taken a series of measures in MCU design to improve reliability. These technologies are mainly reflected in the following aspects. 1. Reduce the external clock frequency   The external clock is a high-frequency noise sou
[Microcontroller]
The phenomenon of single chip computer program running away and its solution--watchdog circuit
1. Program runaway phenomenon With the widespread application of single-chip microcomputers in the energy field, the anti-interference problem of single-chip microcomputers has become more and more prominent. The underground environment of coal mines is generally harsh, which will bring various interferences to the s
[Microcontroller]
The phenomenon of single chip computer program running away and its solution--watchdog circuit
MCU timer/counter comprehensive application example
  P1.0 and P1.1 are driven by 7407 to light up alternately and flash once per second. See the figure below for hardware connection (using 6MHZ crystal oscillator)   Analysis: The flashing cycle is 1S, half on and half off, and the timing time is 500mS. Using a 6MHZ crystal oscillator, the longest timing time of the
[Microcontroller]
MCU timer/counter comprehensive application example
Design and production of wireless answering and scoring system based on AT89S52 single chip microcomputer
The wireless answer scoring system uses AT89S52/51 single-chip microcomputer as the control core, which can wirelessly transmit and receive answer signals, and has the functions of identifying advanced violation signals, countdown function, key verification, digital tube display, etc. Its main functions include: 1) It
[Microcontroller]
Design and production of wireless answering and scoring system based on AT89S52 single chip microcomputer
Arduino CEO interview: AI-enabled MCUs can help more people stop being technology “spectators”
Translated from MIT Technology Review Since its inception in 2005, the Arduino open source platform has revolutionized the world of electronic engineering, and innovation represented by open source has swept the entire technology development. Whether in the past, present or future, the goal of science
[Embedded]
Arduino CEO interview: AI-enabled MCUs can help more people stop being technology “spectators”
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号