Parallel port

by

L. Padilla

Introduction

The parallel port is extensively used in PCs, usually to communicate with close devices. This is due to the need of using many cables, at least 9 for software handshaking, but is common the use of more of them (hardware handshaking). The advantage of this port over the other extensively used PC port, the serial port, is its higher speed, about 10 times faster, and so in principle one can achieve data speeds in the order of several hundreds kilobytes per second.

The most common connection using the PC parallel port is done with the printer. As long as the printer does not generate data, it only accept them, the parallel port was made unidirectional, only for output. However there was no real need for that in the hardware, in fact there are several documents on the Web about how to make a unidirectional parallel port to be bidirectional. Today parallel ports are made bidirectional because some devices can take advance of it, like the Zip units.

Physical layer

The communication is physically controlled by an integrated circuit which works with TTL levels. Therefore it uses 0 Volts as logic 0 and +5 Volts as logic 1. The border between logic 0 and logic 1 is somewhere around 2 Volts. So to assure correct operation of the port you should work with signals between 0 and 1 Volts for logic 0 and between 3 and 6 Volts for logic 1. There are pull-up resistors to +5 Volts in all of the input lines of the parallel port and so by default, i.e. with no input, they are at high state (logic one).

The pin-out of the parallel port is the following:

                  DB-25S (female)

      13 12 11 10  9  8  7  6  5  4  3  2  1
     _________________________________________
     \ o  o  o  o  o  o  o  o  o  o  o  o  o /
      \ o  o  o  o  o  o  o  o  o  o  o  o  /
       \___________________________________/
       25 24 23 22 21 20 19 18 17 16 15 14

                  DB-25S pin-out
             ------------------------
             (o) pin  1 -Strobe
             (x) pin  2 +Data bit 0
             (x) pin  3 +Data bit 1
             (x) pin  4 +Data bit 2
             (x) pin  5 +Data bit 3
             (x) pin  6 +Data bit 4
             (x) pin  7 +Data bit 5
             (x) pin  8 +Data bit 6
             (x) pin  9 +Data bit 7
             (i) pin 10 +Acknowledge
             (i) pin 11 -Busy
             (i) pin 12 +Paper out
             (i) pin 13 +Select
             (o) pin 14 -Auto feed
             (i) pin 15 +Error
             (o) pin 16 +Initialize
             (o) pin 17 -Select input
             (-) pin 18  Ground
             ... ... ..  ...
             (-) pin 25  Ground

             (o) = pin is for output
             (i) = pin is for input
             (x) = pin is for output and maybe also for input
             (-) = pin is common reference

              +  = bit follow direct  logic: 1 = +5V, 0 =  0V
              -  = bit follow inverse logic: 1 =  0V, 0 = +5V

Using the port

Data can be easily sent through the parallel port using redirection in DOS. However you will only gain full control of the port writing your own applications. I will briefly describe the basics of the parallel port control for the purposes of simple interfacing.

The parallel port is controlled writing to and reading from 3 port addresses. The base addresses are 0378h and 037Ch for LPT1, 0278h and 027Ch for LPT2, and 03BCh for LPT3. The meaning of each port address and its bits is the following, where bit 0 is the least significant bit and bit 7 is the most significant bit.

Using the commands and routines which every programming language has to read from and write to the ports, you can set and check the status of the lines of the parallel port. This will let you interface with your own devices, for example you can open/close a relay which feeds a motor, a light, etc.; or you can check if a cable has been cut (alarm) or a switch has been activated, etc. For instance, if you want to monitor the status of the Busy line of LPT1 and activate Initialize when Busy is activated, you can do it with a BASIC program like the following, note that Busy uses inverse logic and Initialize direct logic.

10 WHILE 1 : REM *** Endless loop ***
20 BU = INP (&h0379) AND &h80 : REM *** Read port and mask bit for Busy ***
30 IF (BU <> 0) THEN GOTO 50 : REM *** Check if Busy is low ***
40 WEND
50 OUT &h037A, &h04 : REM *** Set Initialize high ***
60 END

For information about extended capabilities (bidirectional, EPP, ECP) see:

http://www.beyondlogic.org/spp/parallel.htm

http://www.fapo.com/1284int.htm


E-mail: padilla at domain "gae ucm es" (my PGP/GPG public key)
First version: 24-Jun-1997, last update: 21-Jan-2003
This link: http://www.gae.ucm.es/~padilla/extrawork/parallel.html
Color line
Back Go to the parent page: Specifications of useful PC ports.