AnsweredAssumed Answered


Question asked by VRFuser on May 5, 1997
send q VRf-Parallel_Port ww vrf

from: Greg Goebel / HP-MXD / 970-679-3030 / FAX 970-679-5971
to:   VRf
date: Tuesday, 06 May 1997 0946 MDT

Looks like I forgot something (thanks Ted).  GVG

--------------------------------- cut here ----------------------------------

The PC Parallel Port

   *v2.0 / 24 dec 95 / gvg*

* This document provides an overview of PC parallel-port technology and a
simple introduction to programming it at a bit level.

* Revision history:

   v1.0 / not dated / gvg / Initial version contained section 2.0 only.
   v1.1 / 12 oct 95 / gvg / Web update.
   v2.0 / 24 dec 95 / gvg / Extended to full parallel port tutor.



* Personal-computer users are normally familiar with the "parallel port" on
the backs of their computers; this is an 8-bit parallel interface that is
generally used to communicate with printers, but in recent years has evolved
to a general-purpose communications interface.

The PC parallel port was introduced with their IBM PC in the early 1980s; it
was derived from an earlier interface developed by Centronics Corporation in

The original "Centronics" interface featured a 36-pin connector on both the
computer and printer ends of the cable; IBM used a variation of the scheme,
with the same 36-pin connector on the printer end and a 25-pin "subminiature
D" connector (similar to that for an RS-232 port) on the computer side.  The
parallel port on the PC supports the 8 data lines and a subset of the original
Centronics control signals; it eventually completely displaced the Centronics

The traditional or "standard" parallel port interface was an output-only
scheme with a maximum transfer rate of 150 KB per second and a maximum cable
length of about 10 feet.  It was used almost exclusively to communicate with
printers; it was much easier to configure than an RS-232 interface -- it was
about as close to "plug and play" as the old PCs ever got -- and was much

* By the early 1990s, when the capabilities of and demands on printers had
grown considerably, 150 KB per second was too slow; something better was
needed.  To address this problem, Zenith, Xircom, and Intel formed an
"Enhanced Parallel Port" (EPP) Partnership, and introduced an EPP spec in

This new spec retained compatibility with the original standard parallel port
definition, but provided additional timing specs that drove the maximum data
transfer rate up to 2 MB per second (and possibly as high as 8 MB per second).
However, the price for this increased speed was that cable lengths were
restricted to 6 feet, not 10.

* The standard parallel port was actually in principle bidirectional -- you
could in general read signals if you wired external pull-up resistors to the
data pins correctly -- but support of bidirectional operation was not spec'd
in detail and bidirectional support for parallel ports in PCs was
traditionally a little "mushy".

In 1992, Hewlett-Packard joined with Microsoft to come up with a detailed
bidirectional "Extended Capabilities Port" (ECP) spec that was built on top of
EPP.  Like EPP, ECP remains compatible with the original standard parallel
port, but defines a fast two-way communications scheme -- with optional data
compression to make better use of bandwidth.

The ECP spec is much more complete than the standard parallel port definition;
it defines communications protocols with full handshaking and error detection.
The PC can query the remote device to determine if they can support fast
communications and can support data compression.  The data compression scheme
is based on simple "run length encoding", which means that repeated sequences
of identical bytes are simply sent as a count followed by that byte.

ECP also allows multiple devices on the same parallel port; it can send a
"channel address command" to select a single device for data communications.
If no channel address is provided, the address defaults to 0, which is a
"broadcast" address recognized by all devices.  Up to 127 devices can be



* A parallel port is potentially useful for performing digital-I/O; it uses
TTL-level voltages and is available on virtually all PCs.  However, there
isn't a lot of documentation available on how to do this.

It's not all that hard to do.  You can bit-level I/O through the parallel port
using Microsoft QBASIC or Visual BASIC for DOS OUT and INP commands; the
description is also relevant to any language that can perform "peeks and
pokes" to PC I/O address space.

A parallel port uses a 25-pin female connector, whose pin numbering appears as

      13                                                           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                                                     14

There is invariably one parallel port on a PC, which is identified in DOS as
LPT1; there may be additional parallel ports in some cases, identified in DOS
as LPT2, LPT3, and so on.

For standard parallel ports, each port has three control and data registers
that reside at certain default addresses in the I/O space; the table below
lists the addresses (in hexadecimal), the useful bits in the registers, and
how they correspond to the I/O pins:


    LPT1   LPT2   LPT3   reg bit   port pin   i/o

    3BC    378    278       0          2      output
                            1          3      output
                            2          4      output
                            3          5      output
                            4          6      output
                            5          7      output
                            6          8      output
                            7          9      output

    3BD    379    279       0         --        --
                            1         --        --
                            2         --        --
                            3         15      input
                            4         13      input
                            5         12      input
                            6         10      input
                            7*        11      input

    3BE    37A    27A       0*         1      output
                            1*        14      output
                            2         16      output
                            3*        17      output
                            4         --        --
                            5         --        --
                            6         --        --
                            7         --        --

    The "*" indicates inverted logic:  0=1, 1=0

Note that 3BC hex is the *default* assignment for LPT1; however, in many
PCs for various picky reasons this is a reserved assignment and LPT1 is
actually 378 hex.

As mentioned, you can read and write bytes to the I/O address space in
Microsoft BASIC dialects such as QBASIC or Visual BASIC for DOS with the INP
and OUT commands.  The following code fragments show how to use these
commands, as well as perform various bit manipulations:

   ' Store register addresses (expressed in hexadecimal) for LPT1 in
   ' INTEGER variables -- note that the variable names are arbitrary.

   Reg1% = &H3BC
   Reg2% = &H3BD
   Reg3% = &H3BE

   ' Get input data from LPT1 register 2 into the (arbitrary) INTEGER
   ' variable "InData%" and use AND to mask out unused bits (just as
   ' example of how to use AND in this way ... there's no real need to
   ' clear them out in this case); then check to see which bits are clear
   ' or set.

   InData% = INP(Reg2%)
   InData% = InData% AND &HF8         ' &HF8 = binary 1111_1000
   FOR N% = 3 TO 7
     IF (InData% AND 2^N%) = 0 THEN
       PRINT "Bit ";N%;" is clear."
       PRINT "Bit ";N%;" is set."
     END IF
   NEXT N%

   ' Send output data to register 1; and then successively set all the
   ' bits in the output port.

   OutData% = &HAA                    ' &HAA = binary 1010_1010
   OUT Reg1%, OutData%
   OutData% = 0
   FOR N% = 0 TO 7                    ' Output 0000_0001, 0000_0011, ...
     OutData% = OutData% OR 2^N%      ' ... , 0111_1111, 1111_1111.
     OUT Reg1%, OutData%
   NEXT N%

Not much to it.  Again, the commands are relevant to Microsoft BASICs -- if
you are using a different language, you will need to figure out the syntax
of any statements the language uses to perform peeks and pokes to the PC
I/O address space.

Note that the EPP and ECP specs define additional I/O ports, though they
still retain the original default three ports for compatibility with the
standard parallel port.  However, a definition of these additional registers
is beyond the scope of this document.



* The spread of ECP ports over modern PCs has resulted in quite a cottage
industry for parallel-port devices, such as video grabbers, digital cameras,
security keys, and so on ... it tends to be something of a mechanically clumsy
scheme (how many little boxes can you stack on top of a parallel port?) and
hopefully something better will be coming down the road soon.

This article was originally derived from a POPULAR ELECTRONICS article
by John J. Yacano; the 2.0 version incorporated extensive comments from
Winn L. Rosch's HARDWARE BIBLE (3rd Edition), published by SAMS.