1 introduction
Serial communication’s widespread application may cause each kind of transmission facility organically to be united as one body, can carry on the data exchange and the information transmission reliably safely. But because on each equipment transmission channel’s signal is different, applies the serial port are also various, must complete the numerous equipment correspondences, inevitably must involve to each equipment’s between serial port transformation question.
In order to cause computer’s RS-232 connection to carry on the correspondence with each kind of different serial port, thus tests or the control different equipment’s active status, this article designed one kind of general serial port adapter, the adapter had 4 foreign connections, 1 connection control computer, 2, 3, 4 connection double standards serial port’s communication facility, as shown in Figure 1.

2 hardware designs
In order to realize to adapter’s automatic control as well as expands other connections, has used the C8051F020 monolithic integrated circuit. The adapter has selected the C8051F020 microprocessor, the MAX4534 electronic simulation switch, the MAX232 level switch as well as RS-485/RS-422 signal shifter MAX491 and so on.
The overall system take C8051F020 as the core, functional block diagram as shown in Figure 2. Through the serial port 1 control from the superior machine serial port transmission’s data’s receive, the memory and the distinction, then through the serial port 2 control electronic simulation switch, causes its internal analog switch connection corresponding serial port, finally realizes the computer and each serial port correspondence.

2.1 and superior machine communication circuit
The C8051F020 pin’s signal level is the TTL type, but PC machine serial port asynchronous serial communication based on the RS-232 standard. Both correspondence signal’s logic level is inconsistent, must the clear signal level switch. Therefore, selects Maxim Corporation’s MAX232 to realize the TTL level and the RS-232 level bilateral switching.
MAX232 contains two groups receives and the driver, is suitable in each kind of EIA-232C and the V.28/V.24 correspondence connection. This component built-in supply voltage switch, may transform ±10 V voltage which 5 V voltages the RS-232C power output needs. Therefore, uses this component’s serial communication system only to need the sole 5 V power sources.
The serial port correspondence’s RS-232 signal distance take does not surpass 12 m as suitable. The connection uses 9 needle serial port DB9, the serial port transmission data, so long as has the receive data pin and the transmission pin may realize. 2.2 analog switch control circuit
This control circuit mainly (a pair four) completes by MAX4534. The address carries A0 and A1 and the monolithic integrated circuit I/O port is connected, the switch 1, 2, 3, 4 are separately connected with each test facility’s serial port, MAX4534 internal connection logic as shown in Figure 3.

When the superior machine realizes after monolithic integrated circuit’s handshake, if and RS-422 mouth correspondence. Then must transmit detection signal TEST first, this signal after MAX232 level switch, delivers to monolithic integrated circuit C8051F020, after the monolithic integrated circuit receives the signal, through its I/O port P6.0 and the P6.1 output state distinction controlling switch MAX4534 address carries A0 and A1. If A0 and A1 are 0, then closing switch NO1, as shown in Table 1, causes to examine electric circuit’s MAX491 receiving end to be at the conducting state, thus forms the circuit. This time the monolithic integrated circuit returns sends a circuit signal for the superior machine, when after superior machine receive circuit signal, the MCU serial port TXD end may transmit the data freely, sends in the back signal from the equipment also to be possible by the MCU normal receive, thus completes the entire course of communications.

2.3 RS-232 (TTL level) interface circuit design
Because comes out from the monolithic integrated circuit pin the signal is the TTL level, therefore TTL the level RS-232 connection does not need to carry on the level switch, may directly is connected through analog switch MAX4534 and the serial port.
Regarding five RS-232 connections, because the C8051F020 serial port only then two lines connect RXD and TXD, RTS and CTS realize through its two I/O mouth.
2.4 RS-422 connection switching circuit design
The RS-232 serial interface belongs to personal computer (PC) and in the telecommunication application domain the most successful serial data standard; But the RS-422 serial interface is in the industrial application domain the most successful serial data standard. Above these data standard not directly mutually compatible. The RS-422 standard full title is ” the balanced voltage digital interface electric circuit’s electrical specification “, it has defined interface circuit’s characteristic, is different with RS-232, the RS-422 data signal uses the difference transmission mode, is also called as the balanced transmission, it uses a for son twisted pair line, a line definition will be A, another line definition is B. Usually in the situation, transmits between driver A, the B level is 2 V~ 6 V, is a logical condition; Negative level is - 2 V~-6 V. The RS-422 maximum transmitting range is 4000 feet (approximately 1 219 m), the maximum transmission speed is 10 Mb/s, most may meet 10 nodes, has the independent transmission and the reception channel, therefore does not need the control data direction.
Between RS-232 and the RS-422 level switch realizes by Maxim Corporation’s difference balanced type transceiver MAX491, it is suitable for the RS-422/RS-485 correspondence standard, the interior contains 1 transmission driver and 1 receiver. RE is the receiver input permission end, the earth; DE is the driver output permission end, meets 5 V voltages. The monolithic integrated circuit control signal causes the MAX491 receiving end to endure automatically energy, in order to avoid the entire line-wire communication ring circuit forms the regeneration to create the autoexcitation, but the MAX491 transmitting end free breakover, the control signal normally transmits.
3 software programming
The software routine mainly includes the superior machine visualization contact surface procedure and the monolithic integrated circuit and the PC serial port signal procedure. The monolithic integrated circuit uses the C51 language programming, the superior machine operation contact surface procedure uses C Builder to carry on the visualization programming.
3.1 superior machine visualization contact surface programming
Take C Builder as the development kit, the use serial communication controls MSComm to carry on the programming, realizes to the monolithic integrated circuit the control. In this communications system stipulated the character format is: Each data occupies 10, 1 outset position, 8 bit data positions, 1 stop position, non-parity check position. Middle 8 bit data position namely for effective correspondence transmission byte. In order to strengthen correspondence reliability, the reduced correspondence error rate, the bilateral baudrate establishment is 4 800 b/s, by compares the low speed to carry on the correspondence. The software handshake agreement stipulation is as follows: PC machine transmission handshake signal 0xFF gives the monolithic integrated circuit, the superior machine data which the monolithic integrated circuit receives, if for handshake signal 0xFF, then returnes a correct signal 060606 to give PC machine, indicates shakes hand successfully, PC machine then transmits the data packet, the monolithic integrated circuit after the verification correctly this data packet direct access receive, and decomposes the effective data message; If the monolithic integrated circuit receives the superior machine data is not the handshake signal, then returnes a rub-out signal 151515, and continues to wait. Man-machine contact surface as shown in Figure 4.

