| [an error occurred while processing this directive] |
Kris Heidenstrom's PC Parallel Port Mini-FAQBy Kris Heidenstrom (kheidens@clear.net.nz)Release 10, 01 January 1998This is a concise Mini-FAQ with basic information on the standard and PS/2-bidirectional PC parallel ports. As of release 9 this document exists in HTML format only. Please send any comments, corrections and suggestions to kheidens@clear.net.nz. In no event shall the author be liable for any damages whatsoever for any loss relating to this document. Use it at your own risk! IntroductionA parallel port links software to the real world. To software, the parallel port is three 8-bit registers occupying three consecutive addresses in the I/O space. To hardware, the port is a female 25-pin D-sub connector, carrying twelve latched outputs from the computer, accepting five inputs into the computer, with eight ground lines (pins 18-25). Here is the pinout. The normal function of the port is to transfer data to a parallel printer through the eight data pins, using the remaining signals as flow control and miscellaneous controls and indications. A standard port does this using the Centronics parallel interface standard. The original port was implemented with TTL/LS logic. Modern
ports are implemented in an ASIC (application- The BIOS LPT Port TableA parallel port is identified by its I/O base address, and also by its LPT port number. The BIOS power-on self-test checks specific I/O addresses for the presence of a parallel port, and builds a table of I/O addresses in the low memory BIOS data area, starting at address 0040:0008 (or 0000:0408). The parallel port I/O address table contains up to three 16-bit words (four on some BIOSes). Each entry gives the I/O base address of a parallel port. The first word is the I/O base address of LPT1, the second is LPT2, etc. If less than three ports were found, the remaining entries in the table are zero. DOS, and the BIOS printer functions (accessed via int 17h), use this table to translate an LPT port number to a port address, to access the appropriate physical port. The power-on self-test checks these addresses in a specific order, and addresses are put into the table as they are found, so the table will never have gaps. A particular I/O address does not necessarily always equate to the same specific LPT port number, although there are conventions. Addressing ConventionsThe video card's parallel port is normally at 3BCh. This address is the first to be checked by the BIOS, so if a port exists there, it will become LPT1. The BIOS then checks at 378h, then at 278h. I know of no standard address for a fourth port. Direct Hardware AccessA parallel port consists of three 8-bit registers at adjacent addresses in the processor's I/O space. The registers are defined relative to the I/O base address, and are at IOBase+0, IOBase+1 and IOBase+2 (for example if IOBase is 3BCh, then the registers are at 3BCh, 3BDh and 3BEh). Always use 8-bit I/O accesses on these registers. Data RegisterThe data register is at IOBase+0. It may be read and written (using the IN and OUT instructions, or inportb() and outportb() or inp() and outp()). Writing a byte to this register causes the byte value to appear on the data signals, on pins 2 to 9 inclusive of the D-sub connector (unless the port is bidirectional and is set to input mode). The value will remain latched and stable until a different value is written to the data register. Reading this register yields the state of the data signal lines at the time of the read access. Data register: LPTBase+0, read/write, driven by software (driven by hardware in input mode)
Status RegisterStatus register: LPTBase+1, read-only, driven by hardware Control RegisterThe control register is at IOBase+2. It can be read and written. Bits 7 and 6 are unimplemented (when read, they yield undefined values, often 1,1, and when written, they are ignored). Bit 5 is also unimplemented on the standard parallel port, but is a normal read/write bit on the PS/2 port. Bit 4 is a normal read/write bit. Bits 3, 2, 1 and 0 are special - see the following section. Control register: LPTBase+2, read/write (see below), driven by software and hardware (see below)
Note: As described for the status register, signal names which start with '-' are electrically active-low. Printer Control BitsThe bottom four bits of the control register are latched and presented on the parallel port connector, much like the data register. Three of them are inverted, so writing a 1 will output a low voltage on the port pin for them. When the parallel port is used for printing in the normal way, using the Centronics standard, these four signals are used as outputs (control signals to the printer). These four outputs are open collector outputs with pullup resistors, so if they are set electrically high, an external device can force them low (only) without stressing the driver in the PC, and they can be used as inputs. To use them as inputs, write 0100 binary to the bottom four bits of the control register. This sets the outputs all high, so they are pulled high by the pullup resistors in the parallel port circuitry (which are typically 4700 ohms). An external device can then pull them low, and you can read the pin states by reading the control register. Remember to allow for the inversion on three of the pins. If you are using this technique, the control register is not strictly 'read/write', because you may not read what you write (or wrote). Interrupt Enable BitConnector pinoutThis table summarises the above information, indexed by parallel port connector pin number.
Electrical signal characteristics for the three 'direction/type' types are:
Transferring Data Via the Parallel PortThe lowest common denominator parallel port is the standard (dumb unidirectional) type. Data can be transferred between such ports via a PC-to-PC parallel cable as used with INTERLNK, Laplink and FastLynx, which links five data outputs from one end to the five status inputs on the other and vice versa (see below). Data is transferred four bits at a time using the fifth bits for handshaking. This is known as nibble mode. Another method (which will also work with all port types) links eight data bits across to five status inputs and three control lines, which are used as inputs. Other methods yielding a higher data rate can be used if both ports are bidirectional. The EPP and ECP have special hardware support for higher speeds (around 1MB/s) and the ECP also supports high-speed data transfer using DMA (direct memory addressing, a process where the hardware is able to read and write data directly to or from memory without the CPU's intervention). File Transfer Program CablesThe parallel-to-parallel cable is used by DOS's INTERLNK program. Laplink and FastLynx cables are the same. The pin-to-pin connection between two male 25-pin D-sub connectors is: 2-15, 3-13, 4-12, 5-10, 6-11, and the reverse: 15-2, 13-3, 12-4, 10-5, and 11-6, and 25-25. This requires eleven wires. If you have spare wires, link some extra grounds together. Pins 18 to 25 inclusive are grounds. A very long cable may be unreliable; limit it to 5 metres, preferably less. Transferring Data using Standard Parallel PortsThese sample functions use the cable described above and work with any parallel port. Data is sent four bits at a time, using the fifth lines in each direction as data strobe and acknowledge respectively. This is sometimes called 'nibble mode'. These sample functions send and receive a byte of data. One program must be the sender, the other must be the receiver. receive_byte() will be used only on the receiver. transmit_byte() will be used only on the sender, and will not return until the byte has been received and acknowledged by the receiver. input_value() is used on both sender and receiver. In a practical program like INTERLNK, protocols are required to control the data direction and provide error checking, etc. --------------------------- snip snip snip
--------------------------- Bidirectional Ports (PS/2 and compatible)Bidirectional ports (PS/2 and compatible) use control register bit 5 to enable input mode (input mode is enabled while this bit is set to 1). Other ports with input mode capability may enable input mode via a different signal, but I have no details. Sample Program - Display Port TypesThis program reports for LPT1, LPT2, and LPT3 whether the port exists and whether input mode can be enabled by setting the bidirectional control bit in the control register. This only works on some bidirectional ports, so the program will report non-bidirectional or in standard mode for ports that are bidirectional or enhanced, if input mode is not controlled by control register bit 5. This program was written for Borland C. Change outportb() to outp() and inportb() to inp() for Microsoft C, I think. Save this code to BIDIR.C and compile with:bcc -Iinclude_path -Llibrary_path bidir.c --------------------------- snip snip snip --------------------------- Enhanced PortsThe major types of parallel ports are:
The PS/2 bidirectional port is a standard port with input mode capability, enabled via bit 5 of the control register. The EPP (Enhanced Parallel Port) and ECP (Extended Capabilities Port) are described in the IEEE 1284 standard of 1994, which gives the physical, I/O and BIOS interfaces. Both are backward-compatible with the original parallel port, and add special modes which include bidirectional data transfer capability. These modes support fast data transfer between computers and printers, and between computers, and support multiple printers or other peripherals on the same port. In their enhanced modes, they re-define the control and status lines of the parallel port connector, using it as a slow multiplexed parallel bus. The ECP supports DMA (direct memory access) for automated high-speed data transfer. Linkshttp://www.fapo.com/ Warp 9 Engineering (commercial) home page - technical information on all port types. http://www.pcgadgets.com/upcatlog.html PC Gadgets (commercial) catalogue - parallel-port unit to drive stepper motors and monitor switches. http://www.senet.com.au/~cpeacock/ Craig Peacock's Interfacing the PC page - technical information on all port types, links to relevant material, several PC interfacing projects. End of Kris Heidenstrom's PC Parallel Port Mini-FAQ
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||