With the development and maturity of computer technology and communication technology, data communication has become a widely used communication method. It uses communication systems to transmit, exchange and process numbers, letters and characters in binary form between computers. Data communication can be carried out between two or more PCs, between PCs and single-chip microcomputers, and between single-chip microcomputers. The two machines are connected through communication channels such as public telephone networks, carrier channels, optical fiber channels, microwave channels, and satellite channels. At present, single-chip microcomputers are widely used in automatic monitoring, measurement, control and other technical fields with their high performance-price ratio and high reliability. Single-chip microcomputers are mainly used as slaves and installed at the monitoring, measurement and control site, while PCs are used as hosts and installed in environments with superior conditions (such as suitable temperature and temperature, and almost no interference sources). Single-chip microcomputers and PCs use the public telephone network to achieve remote digital communication through a modem MODEM. Its principle block diagram is shown in Figure 1. In practice, the communication distance between PCs and single-chip microcomputers is less than 1 km at the closest and thousands of km at the farthest.
This article will introduce in detail the hardware structure of the 8098 microcontroller and PC to achieve remote communication through a MODEM using a shared telephone network, as well as the program design and implementation methods.
1 PC serial communication structure
The communication between the PC and the microcontroller generally adopts the serial asynchronous communication method. Set up four (COM1, COM2, COM3, COM4) or two (COM1, COM2) serial ports that meet the RS-232C interface standard in the PC (the following description uses two serial ports). COM2 is a 25-pin connector and COM1 is a 9-pin connector.
In order to realize asynchronous communication, the PC sets up a universal asynchronous receiver and transmitter, that is, UART can set the communication format and speed through programming. The level of UART in the PC is TTL level, while the level of the serial port is RS-232C level. Therefore, the data sent by the PC must be converted to RS-232C level by a level converter (such as 1488); the data received by the PC must be converted to TTL level by a level converter (such as 1489). The hardware structure of PC serial communication is shown in Figure 2.
2 MCU serial communication structure
In a single-chip microcomputer, generally only one serial port with 25 pins or 9 pins is set. Since the level in the single-chip microcomputer 8098 is TTL level, in order to realize asynchronous communication through RS-232C, one 1488 and two 1489s are also used for level conversion. The hardware interface of single-chip microcomputer serial communication is shown in Figure 3. The request to send signal (RTS) and the data terminal ready signal (DTR) are sent out by the single-chip microcomputer 8098 through the A port of 8255. Clear to send CTS, data set ready DSR, carrier detect DCD and ring indication RI are sent to 8098 through the B port of 8255.
3 Hardware interface between MCU and PC
When the distance between the microcontroller and the PC is very close (within 15m), the data communication between them can be connected through their serial ports with three or more lines; when the distance is not very far (tens of kilometers), a modem MODEM can be used to achieve data communication through a shared telephone network. At this time, the hardware interface between the microcontroller and the PC is shown in Figure 4.
4 Software Design and Implementation
The following takes the example of a PC calling a MCU or a MCU answering a PC to illustrate the program design.
4.1 PC Programming
The program flowchart is shown in Figure 5.
a. Initialization
In order to realize asynchronous serial communication, the asynchronous transmitter and receiver UART in the PC must be initialized to determine the data format, transmission rate, control method, etc. of the PC asynchronous serial communication. The procedure is as follows:
outportb(COMU+30,OX83) /*使DLAB=1*/
outportb(COMU,OX60) /*Baud rate=1*/
outportb(COMU+1,OX00)
outportb(COMU+3,OX03) /*Data format*/
outportp(COMU+4,OX03) /*Disable MODEM loop feedback*/
outportb(COMU,OX00) /*Disable interrupt*/
Note: COMU is the serial port address
b. Initialize MODEM
The MODEM initialization procedure is as follows:
{ int key,i;
char *at1=“ATZ”;
char *at2=“ATE1Q0V1L3X4S0=1”;
for(i=0,i<=3;i++)
{
if(i<=2)key=at1[i]; /*issue at command*/
if(i= =3)key=0x0d; /*confirmation code*/
outportb(COMU,key); /*send data*/
delay(100); /*delay 100mS*/
}
delay(1000); /*delay 1000mS*/
for(i=0;i<=0;i+ +)
if(i< =15)key=at2[i];
if(i= =16)key=0x0d;
outportb(HOW,key);
delay(100);
}
delay(1000);
}
c. Dial
To achieve data communication with the single-chip microcomputer, the PC first dials the single-chip microcomputer's telephone number, such as 38459620, through the short-range MODEM. The PC first issues a command such as at+h0e1v0x2&c1dt, then sends the telephone number, and finally sends a confirmation code 0x0d. The PC sends commands or numbers to the short-range MODEM through the serial port. It can only send one character or number at a time, and it takes a certain amount of time for the MODEM to receive and respond. Therefore, the PC will delay 100ms each time it sends a character or number. After the confirmation code is sent, it will delay another 1000ms, and then detect the echo code fed back to the PC by the short-range MODEM. If the echo code is OX35, it will enter the digital reception and processing program, otherwise it will continue to detect the echo code. The program is as follows:
"ath0q0v0l3x4&c1&d2dt";/*Get the phone number in the info structure*/
char str=info- >telephoneno;/*number of digits in the phone number*/
int len1=strlen(str);
for(i=0;i<=39;i++)
{
if(I>24)
{
key=str[k]; /*Send phone number*/
k+ +;
}
if(i<24)key=*at1; /*at命令*/
if(i= =39)key=0x0d; /*Send confirmation code*/
outportb(COMU,key); /*Send data to the serial port*/
delay(100); /*delay 100 milliseconds*/
at1+ +;
}
delay(1000);
do
{
key=bioskey(1);
num1=inportb(COMU); /*Detect echo code*/
delay(1);
if(mum1= =0x35)drev(); /*The response code is 0x35, then enter the data receiving and processing program*/
}
while(key= =0);
key=bioskey(0);
if(key= =0x011b)return; /*Press ESC key to return*/
4.2 MCU Programming
The microcontroller program block diagram is shown in Figure 6.
The program list is as follows:
LD 72H, #4003H; 8255 command port address
LD 70H; #0082HH; Port A is output, port B is input
STB 70H,[72H]
LDB 16H, #20; Serial port initialization
LDB 11H, #09H; Mode 1
LDB 0EH, #4DH; baud rate 1200bps
LDB 0EH,80H
LDB 18H,#0CH;Stack
ORB IOC1,#20H
LD 72H, #4000H; 8255 port A address
LD 70H, #0003H; make RTS and DTR both high level
STB 70H,[72H]
LCALL COMZ0; send four 0s in succession
LCALL DT; Delay 1000nS
LCALL COMZ1 ; Initialize MODEM and issue the at command: ata
LCALL DT
LCALL COMZ2 ; Initialize MODEM and issue AT command: ate1q0v1l3x4s0=1
LCALL DT
LCALL COMZ3 ; Initialize MODEM, issue at command: atS7=30
LCALL DT
RING0:LDB SPCON,#09H
RING1:LDB 60H,SPSTAT
JBC 60H,6,RING1
ANDB 60H,#0BFH
LDB 70H, SUBF; Receive a data from the serial port
CMPB 70H,#80H
JE TD ; Send data program
LJMP RING1
Since the program for the microcontroller to send AT commands to the MODEM is similar, we will only use the AT command: ate1q0v1l3x4s0=1 as an example to illustrate. Assume that the AT command is stored in the external memory with the address 0AB40H as the first address. The program is as follows:
COMZ2: LD72H, #0AB40H; at command first address
LDB 20H,#17
COMZ2A: LDB 70H, [72H]+; Get at command
LDB SBUF, 70H; send at command to the serial port
DJNZ 20H,COMZ2A
LDB 70H,#0DH
LDB SBUF, 70H; send confirmation code
RIGHT
Previous article:Implementation of industrial control system based on ATOM processor
Next article:Design and implementation of a single-chip microcomputer controlled Doppler blood flow meter system
Recommended ReadingLatest update time:2024-11-17 00:53
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Siemens Motion Control Technology and Engineering Applications (Tongxue, edited by Wu Xiaojun)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
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
- FIFO Experience
- 【TouchGFX Design】Learning about straight lines and toggle buttons
- Please tell me the interface definition of DC power supply for SONY camera
- Summer benefits, download high-quality resources with one click for 0 points, and 30 download points are waiting for you!
- EBAZ4205 mining board based on Z7010, have you tried it?
- STM32 low power library upower
- AD20 PCB copper plating PR, the copper plating is filled before it is closed. How to set it to not be filled before it is closed and displayed in dotted line form?
- TSMC's former purchasing manager jumped to a Chinese wafer factory and was ordered to pay NT$2.5 million
- IoT wireless transmission technology parameter comparison table
- How to identify the quality of wireless monitoring equipment?