Designing a parallel to serial port adapter
Chapter: 01/2010; In book: Dr Dobbs Journal, Edition: February 2010, Publisher: Dr Dobbs Journal, Editors: Dr Dobbs Journal
Comments on this publication
ResearchGate members can add comments. Sign up now and post your comment!
Data provided are for informational purposes only. Although carefully collected, accuracy cannot be guaranteed. The impact factor represents a rough estimation of the journal's impact factor and does not reflect the actual current impact factor. Publisher conditions are provided by RoMEO. Differing provisions from the publisher's actual policy or licence agreement may be applicable.
Page 1
Page 2
Page 3
Page 4
Page 5
Page 6
Page 7
Page 8
Page 9
Page 1
Designing a Parallel-to-Serial Port Adapter
A parallel-to-serial port adapter for bi-directional parallel-to-serial and serial-to-parallel data
transfer
By Pawan Kumar Janbandhu
February 24, 2010
URL:http://www.ddj.com/cpp/223100564
Pawan Kumar Janbandhu can be contacted at pawan_janbandhu@yahoo.com.
Most electronic devices available in market today come with either serial or parallel port which can be
interfaced with each other using a PC. A standard PC comes with a parallel port (Standard Parallel Port, SPP
/Enhanced Parallel Port, EPP) and Serial ports (USB/RS-232). SPP permits data transfer at the rates of
150kB/sec and is used for printing as well as non-printing purposes like tape-backup systems, DVD drives, and
LAN adapters. EPP increases the performance by mainly reducing the software delays and permits speeds as
high as 2MB/sec which is roughly 50-100 times faster than SPP allowing bi-directional data transfer over data
lines. It is primarily used by non-printer peripherals -- DVD, tape, and hard drives, network adapters, etc. On the
other hand, ECP (Enhanced Capability Port) is used for printers, scanners, and the like which provide features
such as increased speed, data compression, and so on. The RS-232 interface of the PC is used for serial
communication and permits data transfer in the range of 5-10kB/sec and is used in network adapters, serial
printers, etc.
In this article, I present the design of an inexpensive and standalone parallel and serial port adapter that enables
data transfer between serial port (RS-232) and parallel ports (SPP/EPP) of devices such as PCs and printers. I
include both C and assembly programs for testing parallel-to-serial port transmission using the adapter that can
be used to implement its device driver.
Interfacing Through Serial and Parallel Ports
Serial communication can be synchronous or asynchronous. In this article, I only address asynchronous
communication. In serial mode, a byte is transferred with all its bits transmitted one after another. The speed of
serial communication is mainly determined by the baud rate defined which is the number of bits transmitted /
received per second. In asynchronous mode, a start bit (usually low) and a stop bit (usually high) is added at the
beginning and end respectively of 8 data bits to distinguish between two consecutive bytes. You can further
enhance serial communication by adding a parity bit at the end of 8 data bits.
The RS-232 port of PC for serial communication comes as 25-pin and 9-pin adapter in PCs. Only the TxD, RxD,
and GND pins of this port are sufficient for serial communication. However, other signals like DSR, RTS, DTR,
Dr. Dobb's | Designing a Parallel-to-Serial Port Adapter | February 24, 2010 http://www.drdobbs.com/article/printableArticle.jhtml;jsessionid=IJHV...
1 of 9 6/6/2010 4:29 PM
A parallel-to-serial port adapter for bi-directional parallel-to-serial and serial-to-parallel data
transfer
By Pawan Kumar Janbandhu
February 24, 2010
URL:http://www.ddj.com/cpp/223100564
Pawan Kumar Janbandhu can be contacted at pawan_janbandhu@yahoo.com.
Most electronic devices available in market today come with either serial or parallel port which can be
interfaced with each other using a PC. A standard PC comes with a parallel port (Standard Parallel Port, SPP
/Enhanced Parallel Port, EPP) and Serial ports (USB/RS-232). SPP permits data transfer at the rates of
150kB/sec and is used for printing as well as non-printing purposes like tape-backup systems, DVD drives, and
LAN adapters. EPP increases the performance by mainly reducing the software delays and permits speeds as
high as 2MB/sec which is roughly 50-100 times faster than SPP allowing bi-directional data transfer over data
lines. It is primarily used by non-printer peripherals -- DVD, tape, and hard drives, network adapters, etc. On the
other hand, ECP (Enhanced Capability Port) is used for printers, scanners, and the like which provide features
such as increased speed, data compression, and so on. The RS-232 interface of the PC is used for serial
communication and permits data transfer in the range of 5-10kB/sec and is used in network adapters, serial
printers, etc.
In this article, I present the design of an inexpensive and standalone parallel and serial port adapter that enables
data transfer between serial port (RS-232) and parallel ports (SPP/EPP) of devices such as PCs and printers. I
include both C and assembly programs for testing parallel-to-serial port transmission using the adapter that can
be used to implement its device driver.
Interfacing Through Serial and Parallel Ports
Serial communication can be synchronous or asynchronous. In this article, I only address asynchronous
communication. In serial mode, a byte is transferred with all its bits transmitted one after another. The speed of
serial communication is mainly determined by the baud rate defined which is the number of bits transmitted /
received per second. In asynchronous mode, a start bit (usually low) and a stop bit (usually high) is added at the
beginning and end respectively of 8 data bits to distinguish between two consecutive bytes. You can further
enhance serial communication by adding a parity bit at the end of 8 data bits.
The RS-232 port of PC for serial communication comes as 25-pin and 9-pin adapter in PCs. Only the TxD, RxD,
and GND pins of this port are sufficient for serial communication. However, other signals like DSR, RTS, DTR,
Dr. Dobb's | Designing a Parallel-to-Serial Port Adapter | February 24, 2010 http://www.drdobbs.com/article/printableArticle.jhtml;jsessionid=IJHV...
1 of 9 6/6/2010 4:29 PM
Page 2
and CTS can be be used for "hardware handshaking". Handshaking can also be achieved using XON or XOFF
characters which is known as "software handshaking". The voltage levels for RS-232 signals can be anywhere
between -3V to -15V for a mark (logic high) and +3V to +15V for space (logic low). Voltage levels o f ±12V are
more generally used to permit high noise margin. Because of high voltage levels, RS-232 is not TTL compatible.
Hence, line drivers or receivers (such as MC 1488 and MC 1489 respectively) are required to interface the serial
port with an external device. Alternately, this can be achieved using a circuit like that in Figure 1. This circuit
ensures voltage level compatibility for interfacing a TTL compatible device with RS-232 port.
[Click image to view at full size]
Figure 1: Simplified circuit for interfacing external device with RS-232 port
Data can be read or written to the serial port of PC via the IN and OUT instruction on the serial port register
(0x2f8/0x3f8). Baud rates on either side of the PC and external interfacing device should be set to same value to
ensure correct data transfer. This involves data transfers between devices with IN/OUT data in parallel format;
i.e. exchange of whole byte on 8 parallel data lines at a time, rather than bit-by-bit as in case of serial
communication. Hence, parallel data transfer is faster than serial communication. Examples of such devices are
PCs, printers, drives etc. Parallel communication can be bi-directional, i.e. data can be received as well as
transmitted on the same data lines using Enhance Parallel Port (EPP) or unidirectional like Standard Parallel
Port (SPP) (data lines are output only) and printers (data can only be received).
Printers having Centronix parallel ports can be interfaced with the parallel port of the PCs for communication.
The printer port is TTL compatible. Hence, line drivers and receivers are not required to interface the printer
with external peripherals. Proper handshaking is required for interfacing printer's parallel port with external
devices such as PC to ensure correct data transfer.
Dr. Dobb's | Designing a Parallel-to-Serial Port Adapter | February 24, 2010 http://www.drdobbs.com/article/printableArticle.jhtml;jsessionid=IJHV...
2 of 9 6/6/2010 4:29 PM
characters which is known as "software handshaking". The voltage levels for RS-232 signals can be anywhere
between -3V to -15V for a mark (logic high) and +3V to +15V for space (logic low). Voltage levels o f ±12V are
more generally used to permit high noise margin. Because of high voltage levels, RS-232 is not TTL compatible.
Hence, line drivers or receivers (such as MC 1488 and MC 1489 respectively) are required to interface the serial
port with an external device. Alternately, this can be achieved using a circuit like that in Figure 1. This circuit
ensures voltage level compatibility for interfacing a TTL compatible device with RS-232 port.
[Click image to view at full size]
Figure 1: Simplified circuit for interfacing external device with RS-232 port
Data can be read or written to the serial port of PC via the IN and OUT instruction on the serial port register
(0x2f8/0x3f8). Baud rates on either side of the PC and external interfacing device should be set to same value to
ensure correct data transfer. This involves data transfers between devices with IN/OUT data in parallel format;
i.e. exchange of whole byte on 8 parallel data lines at a time, rather than bit-by-bit as in case of serial
communication. Hence, parallel data transfer is faster than serial communication. Examples of such devices are
PCs, printers, drives etc. Parallel communication can be bi-directional, i.e. data can be received as well as
transmitted on the same data lines using Enhance Parallel Port (EPP) or unidirectional like Standard Parallel
Port (SPP) (data lines are output only) and printers (data can only be received).
Printers having Centronix parallel ports can be interfaced with the parallel port of the PCs for communication.
The printer port is TTL compatible. Hence, line drivers and receivers are not required to interface the printer
with external peripherals. Proper handshaking is required for interfacing printer's parallel port with external
devices such as PC to ensure correct data transfer.
Dr. Dobb's | Designing a Parallel-to-Serial Port Adapter | February 24, 2010 http://www.drdobbs.com/article/printableArticle.jhtml;jsessionid=IJHV...
2 of 9 6/6/2010 4:29 PM
Page 3
The standard PC parallel port comes as 25-pin female type connector containing 17 active lines and eight ground
lines. Unlike RS-232 port, the parallel port of a PC is TTL compatible. The 17 signal lines are divided into eight
data, five status, and four control lines. Data that is written to data port appears as active high signals on the
corresponding pins of the parallel port connector. The port uses totem-pole drivers; its outputs are actively
driven both high and low. Control lines comprise the four least significant bits of the 8-bit control port. They are
typically driven by open collector drivers. Control port can be used as both i/p and o/p port. However, using
control lines is not as good as input lines as some parallel ports use totem-pole, not the more common open
collector drivers on the lines, and other do not sense the actual physical levels on these lines. Status lines
comprise of five most significant bits of the 8-bit read only status port. Bit 6 of the status port is also the parallel
port interrupt request (IRQ signal). More details can be found in Using Parallel Port Adapter as a Host Interface
Port by Dhananjay V. Gadre and in the IBM Technical Reference Library.
Data can be transferred by writing OUT instruction on the data register and can be received in 4-bit nibbles using
status port or in 8-bit form by writing IN instructions on both control and status ports. However, these methods
are software intensive. The device driver on the PC checks if peripheral is ready by probing Busy line then
places outgoing data onto the data lines and generates a Strobe signal on one of the control lines. Similarly, for
reading data, the PC reads data on the status lines and control lines (in byte mode) or a nibble on the status lines
(in nibble mode) and then generate an Ack signal (acknowledge). Since, this is so software intensive, data
transfer rates are limited to between 50 and 150kB/sec.
Using EPP, a data byte can be transferred by a single IN/OUT instruction to the I/O controller which handles the
handshaking and strobe signal generations. Thus data transfer rates are limited by the rate at which the
instruction can be executed and speeds up to 1-2MB/s can be easily achieved. The EPP protocol defines four
data transfer cycles -- data write, data read, address write and address read. Data cycles are used for transferring
data to and from peripheral devices while address cycles are used to exchange device address, control
information etc. Only 14 of the 17 SPP signals are utilized in EPP mode for data transfer, handshaking and
strobe. Data can be transmitted by simply performing OUT instruction to "base_address + 4" where base address
is the address where the Data register is located in the PC's I/O space which is 0x378h for LPT1 and 0x278h for
LPT2. The EPP controller generates the necessary handshake signals and strobe to transfer the data using an
EPP Data Write cycle. Address cycles are generated when read/write I/O operation are generated to
"base_address+3". More details can be found in The Enhanced Parallel Printer Port for Fast I/O by Dhananjay
V. Gadre and Larry A. Stein.
The Design of a Parallel-toSerial Adapter Using the AT89C2051 Microcontroller
The heart of the adapter is the microcontroller AT89C2051. AT89C2051 is a Atmel 20-pin microcontroller with
2k bytes of programmable and erasable read only memory (PEROM) with 15 I/O lines including a full duplex
serial port and 8-bit bi-directional port and is compatible with the MCS-51 instruction set. All the data transfer
described below was done with the microcontroller being set to mode one (one start bit, 8 data bits, one stop bit)
and baud rate given by the following equation:
Baud rate = ((2SMOD)*12*(106))/(32*12*(256-nu))
where nu is the number to be loaded in the timer 1 register (=CCh for 1200, EEh for 3600, F9h for 9600),
SMOD = 1. The data transfer was carried out at various baud rates using 12MHz crystal oscillator used at the
microcontroller end.
Parallel to Serial Port Communication
Parallel to serial port communication using same PC can be established as follows. Strobe, Busy, and Ack signals
of the SPP are used for handshaking whereas RS232 serial port is used in software handshake mode. Listings 1
Dr. Dobb's | Designing a Parallel-to-Serial Port Adapter | February 24, 2010 http://www.drdobbs.com/article/printableArticle.jhtml;jsessionid=IJHV...
3 of 9 6/6/2010 4:29 PM
lines. Unlike RS-232 port, the parallel port of a PC is TTL compatible. The 17 signal lines are divided into eight
data, five status, and four control lines. Data that is written to data port appears as active high signals on the
corresponding pins of the parallel port connector. The port uses totem-pole drivers; its outputs are actively
driven both high and low. Control lines comprise the four least significant bits of the 8-bit control port. They are
typically driven by open collector drivers. Control port can be used as both i/p and o/p port. However, using
control lines is not as good as input lines as some parallel ports use totem-pole, not the more common open
collector drivers on the lines, and other do not sense the actual physical levels on these lines. Status lines
comprise of five most significant bits of the 8-bit read only status port. Bit 6 of the status port is also the parallel
port interrupt request (IRQ signal). More details can be found in Using Parallel Port Adapter as a Host Interface
Port by Dhananjay V. Gadre and in the IBM Technical Reference Library.
Data can be transferred by writing OUT instruction on the data register and can be received in 4-bit nibbles using
status port or in 8-bit form by writing IN instructions on both control and status ports. However, these methods
are software intensive. The device driver on the PC checks if peripheral is ready by probing Busy line then
places outgoing data onto the data lines and generates a Strobe signal on one of the control lines. Similarly, for
reading data, the PC reads data on the status lines and control lines (in byte mode) or a nibble on the status lines
(in nibble mode) and then generate an Ack signal (acknowledge). Since, this is so software intensive, data
transfer rates are limited to between 50 and 150kB/sec.
Using EPP, a data byte can be transferred by a single IN/OUT instruction to the I/O controller which handles the
handshaking and strobe signal generations. Thus data transfer rates are limited by the rate at which the
instruction can be executed and speeds up to 1-2MB/s can be easily achieved. The EPP protocol defines four
data transfer cycles -- data write, data read, address write and address read. Data cycles are used for transferring
data to and from peripheral devices while address cycles are used to exchange device address, control
information etc. Only 14 of the 17 SPP signals are utilized in EPP mode for data transfer, handshaking and
strobe. Data can be transmitted by simply performing OUT instruction to "base_address + 4" where base address
is the address where the Data register is located in the PC's I/O space which is 0x378h for LPT1 and 0x278h for
LPT2. The EPP controller generates the necessary handshake signals and strobe to transfer the data using an
EPP Data Write cycle. Address cycles are generated when read/write I/O operation are generated to
"base_address+3". More details can be found in The Enhanced Parallel Printer Port for Fast I/O by Dhananjay
V. Gadre and Larry A. Stein.
The Design of a Parallel-toSerial Adapter Using the AT89C2051 Microcontroller
The heart of the adapter is the microcontroller AT89C2051. AT89C2051 is a Atmel 20-pin microcontroller with
2k bytes of programmable and erasable read only memory (PEROM) with 15 I/O lines including a full duplex
serial port and 8-bit bi-directional port and is compatible with the MCS-51 instruction set. All the data transfer
described below was done with the microcontroller being set to mode one (one start bit, 8 data bits, one stop bit)
and baud rate given by the following equation:
Baud rate = ((2SMOD)*12*(106))/(32*12*(256-nu))
where nu is the number to be loaded in the timer 1 register (=CCh for 1200, EEh for 3600, F9h for 9600),
SMOD = 1. The data transfer was carried out at various baud rates using 12MHz crystal oscillator used at the
microcontroller end.
Parallel to Serial Port Communication
Parallel to serial port communication using same PC can be established as follows. Strobe, Busy, and Ack signals
of the SPP are used for handshaking whereas RS232 serial port is used in software handshake mode. Listings 1
Dr. Dobb's | Designing a Parallel-to-Serial Port Adapter | February 24, 2010 http://www.drdobbs.com/article/printableArticle.jhtml;jsessionid=IJHV...
3 of 9 6/6/2010 4:29 PM
Page 4
and 2 (at the of this article) present the assembly and C program used to test the adapter in parallel-to-serial data
transmission mode. Figure 2 is the circuit diagram for this. Figure 3 is the timing diagram for parallel-to-serial
data transfer using handshake signals. The timing cycles for parallel to serial data transfer are:
The program on the PC first checks the Busy line. If Busy is low (i.e. microcontroller is ready to receive
data), it writes data on the data register and sends Strobe signal (changes Strobe to low) and waits for Ack
from the microcontroller.
1.
On receiving strobe signal, microcontroller deasserts Busy to high, reads data and sends Ack (sets Ack to
high).
2.
As soon as PC receives Ack signal, it removes Strobe and removes data (writes 0xff on data lines since,
microcontroller requires all the pins on which it is receiving data i.e. port 1 to be set to high in order for it
to read data on the data lines) and waits for Busy to be asserted low by the controller.
3.
After receiving Strobe, microcontroller deasserts Ack to low and sends the byte to the PC over the serial
port and deasserts Busy to low.
4.
Program reads the byte from the serial register and the next cycle begins.5.
The program was tested successfully with baud rates of 1200 and 3600.
[Click image to view at full size]
Figure 2: Circuit Diagram for Parallel Port to Serial Port Interface using AT89C2051 microcontroller
[Click image to view at full size]
Dr. Dobb's | Designing a Parallel-to-Serial Port Adapter | February 24, 2010 http://www.drdobbs.com/article/printableArticle.jhtml;jsessionid=IJHV...
4 of 9 6/6/2010 4:29 PM
transmission mode. Figure 2 is the circuit diagram for this. Figure 3 is the timing diagram for parallel-to-serial
data transfer using handshake signals. The timing cycles for parallel to serial data transfer are:
The program on the PC first checks the Busy line. If Busy is low (i.e. microcontroller is ready to receive
data), it writes data on the data register and sends Strobe signal (changes Strobe to low) and waits for Ack
from the microcontroller.
1.
On receiving strobe signal, microcontroller deasserts Busy to high, reads data and sends Ack (sets Ack to
high).
2.
As soon as PC receives Ack signal, it removes Strobe and removes data (writes 0xff on data lines since,
microcontroller requires all the pins on which it is receiving data i.e. port 1 to be set to high in order for it
to read data on the data lines) and waits for Busy to be asserted low by the controller.
3.
After receiving Strobe, microcontroller deasserts Ack to low and sends the byte to the PC over the serial
port and deasserts Busy to low.
4.
Program reads the byte from the serial register and the next cycle begins.5.
The program was tested successfully with baud rates of 1200 and 3600.
[Click image to view at full size]
Figure 2: Circuit Diagram for Parallel Port to Serial Port Interface using AT89C2051 microcontroller
[Click image to view at full size]
Dr. Dobb's | Designing a Parallel-to-Serial Port Adapter | February 24, 2010 http://www.drdobbs.com/article/printableArticle.jhtml;jsessionid=IJHV...
4 of 9 6/6/2010 4:29 PM
Page 5
Figure 3: Timing Diagram for Parallel-to-Serial Interface using the AT89C2051 microcontroller
Serial-to-Parallel Port Communication
Serial to parallel data transfer can be achieved in the following way. Figure 4 is the circuit diagram for interface
between RS232 and printer parallel port. Strobe is used to synchronize data transfer between microcontroller
and printer. Busy and Ack signals are used to accomplish data transfer with proper handshaking. Transmission of
any one character e.g. "A" by microcontroller to PC was used to synchronize data transfer between PC and
microcontroller.
Timing cycles for data transfer are:
Microcontroller first checks the Busy line. If it is asserted low (printer not busy), it sends a character "A"
to the PC.
1.
As soon as the PC receives this character, it writes data on the serial register and keep on polling for "A"
on the receive buffer.
2.
Microcontroller waits for the byte to be received over serial port by polling received data ready buffer or
by calling the interrupt subroutine and when the data is ready, it writes it on the data lines of port 1
followed by assertion of Strobe to low.
3.
Printer asserts Busy to high, reads data sends Ack, writes data and when ready to receive another byte
asserts Busy to low.
4.
Meanwhile, microcontroller waits for Ack, removes Strobe as soon as it receives Ack and keep on polling
Busy pin until it is asserted to low and then sends character "A" to the PC to indicate that it is ready to
receive another byte and the cycle continues.
5.
[Click image to view at full size]
Dr. Dobb's | Designing a Parallel-to-Serial Port Adapter | February 24, 2010 http://www.drdobbs.com/article/printableArticle.jhtml;jsessionid=IJHV...
5 of 9 6/6/2010 4:29 PM
Serial-to-Parallel Port Communication
Serial to parallel data transfer can be achieved in the following way. Figure 4 is the circuit diagram for interface
between RS232 and printer parallel port. Strobe is used to synchronize data transfer between microcontroller
and printer. Busy and Ack signals are used to accomplish data transfer with proper handshaking. Transmission of
any one character e.g. "A" by microcontroller to PC was used to synchronize data transfer between PC and
microcontroller.
Timing cycles for data transfer are:
Microcontroller first checks the Busy line. If it is asserted low (printer not busy), it sends a character "A"
to the PC.
1.
As soon as the PC receives this character, it writes data on the serial register and keep on polling for "A"
on the receive buffer.
2.
Microcontroller waits for the byte to be received over serial port by polling received data ready buffer or
by calling the interrupt subroutine and when the data is ready, it writes it on the data lines of port 1
followed by assertion of Strobe to low.
3.
Printer asserts Busy to high, reads data sends Ack, writes data and when ready to receive another byte
asserts Busy to low.
4.
Meanwhile, microcontroller waits for Ack, removes Strobe as soon as it receives Ack and keep on polling
Busy pin until it is asserted to low and then sends character "A" to the PC to indicate that it is ready to
receive another byte and the cycle continues.
5.
[Click image to view at full size]
Dr. Dobb's | Designing a Parallel-to-Serial Port Adapter | February 24, 2010 http://www.drdobbs.com/article/printableArticle.jhtml;jsessionid=IJHV...
5 of 9 6/6/2010 4:29 PM
Page 6
Figure 4: Circuit Diagram for Serial Port to Printer Parallel Port Interface using AT89C2051 microcontroller
The program can, be further enhanced by providing a buffer of size 60-80 characters on the microcontroller.
The design can be easily enhanced to support Enhanced Parallel Port (EPP) instead of SPP. EPP requires to
outport data on the data register to transfer data and inport data on the data register to read data. In addition,
nDataStrobe signal is to be monitored which tells a data write or read operation in progress.
Finalizing the Adapter
The final adapter will have three lines for serial port -- RxD, TxD and Ground -- and one 25-pin interface. The
adapter will have both parallel-to-serial mode and serial-to-printer mode programs at different locations. A
switch for 0/5V (P3.7 on the microcontroller) can be used to decide which program to run. Similarly, you can
use P3.3 to set 2 baud rates. Everytime a serial interrupt occurs, the interrupt routine first checks which program
caused the interrupt by checking pin P3.7 and then jumping to respective location for the different TxD and RxD
routines. Final circuitry would be as shown in Figures 2 and 4.
Conclusion
I've presented a simple standalone parallel to serial port adapter using the 20-pin Atmel AT89C2051
microcontroller that supports bi-directional data communication between RS-232 and SPP ports which can be
further enhanced to support USB and EPP/ECP ports on similar lines. The adapter supports auto baud setting
and has a switch to determine which routine to run (parallel to serial OR serial to printer port communication). It
can be used for numerous purposes like network adapters for interfacing various electronic devices. The adapter
was successfully tested using PC and printer. C and assembly routines test the adapter in parallel-to-serial port
mode that can be used to develop its device drivers.
Dr. Dobb's | Designing a Parallel-to-Serial Port Adapter | February 24, 2010 http://www.drdobbs.com/article/printableArticle.jhtml;jsessionid=IJHV...
6 of 9 6/6/2010 4:29 PM
The program can, be further enhanced by providing a buffer of size 60-80 characters on the microcontroller.
The design can be easily enhanced to support Enhanced Parallel Port (EPP) instead of SPP. EPP requires to
outport data on the data register to transfer data and inport data on the data register to read data. In addition,
nDataStrobe signal is to be monitored which tells a data write or read operation in progress.
Finalizing the Adapter
The final adapter will have three lines for serial port -- RxD, TxD and Ground -- and one 25-pin interface. The
adapter will have both parallel-to-serial mode and serial-to-printer mode programs at different locations. A
switch for 0/5V (P3.7 on the microcontroller) can be used to decide which program to run. Similarly, you can
use P3.3 to set 2 baud rates. Everytime a serial interrupt occurs, the interrupt routine first checks which program
caused the interrupt by checking pin P3.7 and then jumping to respective location for the different TxD and RxD
routines. Final circuitry would be as shown in Figures 2 and 4.
Conclusion
I've presented a simple standalone parallel to serial port adapter using the 20-pin Atmel AT89C2051
microcontroller that supports bi-directional data communication between RS-232 and SPP ports which can be
further enhanced to support USB and EPP/ECP ports on similar lines. The adapter supports auto baud setting
and has a switch to determine which routine to run (parallel to serial OR serial to printer port communication). It
can be used for numerous purposes like network adapters for interfacing various electronic devices. The adapter
was successfully tested using PC and printer. C and assembly routines test the adapter in parallel-to-serial port
mode that can be used to develop its device drivers.
Dr. Dobb's | Designing a Parallel-to-Serial Port Adapter | February 24, 2010 http://www.drdobbs.com/article/printableArticle.jhtml;jsessionid=IJHV...
6 of 9 6/6/2010 4:29 PM
Page 7
Acknowledgements
This work is part of my B-Tech final year project done at IIT, Bombay in 1998-99. I thank all the people in SPI
lab in Electrical Engineering department for their timely support whenever required.
/* Description: The program initializes various parallel
port registers, reads a character from the keyboard,
displays it on screen, transmits it over parallel port,
reads the received character on the serial port and
displays it on the screen.*/
#include <stdio.h>
#include <dos.h>
#include <conio.h>
#define DATA 0x378
#define STAT 0x379
#define CNTRL 0x37a
#define SP2 0x2f8
#define LCR 0x2fb
#define DLL 0x2f8
#define DLH 0x2f9
#define LSR 0x2fd
#define IER 0x2f9
#define IIR 0x2fa
void main()
{
unsigned inc1, inc2, inr;
int ch;
int rcv;
/*-------------------------Initialization--------------------------*/
outportb(DATA, 0XFF); /* initialize data port */
outportb(CNTRL, 0x00);
outportb(LCR, 0x00);
outportb(IER, 0x03); /*set interrupt enable register */
outportb(LCR, 0x83); /* set bit format, DLAB=1*/
outportb(DLL, 0x60); /*set baud rate = 1200 */
outportb(DLH, 0x00);
/*------------------------Parallel Port--------------------*/
clrscr();
while((ch = getch()) != '\r')
{
putchar(ch);
delay(1);
do /* wait for Busy signal*/
{
inc1=inportb(STAT);
}
while ((inc1 & 0x80) == 0x80);
outportb(DATA, ch);
delay(5);
outportb(CNTRL, 0x01); /* send strobe */
do /* wait for Ack */
{
inc2=inportb(STAT);
}
while((inc2 & 0x40) == 0x40);
delay(2);
outportb(CNTRL, 0X00); /* clear strobe */
delay(5);
outportb(DATA, 0xff); /*remove data */
/*----------------Serial Port----------------------*/
Dr. Dobb's | Designing a Parallel-to-Serial Port Adapter | February 24, 2010 http://www.drdobbs.com/article/printableArticle.jhtml;jsessionid=IJHV...
7 of 9 6/6/2010 4:29 PM
This work is part of my B-Tech final year project done at IIT, Bombay in 1998-99. I thank all the people in SPI
lab in Electrical Engineering department for their timely support whenever required.
/* Description: The program initializes various parallel
port registers, reads a character from the keyboard,
displays it on screen, transmits it over parallel port,
reads the received character on the serial port and
displays it on the screen.*/
#include <stdio.h>
#include <dos.h>
#include <conio.h>
#define DATA 0x378
#define STAT 0x379
#define CNTRL 0x37a
#define SP2 0x2f8
#define LCR 0x2fb
#define DLL 0x2f8
#define DLH 0x2f9
#define LSR 0x2fd
#define IER 0x2f9
#define IIR 0x2fa
void main()
{
unsigned inc1, inc2, inr;
int ch;
int rcv;
/*-------------------------Initialization--------------------------*/
outportb(DATA, 0XFF); /* initialize data port */
outportb(CNTRL, 0x00);
outportb(LCR, 0x00);
outportb(IER, 0x03); /*set interrupt enable register */
outportb(LCR, 0x83); /* set bit format, DLAB=1*/
outportb(DLL, 0x60); /*set baud rate = 1200 */
outportb(DLH, 0x00);
/*------------------------Parallel Port--------------------*/
clrscr();
while((ch = getch()) != '\r')
{
putchar(ch);
delay(1);
do /* wait for Busy signal*/
{
inc1=inportb(STAT);
}
while ((inc1 & 0x80) == 0x80);
outportb(DATA, ch);
delay(5);
outportb(CNTRL, 0x01); /* send strobe */
do /* wait for Ack */
{
inc2=inportb(STAT);
}
while((inc2 & 0x40) == 0x40);
delay(2);
outportb(CNTRL, 0X00); /* clear strobe */
delay(5);
outportb(DATA, 0xff); /*remove data */
/*----------------Serial Port----------------------*/
Dr. Dobb's | Designing a Parallel-to-Serial Port Adapter | February 24, 2010 http://www.drdobbs.com/article/printableArticle.jhtml;jsessionid=IJHV...
7 of 9 6/6/2010 4:29 PM
Page 8
do /* wait for Data*/
{
inr = inportb(IIR);
}
while((inr & 0x04) != 0x04);
outportb(LCR, 0x03); /* dlab = 0 */
rcv=inportb(SP2);
putchar(rcv);
}
/*------------------------------------------------------*/
/* send next byte */
}
Listing 1: C program
/*Description: The program polls for Strobe to be
asserted to low by the PC (indicating data ready),
reads data from the parallel port and acknowledges it,
transmits it over transmitter pin and deasserts Busy to
low to indicate that next cycle may begin.*/
.org 0000h
ljmp main
.org 0023h
nop
nop
clr scon.1
nop
reti
main: .org 0050h
anl tmod,#0fh
orl tmod,#20h
mov th1,#0cch
orl pcon, #80h
orl tcon, #40h
mov scon, #50h
mov ie, #90h
setb p3.5
getdata: setb p3.4
strwait: jb p3.2, strwait
clr p3.4
nop
mov a,p1
clr p3.5
nop
nop
stb: jnb p3.2, stb
setb p3.5
nop
nop
mov sbuf,a
nop
nop
nop
nop
sjmp getdata
.end
Listing 2: Assembly program
Dr. Dobb's | Designing a Parallel-to-Serial Port Adapter | February 24, 2010 http://www.drdobbs.com/article/printableArticle.jhtml;jsessionid=IJHV...
8 of 9 6/6/2010 4:29 PM
{
inr = inportb(IIR);
}
while((inr & 0x04) != 0x04);
outportb(LCR, 0x03); /* dlab = 0 */
rcv=inportb(SP2);
putchar(rcv);
}
/*------------------------------------------------------*/
/* send next byte */
}
Listing 1: C program
/*Description: The program polls for Strobe to be
asserted to low by the PC (indicating data ready),
reads data from the parallel port and acknowledges it,
transmits it over transmitter pin and deasserts Busy to
low to indicate that next cycle may begin.*/
.org 0000h
ljmp main
.org 0023h
nop
nop
clr scon.1
nop
reti
main: .org 0050h
anl tmod,#0fh
orl tmod,#20h
mov th1,#0cch
orl pcon, #80h
orl tcon, #40h
mov scon, #50h
mov ie, #90h
setb p3.5
getdata: setb p3.4
strwait: jb p3.2, strwait
clr p3.4
nop
mov a,p1
clr p3.5
nop
nop
stb: jnb p3.2, stb
setb p3.5
nop
nop
mov sbuf,a
nop
nop
nop
nop
sjmp getdata
.end
Listing 2: Assembly program
Dr. Dobb's | Designing a Parallel-to-Serial Port Adapter | February 24, 2010 http://www.drdobbs.com/article/printableArticle.jhtml;jsessionid=IJHV...
8 of 9 6/6/2010 4:29 PM
Page 9
Dr. Dobb's | Designing a Parallel-to-Serial Port Adapter | February 24, 2010 http://www.drdobbs.com/article/printableArticle.jhtml;jsessionid=IJHV...
9 of 9 6/6/2010 4:29 PM
9 of 9 6/6/2010 4:29 PM
Loading ...
Resources
-
4.01 MB · Uploaded Jan 26, 2012 by Pawan Kumar Janbandhu
Science & Research Jobs
Consumer Lifestyle - Integral Project Leader
Position: Project Manager
Employer: Philips (China) Investment Co.,Ltd

