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

Table of Contents

Hardware Properties / Pinout
Port Addresses
Software Registers - Standard Parallel Port (SPP)

WARNING!!!

BE CAREFULL WITH YOUR PARALLEL PORT ITS FRAGILE
DO NOT USE (PLAY \ EXPERIMENT WITH) YOUR ON MOTHERBOARD PARALLEL PORT
USE A CHEAP IO CARD PLUG IN PARALLEL PORT
IF SOMETHING GOES WRONG ITS ONLY 10 U$D
YOUR MOTHERBOARD IS MORE EXPENSIVE SMOKE
 
 

     
Hardware Properties
    Below is a table of the "Pin Outs" of 
    the D-Type 25 Pin connector 
    and the Centronics 36 Pin connector. 

    The D-Type 25 pin connector is the most common connector found on the Parallel Port of the computer, 
    while the Centronics 36 Pins Connector is commonly found on printers. 
     
     

    Pin No (D-Type 25)
    Pin No (Centronics)
    SPP Signal
    Direction In/out
    Register
    Hardware Inverted
    1
    1
    nStrobe
    In/Out
    Control
    Yes
    2
    2
    Data 0
    Out
    Data
     
    3
    3
    Data 1
    Out
    Data
     
    4
    4
    Data 2
    Out
    Data
     
    5
    5
    Data 3
    Out
    Data
     
    6
    6
    Data 4
    Out
    Data
     
    7
    7
    Data 5
    Out
    Data
     
    8
    8
    Data 6
    Out
    Data
     
    9
    9
    Data 7
    Out
    Data
     
    10
    10
    nAck
    In
    Status
     
    11
    11
    Busy
    In
    Status
    Yes
    12
    12
    Paper-Out / Paper-End
    In
    Status
     
    13
    13
    Select
    In
    Status
     
    14
    14
    nAuto-Linefeed
    In/Out
    Control
    Yes
    15
    32
    nError / nFault
    In
    Status
     
    16
    31
    nInitialize
    In/Out
    Control
     
    17
    36
    nSelect-Printer / nSelect-In
    In/Out
    Control
    Yes
    18 - 25
    19-30
    Ground
    Gnd
     
     
    Table 1. Pin Assignments of the D-Type 25 pin Parallel Port Connector.

    The above table uses "n" in front of the signal name to denote that the signal is active low. e.g. nError. If the printer has occurred an error then this line is low. This line normally is high, should the printer be functioning correctly. The "Hardware Inverted" means the signal is inverted by the Parallel card's hardware. Such an example is the Busy line. If +5v (Logic 1) was applied to this pin and the status register read, it would return back a 0 in Bit 7 of the Status Register.

    The output of the Parallel Port is normally TTL logic levels. The voltage levels are the easy part. The current you can sink and source varies from port to port. Most Parallel Ports implemented in ASIC, can sink and source around 12mA. However these are just some of the figures taken from Data sheets, Sink/Source 6mA, Source 12mA/Sink 20mA, Sink 16mA/Source 4mA, Sink/Source 12mA. As you can see they vary quite a bit. The best bet is to use a buffer, so the least current is drawn from the Parallel Port.

     
