⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ibmlpt.txt

📁 Parallel Port description of the communication port
💻 TXT
📖 第 1 页 / 共 4 页
字号:
Also available as:
<URL:ftp://ftp.rmii.com/pub2/hisys/parport>
<URL:http://www.rmii.com/~hisys/parport.html>
<URL:http://nyx10.cs.du.edu:8001/~zstewart/parport.html>

==== Version 0.96   9/1/94     Zhahai Stewart   zstewart@hisys.com

         Interfacing the IBM PC Parallel Printer Port

1. Overview

This document is called an FAQ because it answers many commonly asked
questions about the IBM parallel port, but it is formatted more as a brief
tutorial.  Read it twice before asking for more info; some stuff comes
late.

Most of this I puzzled out for myself from various documention and
experiences.  The IBM documentation has some errors; I've had to cross
correlate various sources including schematics to get a consistent and
workable picture.  Since the first version, others have contributed
information, proofreading, and suggestions (see acknowledgements).

Starting with the original IBM PC, IBM defined a standard parallel printer
port which has become very widespread.  This port uses a female DB-25S
connector on the computer, and a special male DB-25P to Centronics male 36
pin "IBM Printer cable" is used to connect to standard Centronics parallel
printers.  This DB-25 connector is possible because about half of the
Centronics pins carry just electrical ground.

The original definition was embodied in the "IBM Printer Adaptor", and the
"IBM Monochrome Display and Printer Adaptor" cards.

2. Conventions used in this document.

An electrical "high" (on a pin or line) is TTL high, +2.4 to +5 volts.
An electrical "low" is TTL low, 0 to +0.8 volts.

A data high is a 1, a data low is a 0.

The connection between data (eg: a register bit) and pins is direct if a
data 1 is associated with an electical TTL high, and inverted if data 1
is associated with TTL low.  An overall connection (data to TTL to data)
is considered direct if outputing a 1 produces a 1 on input at the other
end, or inverted if outputting a 1 produces a 0 on the other end.

Pin labels, like "-Strobe" or "+Busy", are as defined by the printers and
by IBM.  The prefix "-" (or draw a line over the name) implies that the
signal is "active low"; that is, that when the signal is in its active state
when electically low.  The "+" prefix means "active high", just the opposite.

I have labeled the Data Out register bits as D0 to D7, with D0 being the
least significant bit and D7 the most signficant.  The Control Out bits are
labeled C0 to C3 (for the ones which go to pins) and C4 (for IRQ enable),
and maybe C5 (for bidirection ports only, controls direction).  The Status
In bits are labeled S3 to S7 (corresponding to data and CPU bit positions).
Often I will suffix C0 to C3 and S3 to S7 with a "+" or "-" as a reminder
of whether or not that register bit is inverted as compared to the output
or input pin it is associated with; "-" is for inverted, of course.  All
the Data Out bits are direct (not inverted); likewise data in for
bidirectional printer ports, but I have not bothered to suffix a "+".

Hexadecimal numbers are prededed by "0x", the C convention.

A "tristated" or disabled electical output basically disconnects the output
from the line or pin (high impedance), neither driving it high nor low.

3. Addresses, naming, BIOS and DOS

IBM defined three standard port base addresses (in 80x86 IO address space).
The Printer Adaptor could use base address 0x378, or later 0x278, while
the Monochrome Display and Printer Adaptor used base address 0x3BC.

The IBM BIOS defines RAM space for 4 parallel printer port base addresses,
stored as 4 16 bit words starting at main memory address 0x408.  During
bootup, the BIOS will check for parallel printer ports at base addresses
0x3BC, 0x378, and 0x278, in order, and store the base addresses of any
that are found in consecutive locations in this table.  Unused entries
may be 0, or some BIOSes fill them with the first port address found.
Some software may ignore this table, but it is used by at least the BIOS
itself (eg: INT 17, Printer I/O), and by DOS, as described below.

The BIOS detects these ports by writing 0xAA to the Data Out register (at
I/O address Base+0), reading the Data Feedback register (same address), and
deciding there is a port installed if it reads 0xAA.  This could be confused
if any lines are externally pulled up or down (or if the port defaulted to
tristate, or if there is another readback device register at that address).
The BIOS also counts the number of parallel ports it found and stores this
count in the upper two bits of the byte at 0x411 (yes, the table can hold
up to 4 entries, but the BIOS equipment flag printer count only goes to 3).

