Ads

Get STM32 tutorial using HAL at $10 for a limited time!

Monday, November 30, 2015

Interfacing with Parallel Port and C++ Part 1

Parallel port is one of the interface that can be found on a PC, especially on old PCs. This port is used for sending information to the printer and also known as printer port. The physical connector of parallel port is consist of 25 pins and also known as DB25 connector.


These pins can be divide to four groups:

  1. Output pins (2 - 9): Output pins is used for transmit data (8-bits) from PC to printer in parallel format (each pin is used to transmit one bit of data at a time). 
  2. Input pins (10, 11, 12, 13, 15): Input pins is used to read indicator status that received from printer.
  3. Input/Output (Bidirectional) pins (1, 14, 16, 17): These lines was used for control the flow of data.
  4. GND pins (18 - 25).
We can read or write data from or to these I/O pins by accessing their I/O address. There are three sequential I/O address space that corresponding to the parallel port pins: 0x378 (output pins), 0x379 (input pins), 0x37A (input/output pins).


The 0x378 address can be defined as BASE address of parallel port I/O address. The two other addresses is defined by BASE+1 (0x379) and BASE+2 (0x37A). Writing to BASE address will output 8 bits of data to parallel port output pins. The BASE+1 address is read only. It is used for read data that come from printer/other external device. The BASE+2 address is input/output address, so we can read or write data from or to this address.

The picture below show the mapping between parallel port pins and each bit location in the I/O address space.


Some data bits used by BASE+1 and BASE+2 addresses are inverted by the parallel port circuitry. These inverted bits are marked by a "/" character preceding the letter "D" of that bit. If a program needs to send or receive data to or from these inverted bits, it needs to invert that data bit in software beforehand. This double inversion (once in hardware and again in software) has the effect of correcting the signal back to the intended state.

For summary, parallel port use three I/O addresses for transfer data through port's interface. Each address control one byte of data, however, for two I/O address, several data bits are unused and and few other bits are inverted internally by port circuity. The first I/O address is used to output data only, the second address is used to input data only, and the last address can be used to both input and output data.

Referenced from:
- Interfacing with C++ Programming Real-World Applications by Jayantha Katupitiya and Kim Bentley.

No comments :

Post a Comment