Using the Parallel Port as an Input/Output Channel
Primary Software: LabWindows/CVI Development Systems>>LabWindows/CVI Full Development System
Primary Software Version: 15.1
Primary Software Fixed Version: N/A
Secondary Software: N/A
How can I use a parallel printer port as an input or output channel?
There are 3 locations in the I/O port address space at which printer cards can be configured: 278, 378, and 3BC. (The 3BC address was previously used with now obsolete combination monochrome display/printer cards.) Often the 278 and 378 ports are marked LPT1 and LPT2, which turns out not to be completely accurate in all cases. Typical BASE ADDRESSES are:
LPT1 0x378 (378h)
LPT2 0x278 (278h)
When configuring your system during a startup routine, DOS scans downward through the 3 locations, starting at 3BC, to determine if those addresses are occupied in your system. The first occupied port is then named LPT1, and so on. Each time it makes an assignment, it stores the I/O port address in a table which starts at memory address 408 (hex), occupying 2 bytes per LPT number and ordered by LPT number. When the operating system writes to a particular printer, the data is indexed into the table, the correct I/O port address is determined, and the data is passed to that port.
If you are developing an application for general use, then the best application architecture will include determining what is located at which of these addresses. (When developing a custom setup for your own purposes, it may be sufficient to hard code the port address.
To write to the printer port, simply output the appropriate data to the appropriate port address. If writing to an actual printer, it will generally be necessary to strobe that value. Also, your application may need some indication that the data on the pins is valid. This is done this by changing bit 0 of the control register to zero and then bringing it back to 1. (Bit 0 of the control register is located at Base Address + 2.). Don't tamper with the other bits in this register. Dropping this bit in the control register asserts the Strobe signal on pin 1 of the connector. Most printers require that the strobe last for at least 0.5 microseconds.
In LabWindows CVI 4.0.1 you can use a " data = inp(address); " function call to read one of the registers and you can use an " outp(address, bytevalue); " function to write to one of the registers. Where bytevalue is a value between 0 and 255 that sets the desired bit pattern.
The following information defines common base addresses for port registers. Note that the register bits are listed as well as the corresponding DB25 connector pin that that bit is connected to. All the lines listed as Outputs are open collector type on most newer computers, which means that with care they can be used as inputs.
KnowledgeBase 0XLBTD2Q: What Does EPP/ECP Mode Mean with Respect to Parallel Ports?
Report Date: 01/22/1997
Last Updated: 11/10/2016
Document ID: 0TL70ATL