
In microcontroller applications, often encountered in communicating with the computer situation. Communication distance is short, plus a level-shifting circuit (such as the MAX232) on the line. However, long-range (greater than 2km) communication, you must use a modem MODEM. General information on the connection between the MCU and MODEM take at least 4 to 5 I / O port. I refer to the relevant information and through the experiment, only the two I / O ports can be connected to Microcontroller with MODEM and remote communications, simplify the design of single chip peripheral circuits, saving I / O ports, improve reliability , reducing the difficulty of producing, but the software is slightly larger. Introduced to this method here, for reference.
MODEM external data interface is 25-pin female socket, the pin is defined as the attached table.

To simplify the interface, need to do a special three-wire cable MODEM (Figure 1). MODEM end of the plug {4} (RTS), {5} (CTS), {8} (CD) pin shorted, {6} (DSR), {20} (DTR) pin shorted, the CD will MODEM , CTS RTS signal as the signal back to MODEM, the DSR as a DTR signal back to MODEM. This, MODEM MODEM with each other to complete the handshake, you can direct communications from the DTE to DTE (DTE here refers to the other side of the microcontroller and PC). Of course, DTE must be received CONNECT MODEM sent before they can enter the data communication signals (preferably then set a time delay of less than 1s). As a result, the control of the MODEM completely realized by the soft-command (because there is no connection related control line).
Before use, should be a good pre-MODEM MCU end of the parameters for programming. MODEM serial port will be connected to a computer, run WIN95/98 the "Super Terminal" program. Enter and then type AT & F, response time MODEM OK. If there is no OK response will have to check the MODEM and computer serial port connection and HyperTerminal serial port used is correct. Then type the following command sequence:
ATE0 (typing the command echo cancellation)
ATV0 (using digital feedback command results)
ATS0 = 0 (automatically answer the call against MODEM)
AT & W0 (0 configuration write memory, so each boot automatically transferred out)
Control procedures for the preparation of MODEM, MODEM control must be understood. MODEM interaction and data transfer is ordered the two states. Interactive state in the command, the available dial-up AT command set to MODEM, the response dial, set the relevant parameters. MODEM time all the characters received from the serial port as the command processing MODEM is not sent to the telephone line, and the MODEM will use numeric code or English, the report orders the implementation of the string (using the MODEM settings to see what kind of response .) In the data transmission state, all sent to the MODEM from the serial characters are sent to the phone line. MODEM state after power is in order, if, as the called party to respond to incoming, the available ATA command to answer the call, the handshake signal to enter after the completion of data transfer state. If a caller calls each other, with the ATDT ×××××(××××× for the other phone number) command to call each other until the other party answers, handshake automatically after completion of data transfer state. In the data transmission state, the suspension of the serial port for 2 seconds, and then send "+++"( careful not to carriage return), then pause for 2 seconds to send the serial port, MODEM automatically return to command state.
The following are examples of some commonly used MODEM control commands.
1. ATDTW0127800000
A call. Dial 0, the second dial tone to be set aside 127.8 million. If not dial 0 outside ? can be removed to W0.
2. ATA - MODEM MODEM command remote call answering. MODEM successful if the two sides shook hands, then enter the data transfer state.
3. (Pause 2 seconds )+++( pause 2 seconds), the MODEM from the data transfer status back to the command state.
4. ATH - Command MODEM to hang up.
As pre-set with ATV0 MODEM response to digital code, it is necessary to understand the meaning of the data response code.
Loopback 0, OK, that command to complete.
Loopback 1x, the representation and the other to complete the handshake signals, the two rate MODEM connected to x, and then enter the data transfer status MODEM.
Loopback 2 when the ring, that is calls.
Echo 3, that no carrier, call, or answer not successful.
Accordingly, we can write the microcontroller through the serial port control procedures for the MODEM. Here the author provides a remote alarm / monitoring program, the program flow chart shown in Figure 2, the hardware wiring diagram shown in Figure 3 (this figure is not drawn reset the microcontroller, crystal and power supply circuit).