Academic Company Events Community Support Solutions Products & Services Contact NI MyNI
280 ratings:
 3.37 out of 5   

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.

          BASE ADDRESS
(PDR) Data register (Read or Write)

Bit 0 Pin 2 Data Output
Bit 1 Pin 3 Data Output
Bit 2 Pin 4 Data Output
Bit 3 Pin 5 Data Output
Bit 4 Pin 6 Data Output
Bit 5 Pin 7 Data Output
Bit 6 Pin 8 Data Output
Bit 7 Pin 9 Data Output

(PSR) Status register (Read Only)

Bit 0 Not used
Bit 1 Not used
Bit 2 Not used
Bit 3 Pin 15 ERROR Input
Bit 4 Pin 13 SELECT Input
Bit 5 Pin 12 PAPER END Input
Bit 6 Pin 10 ACKNOWLEDGE Input
Bit 7 Pin 11 BUSY Input

(PCR) Control register (Read or Write)

Bit 0 Pin 1 DATA STROBE Output
Bit 1 Pin 14 AUTO LINE FEED Output
Bit 3 Pin 17 SELECT INPUT Output
Bit 4 0 = disable interrupt, 1 = enable interrupt
Bit 5
Bit 6
Bit 7

Related Links:
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

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
  1 2 3 4 5
Please Contact NI for all product and support inquiries.submit