The EE Compendium - The Home of Electronic Engineering and Embedded Systems Programming

The Home of Electronic Engineering and Embedded Systems Programming

Intel 8051
Microchip PIC
Motorola 6805
Motorola 68HC11
Motorola 68HC12
Rabbit 2000
More Micros...
LCD Project
MP3 Projects
PC Parallel Port
MAX7219
More Projects...
Project Kits
Software
Code Cache
Compilers
Hardware
CAD / CAE
Components
Distributors
Simulation
Test Equipment
Hotsheet  NEW! 
Articles
Books
Career
Consultants
Forums
Free Stuff
Fun Stuff
Magazines
Portals
Project Management 
Product Reviews
Robotics
Misc. Links
The standard PC printer port is handy for testing and controlling devices. It provides an easy way to implement a small amount of digital I/O. I like to use to during initial development of a product -- before the "real" hardware is ready, I can dummy up a circuit using the printer port, and thus get started testing my software.

This source code module provides the low-level control of the port, implementing code to control 12 outputs and read 5 inputs.

This code was written for Borland C/C++ v3.1, but you should be able to adapt it for other compilers. You can view the source code online, or download an archive (prn_io.zip) that contains PRN_IO.C and PRN_IO.H. To use the module in your program, simply #include PRN_IO.H from wherever you need to call the functions, and compile and link PRN_IO.C into your program.

  ViewView The Source Code
  DownloadDownload The Source Code

The following tables list the details of how the software interfaces to hardware port. Refer to the source code itself for more information, or check out one of the links at the end of this page.

Printer Port Addresses
Printer Port Base Address
LPT1 0x0378 or 0x03BC
LPT2 0x0278 or 0x0378
LPT3 0x0278

Printer Port Registers
Register Name Address
Data Register Base + 0x00
Status Register Base + 0x01
Control Register Base + 0x02

Data Register Bit Definitions
Bit Function Low High
7 (MSB) D7 0 1
6 D6 0 1
5 D5 0 1
4 D4 0 1
3 D3 0 1
2 D2 0 1
1 D1 0 1
0 (LSB) D0 0 1

Status Register Bit Definitions
Bit Function Low High
7 (MSB) Busy Busy Not Busy
6 Acknowledge Nack Ack
5 Paper Status No Paper Paper
4 Selection Status Not Selected Selected
3 Error Status No Error Error
2 Not Used - -
1 Not Used - -
0 (LSB) Not Used - -

Control Register Bit Definitions
Bit Function Low High
7 (MSB) Not Used - -
6 Not Used - -
5 Not Used - -
4 Interrupt Control Interrupts Disabled Interrupts Enabled
3 Select Selected Not Selected
2 Initialize False True
1 Auto Feed True False
0 (LSB) Strobe (Active-Low) True False

Source Code Implementation Notes:

  • The code is written to use LPT1 at 0x0378; change it if you need to
  • The code doesn't attempt to use interrupts
  • The parallel port is also capable of enhanced modes (see the links below), but this code doesn't attempt to use them
  • This code assumes that the port is configured as a "standard" or "normal" port; configuring the port for EPP or ECP modes may or may not work

Parallel Port Books: Parallel Port Specs And Info: Parallel Port Drivers:

 
Home About This Site Add URL Contact Us Privacy Link To Us Search What's New?

—   T H E   E E   C O M P E N D I U M   —
Copyright © 2008 by EE Compendium, Last Update: Wednesday, 09/06/06