Port Addresses
    The Parallel Port has three commonly used base addresses. These are listed in table 2, below. The 3BCh base address was originally introduced used for Parallel Ports on early Video Cards. This address then disappeared for a while, when Parallel Ports were later removed from Video Cards. They has now reappeared as an option for Parallel Ports integrated onto motherboards, upon which their configuration can be changed using BIOS.

    LPT1 is normally assigned base address 378h, while LPT2 is assigned 278h. However this may not always be the case as explained later. 378h & 278h have always been commonly used for Parallel Ports. The lower case h denotes that it is in hexadecimal. These addresses may change from machine to machine.

    Address
    Notes:
    3BCh - 3BFh
    Used for Parallel Ports which were incorporated on to Video Cards - Doesn't support ECP addresses
    378h - 37Fh
    Usual Address For LPT 1
    278h - 27Fh
    Usual Address For LPT 2
    Table 2 Port Addresses

    When the computer is first turned on, BIOS (Basic Input/Output System) will determine the number of ports you have and assign device labels LPT1, LPT2 & LPT3 to them. BIOS first looks at address 3BCh. If a Parallel Port is found here, it is assigned as LPT1, then it searches at location 378h. If a Parallel card is found there, it is assigned the next free device label. This would be LPT1 if a card wasn't found at 3BCh or LPT2 if a card was found at 3BCh. The last port of call, is 278h and follows the same procedure than the other two ports. Therefore it is possible to have a LPT2 which is at 378h and not at the expected address 278h.

    What can make this even confusing, is that some manufacturers of Parallel Port Cards, have jumpers which allow you to set your Port to LPT1, LPT2, LPT3. Now what address is LPT1? - On the majority of cards LPT1 is 378h, and LPT2, 278h, but some will use 3BCh as LPT1, 378h as LPT1 and 278h as LPT2. Life wasn't meant to be easy.

    The assigned devices LPT1, LPT2 & LPT3 should not be a worry to people wishing to interface devices to their PC's. Most of the time the base address is used to interface the port rather than LPT1 etc. However should you want to find the address of LPT1 or any of the Line PrinTer Devices, you can use a lookup table provided by BIOS. When BIOS assigns addresses to your printer devices, it stores the address at specific locations in memory, so we can find them.
     

    Start Address
    Function
    0000:0408
    LPT1's Base Address
    0000:040A
    LPT2's Base Address
    0000:040C
    LPT3's Base Address
    0000:040E
    LPT4's Base Address (Note 1)
    Table 3 - LPT Addresses in the BIOS Data Area;

    Note 1 : Address 0000:040E in the BIOS Data Area may be used as the Extended Bios Data Area in PS/2 and newer Bioses.

    The above table, table 3, shows the address at which we can find the Printer Port's addresses in the BIOS Data Area. Each address will take up 2 bytes. The following sample program in C, shows how you can read these locations to obtain the addresses of your printer ports.

      #include <stdio.h>
      #include <dos.h>
      
      void main(void)
      {
       unsigned int far *ptraddr;  /* Pointer to location of Port Addresses */
       unsigned int address;       /* Address of Port */
       int a;
      
       ptraddr=(unsigned int far *)0x00000408;
      
       for (a = 0; a < 3; a++)
         {
          address = *ptraddr;
          if (address == 0)
                      printf("No port found for LPT%d \n",a+1);
          else
                      printf("Address assigned to LPT%d is %Xh\n",a+1,address);
          *ptraddr++;
         }
      }
