Research on Remote Communication between Single Chip Microcomputer and PC Based on MODEM

Publisher:rho27Latest update time:2011-12-12 Keywords:MODEM Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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 is equipped with a universal asynchronous receiver and transmitter, that is, UART, which can set the communication format and speed through programming. The level of the 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 MCU and 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 MCU and 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 [page]

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 between the PC and 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 issues the telephone number, and finally issues 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);

[page]

if(mum1= =0x35)drev(); /*If 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

Keywords:MODEM Reference address:Research on Remote Communication between Single Chip Microcomputer and PC Based on MODEM

Previous article:ADS1212 and 51 MCU realize high-precision data acquisition design
Next article:A method for establishing a 51 single-chip microcomputer virtual laboratory

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号