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.
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
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
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Problems with frequency modulation using MAX2607
- Recruiting BLE software development engineers (with favorable treatment)
- Eliminating Software Failures with MSP432
- Op amp adder and subtractor
- Award-winning lecture: Nexperia Micro Classroom - Explanation of parameters in the power GaN device data sheet
- [Environmental Expert's Smart Watch] Part 12: Configuration of watch name and time
- [TI recommended course] #Boost and buck-boost DCDC converters help wireless charging design#
- Why does the servo motor make noise during operation?
- How to choose LoRa products
- [2022 Digi-Key Innovation Design Competition] Pi-hole Magical Uses of Pi400