After entering the control interface, first according to superior machine and monolithic integrated circuit’s communication protocol, choice serial port number, communication baudrate, parity check position, data position as well as stop position. When the superior machine the click needs to correspond in the contact surface connection option when serial port, will trigger a transmission signal to give the monolithic integrated circuit, the monolithic integrated circuit basis agreement control electronic simulation switch connection corresponding serial port electric circuit, simultaneously will return sends a circuit signal for the superior machine, will thus cause on the contact surface the serial port to instruct that will assume the green condition, indicated that the communication circuit has put through, may transmit and receive the data. Superior machine correspondence flow as shown in Figure 5.

3.2 monolithic integrated circuits and PC serial port correspondence programming
Mainly uses monolithic integrated circuit’s timer, the I/O port, UART, the priority overlapping switch in this design, to interrupt the establishment, the clock signal, the register, D/A and A/D and so on. Defines C8051F020 UART0 and the computer connection, UART1 and various serial ports is connected. First priority overlapping switch decoder overlapping switch port P0~P3 pin assignment for UART0, UART1, INT0 and INT1.
Establishes XBARE=1, enables the overlapping switch. UART0 has the highest priority, P0.0 assigns for TX0, P0.1 assigns for RX0. Next is UART1, P0.2 is assigned assigns for TX1, P0.3 for RX1. P0.4 assigns for INT0. Because the exterior memory interface elects in the low port (EMIFLE=1), therefore the overlapping switch jumps over P0.6(RD) and P0.7(WR). Because the exterior memory interface disposition is the multiplying way, therefore the overlapping switch also jumps over P0.5(ALE). Next jump’s pin P1.0 has not assigned for INT1. And uses the low port the exterior memory interface disposition for the multiplying way, P1.2, P1.3 and the P1.4 disposition is the analog input, in order to survey with ADC1 exerts on these pins the voltage.
When in overlapping switch disposition register XBR0, XBR1 and XBR2 the peripheral device correspondence enables the position establishes for logic ‘ 1 ‘, overlapping switch port pin assignment for peripheral device. UART0 TX pin (TX0, P0.0), UART1 TX pin (TX1, P0.2), ALE, RD, WR (P0. [7:3]) the output establishes as the push-pull way, through establishes P0MDOUT=0xE5 to realize. Through establishes P2MDOUT=0xFF, P3MDOUT=0xFF and P6MDOUT=0xFF the EMIF port (P2, P3, P6) output mode disposition for push-pull way. Monolithic integrated circuit correspondence master routine flow as shown in Figure 6.

4 concluding remark
When to the core component C8051F020 programming and to hardware board debugging uses Cygnal IDE the Cygnal integrated development environment software. The Cygnal integrated development environment uses the standard Windows95/98/NT/2000 to take the contact surface, realizes IDE and in target system’s monolithic integrated circuit correspondence using the PC machine serial port and the goal board’s JTAG connection (each wrap development system has RS-232 serial adapter which needs to JTAG protocol conversion), after target system connection may carry on the non-jack-in type, the full speed online debugging and programs in the system.
In addition, this serial port adapter is very easy to expand other connections, the available I/O mouth meets the digital interface, may also meets the simulated signal connection through monolithic integrated circuit’s A/D and D/A. If the periphery connection are excessively many, then may merge is or several connections, only need add the relay in the electric circuit (relay by monolithic integrated circuit’s I/O control) to carry on the output cut then.