Warning: Just before this table there are 4 words at 0x400 which contain up
to 4 entries for base addresses for serial COM ports.  At least some serial
port software is known to store more than 4 entries, thus overlapping the
parallel port table.  Hopefully this is rare!

DOS (MSDOS and IBM DOS) maps these as LPTn devices.  Unlike COMn devices and
comm ports, the name mapping varies depending on whether or not there is a
Monochrome Display and Printer Adaptor card or not.  The first entry in
the BIOS table at 0x408 becomes LPT1, the second entry LPT2, and the third
entry LPT3 (if there are that many).  The DOS device "PRN" is really
software alias for another port, by default LPT1; use the MODE command to
change this aliasing.  The following table has "typical" assignments.

Note that by swapping the entries in the BIOS table at 0x408, you can change
which physical ports are assigned to LPT1, LPT2, etc.  Several "printer
swap" programs do just that.

Typical Assignments

Addr    MDPA   no MDPA
 0x3BC  LPT1    n/a     Monochrome Display and Printer Adapter (MDPA)
 0x378  LPT2    LPT1    Primary Printer Adapter
 0x278  LPT3    LPT2    Secondary Printer Adapter

Name    MDPA    no MDPA
 LPT1   0x3BC    0x378
 LPT2   0x378    0x278
 LPT3   0x278     n/a

4. Registers addresses within the parallel printer port:

Port            R/W IOAddr      Bits    Function
----------          ------      -----   ----------------
Data Out        W   Base+0      D0-D7   8 LS TTL outputs
Status In       R   Base+1      S3-S7   5 LS TTL inputs
Control Out     W   Base+2      C0-C3   4 TTL Open Collector outputs
    "           "     "         C4      internal, IRQ enable
    "           "     "         C5      internal, Tristate data [PS/2]

Data Feedback   R   Base+0      D0-D7   matches Data Out
Control Feedbk  R   Base+2      C0-C3   matches Control Out
    "           "     "         C4      internal, IRQ enable readback

The Feedback registers are for diagnostic purposes (except in bidirectional
ports, where Data Feedback is used for data input; and the IRQ enable C4).

5. Pin signals and register bits

<= in   DB25    Cent    Name of         Reg
=> out  pin     pin     Signal          Bit     Function Notes
------  ----    ----    --------        ---     -----------------------------
=>       1       1      -Strobe         C0-     Set Low pulse >0.5 us to send
=>       2       2      Data 0          D0      Set to least significant data
=>       3       3      Data 1          D1      ...
=>       4       4      Data 2          D2      ...
=>       5       5      Data 3          D3      ...
=>       6       6      Data 4          D4      ...
=>       7       7      Data 5          D5      ...
=>       8       8      Data 6          D6      ...
=>       9       9      Data 7          D7      Set to most significant data
<=      10      10      -Ack            S6+ IRQ Low Pulse ~ 5 uS, after accept
<=      11      11      +Busy           S7-     High for Busy/Offline/Error
<=      12      12      +PaperEnd       S5+     High for out of paper
<=      13      13      +SelectIn       S4+     High for printer selected
=>      14      14      -AutoFd         C1-     Set Low to autofeed one line
<=      15      32      -Error          S3+     Low for Error/Offline/PaperEnd
=>      16      31      -Init           C2+     Set Low pulse > 50uS to init
=>      17      36      -Select         C3-     Set Low to select printer
==      18-25   19-30,  Ground
               33,17,16

Note: Some cables, ports, or connectors may not connect all grounds.
Centronics pins 19-30 and 33 are "twisted pair return" grounds, while
17 is "chassis ground" and 16 is "logic ground".

"<= In" and "=> Out" are defined from the viewpoint of the PC, not the
printer.  The IRQ line (-Ack/S6+) is positive edge triggered, but only
enabled if C4 is 1.

Here's the same data grouped for ease of reference by Control Out and Status
In registers and pins.  (Data Out is straightforward in previous table).