Software Registers - Standard Parallel Port (SPP)
     
    Offset
    Name
    Read/Write
    Bit No.
    Properties
    Base + 0
    Data Port
    Write (Note-1)
    Bit 7
    Data 7
    Bit 6
    Data 6
    Bit 5
    Data 5
    Bit 4
    Data 4
    Bit 3
    Data 3
    Bit 2
    Data 2
    Bit 1
    Data 1
    Bit 0
    Data 0
    Table 4 Data Port

    Note 1 : If the Port is Bi-Directional then Read and Write Operations can be performed on the Data Register.

    The base address, usually called the Data Port or Data Register is simply used for outputting data on the Parallel Port's data lines (Pins 2-9). This register is normally a write only port. If you read from the port, you should get the last byte sent. However if your port is bi-directional, you can receive data on this address. See Bi-directional Ports for more detail.
     

    Offset
    Name
    Read/Write
    Bit No.
    Properties
    Base + 1
    Status Port
    Read Only
    Bit 7
    Busy
    Bit 6
    Ack
    Bit 5
    Paper Out
    Bit 4
    Select In
    Bit 3
    Error
    Bit 2
    IRQ (Not)
    Bit 1
    Reserved
    Bit 0
    Reserved
    Table 5 Status Port

    The Status Port (base address + 1) is a read only port. Any data written to this port will be ignored. The Status Port is made up of 5 input lines (Pins 10,11,12,13 & 15), a IRQ status register and two reserved bits. Please note that Bit 7 (Busy) is a active low input. E.g. If bit 7 happens to show a logic 0, this means that there is +5v at pin 11. Likewise with Bit 2. (nIRQ) If this bit shows a '1' then an interrupt has not occurred.
     

    Offset
    Name
    Read/Write
    Bit No.
    Properties
    Base + 2
    Control Port
    Read/Write
    Bit 7
    Unused
    Bit 6
    Unused
    Bit 5
    Enable Bi-Directional Port
    Bit 4
    Enable IRQ Via Ack Line
    Bit 3
    Select Printer
    Bit 2
    Initialize Printer (Reset)
    Bit 1
    Auto Linefeed
    Bit 0
    Strobe
    Table 6 Control Port

    The Control Port (base address + 2) was intended as a write only port. When a printer is attached to the Parallel Port, four "controls" are used. These are Strobe, Auto Linefeed, Initialize and Select Printer, all of which are inverted except Initialize.

    The printer would not send a signal to initialize the computer, nor would it tell the computer to use auto linefeed. However these four outputs can also be used for inputs. If the computer has placed a pin high (e.g. +5v) and your device wanted to take it low, you would effectively short out the port, causing a conflict on that pin. Therefore these lines are "open collector" outputs (or open drain for CMOS devices). This means that it has two states. A low state (0v) and a high impedance state (open circuit).

    Normally the Printer Card will have internal pull-up resistors, but as you would expect, not all will. Some may just have open collector outputs, while others may even have normal totem pole outputs. In order to make your device work correctly on as many Printer Ports as possible, you can use an external resistor as well. Should you already have an internal resistor, then it will act in Parallel with it, or if you have Totem pole outputs, the resistor will act as a load.

    An external 4.7k resistor can be used to pull the pin high. I wouldn't use anything lower, just in case you do have an internal pull up resistor, as the external resistor would act in parallel giving effectively, a lower value pull up resistor. When in high impedance state the pin on the Parallel Port is high (+5v). When in this state, your external device can pull the pin low and have the control port change read a different value. This way the 4 pins of the Control Port can be used for bi-directional data transfer. However the Control Port must be set to xxxx0100 to be able to read data, that is all pins to be +5v at the port so that you can pull it down to GND (logic 0).

    Bits 4 & 5 are internal controls. Bit four will enable the IRQ (See Using the Parallel Ports IRQ) and Bit 5 will enable the bi-directional port meaning that you can input 8 bits using (DATA0-7). This mode is only possible if your card supports it. Bits 6 & 7 are reserved. Any writes to these two bits will be ignored.Bit 5 of the Control Port enables or disables the bi-directional function of the Parallel Port. This is only available on true bi-directional ports. When this bit is set to one, pins 2 to 9 go into high impedance state. Once in this state you can enter data on these lines and retrieve it from the Data Port (base address). Any data which is written to the data port will be stored but will not be available at the data pins. To turn off bi-directional mode, set bit 5 of the Control Port to '0'.

     
    However not all ports behave in the same way. Other ports may require setting bit 6 of the Control Port to enable Bi-directional mode and setting of Bit 5 to dis-enable Bi-directional mode, Different manufacturers implement their bi-directional ports in different ways. If you wish to use your Bi-directional port to input data, test it with a logic probe or multimeter first to make sure it is in bi-directional mode.

    WARNING!!!

    BE CAREFULL WITH YOUR PARALLEL PORT ITS FRAGILE
    DO NOT USE (PLAY \ EXPERIMENT WITH) YOUR ON MOTHERBOARD PARALLEL PORT
    USE A CHEAP IO CARD PLUG IN PARALLEL PORT
    IF SOMETHING GOES WRONG ITS ONLY 10 U$D
    YOUR MOTHERBOARD IS MORE EXPENSIVE SMOKE

Copyright 1999-2001 Craig Peacock 19th August 2001.
http://www.beyondlogic.org/spp/parallel.htm