Parallel port
The parallel port uses a sub-d 25 connector to provide a 8-bit data bus. It is commonly used by printers. There are 3 kinds of parallel ports: Standard Parallel Port (SPP), Enhanced Parallel Port (EPP) and Extended Capabilities Parallel Port (ECP). iirc they are all part of IEEE Standard 1284, or is it just the second two?
Pin types
Most parallel ports come in either 36 or 25 pin varieties. 25 being the most common.
Registers & Common Address
Common base addresses are:
- LPT1: 0x378 (or occasionally 0x3BC) (IRQ 7)
- LPT2: 0x278 (IRQ 6)
- LPT3: 0x3BC (IRQ 5)
Parallel Port Software Interface
Each parallel port has three IO port registers, Data, Status and Control. Their addresses are relative to the base address of the parallel port in question.
Data Register
Address = Base Address + 0
Any byte writen to this register is put on pins 2 through 9 of the port. Any read from this register reflects the state of the port.
Status Register
Address = Base Address + 1
Bit 0 | Bit 1 | Bit 2 | Bit 3 | Bit 4 | Bit 5 | Bit 6 | Bit 7 |
Reserved | Reserved | IRQ | ERROR | SELECT_IN | PAPER_OUT | ACK | BUSY |
The ERROR, ACK and BUSY signals are active low when reading from the IO port.
Control Register
Address = Base Address + 2
Bit 0 | Bit 1 | Bit 2 | Bit 3 | Bit 4 | Bit 5 | Bit 6 | Bit 7 |
STROBE | AUTO_LF | INITIALISE | SELECT | IRQACK | BIDI | Unused | Unused |
The STROBE and INITIALISE signals are active low when writing to the IO port.
The STROBE signal is for handshaking and alerts the printer to data being ready at the data port.
AUTO_LF is the Automatic Line-Feed signal. If this is set and the printer receives a Carriage-Return character (0x0D), the printer will automatically perform a Line-Feed (character 0x0A) as well.
INITIALISE, sometimes called PRIME, alerts the device that data that a data conversation is about to start. This signal may result in a printer performing a reset and any buffers being flushed.
Standard Parallel Port Mode
This is the most basic of the parallel modes. The other modes are EPP and ECP. All systems should support this mode and it may well be the default at boot time. Some BIOSes also support setting the default mode of the parallel port. In this mode, the Data register and the Control register are Write-Only and the Status register is Read-Only.
In Standard (or Compatibility) mode, data is sent to the connected device by writing the byte to the data port, then pulsing the STROBE signal. This pulse informs the device that data is ready to be read. The device will usually respond by raising its BUSY signal, reading the data and perform some processing on it. Once this processing is complete, the device will lower the Busy signal and may raise an ACK signal to indicate that it has finished. This mechanism is called Centronics Handshaking.
This method of loading the data and then pulsing the strobe through software causes a slowdown to the maximum data throughput of the port. This means that a standard mode has a maximum transfer rate of around 1000 bytes per second, depending on the timings of the computer and receiving device. The more advanced types (or modes) of parallel ports, EPP and ECP, reduce this by providing hardware-based handshaking. Relieving software of this requirement reduces CPU load and increases the port's maximum potential speed.
For a line printer, this method should be enough to get things going, simply sending characters using this method to the parallel port while the printer is online should get the print head moving, assuming no buffers are in the way to store the values.
Depending on the connected device, you may have to raise the INITIALISE signal before data transmission to ready the device, and possibly again after in order to flush any buffers.