<= in   DB25    Cent    Name of         Reg
=> out  pin     pin     Signal          Bit     Function Notes
------  ----    ----    --------        ---     ------------------------------
=>      17      36      -Select         C3-     Set Low to select printer
=>      16      31      -Init           C2+     Set Low pulse > 50uS to init
=>      14      14      -AutoFd         C1-     Set Low to autofeed one line
=>       1       1      -Strobe         C0-     Set Low pulse > 0.5 us to send

<=      11      11      +Busy           S7-     High for Busy/Offline/Error
<=      10      10      -Ack            S6+ IRQ Low Pulse ~ 5 uS, after accept
<=      12      12      +PaperEnd       S5+     High for out of paper
<=      13      13      +SelectIn       S4+     High for printer selected
<=      15      32      -Error          S3+     Low for Error/Offline/PaperEnd

6. Electrical

See also the tutorial section below on TTL outputs.

The Data Out pins were orginally driven by a 74LS374 octal latch, which could
source 2.6 mA and sink 24 mA.  There were 0.0022uF capacitors between each
line and ground to reduce transients.  The manual warns "It is essential that
the external device not try to pull these lines to ground", as this might
cause the 74LS374 to source more current than it could handle without damage.

The Feedback input port for the Data Out register consisted of a 74LS244
*tri-state buffer*; it is uninverted. Note that this port is only for
diagnostics - if at any time the feedback *buffer* for the data port does
not match the data being output, there is an error (eg: a line stuck high or
low). Exception: bidirectional printer ports allow the 74LS374 (or equivalent)
driver chip to be tri*-*stated, which makes the data feedback port into a
legitimate unlatched input port.

The Control Out pins were driven by 7405 inverting open collector buffers,
pulled to +5 volts via 4.7K resistors.  All data lines except C2 are inverted
before going to output pins; data line C2 is double inverted before going to
pin 16 (ie: is not inverted).

The Feedback input for the Control Out register also inverted all but C2,
which was passed through uninverted.  It is possible to use some or all of
the control out port bits for input, by programming the corresponding
control out to high (remembering the inversion on C0, C1, and C3), in which
case the open collector outputs are pulled high by the 4.7K resistors; any
externally applied high will retain the high state, while an externally
applied low will pull down the electical level to low.  This can be read
via the corresponding feedback bit(s).  If either the output from the control
register, or an externally applied signal, are low, then the input will be
low.  Remember the inversions between this electrical level and the bits, tho.

The Status In register is inverted for only pin 10, register bit S7.

ESD (from Steven M. Scharf <scharf@mirage.nsc.com>)

LSI implementations of the parallel port have often had serious ESD
(electrostatic discharge; includes static electricity) problems. National
and other high-end manufacturers have added extensive anti-ESD circuitry
to the parallel port signal lines; on cheap parallel port designs on some
other SuperIO clones ESD can easily destroy the parallel port circuit
when you turn the printer on when the computer is off or the printer is
on a switchbox.

7. Timing

The original IBM Printer Adapter which came out along with the PC (floppy
disks, pre XT) was built from TTL MSI parts.  They (and their clones) were
fast enough to work with the later AT bus, now called ISA, and still do.
I've yet to hear of a TTL printer adapter which is too slow for an ISA bus.
Partly this is because it was simple and fast in bus access (unlike the
serial port 8250 chip), and partly this is because even fast 486's slow
their ISA bus down to 8-11 MHz typically.

8. How to Print to a standard printer.

This is as defined for early IBM printers, and more or less compatible with
most others that use the Centronics 36 pin interface.

 Wait for not +Busy (+Busy low)
 Set Data Out bits
     at least 0.5 uS delay
 Pulse -Strobe low for at least 0.5 uS
     hold Data Out for at least 0.5 uS after end of -Strobe pulse
 Some time later, printer will pulse -Ack low for at least 5 uS
 Printer may lower +Busy when it raises -Ack at end of pulse
 Set other Control outputs or check Status inputs as desired.

9. BIOS Printer Support

The PC ROM BIOS detects and initializes the printer ports on bootup, and
provides printer support via INT 17 (and indirectly uses this in INT 5
"Print Screen").  The detection and building of a printer port base address

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -