My ChipCenter Knowledge Center Guides & Experts Product Reviews Ask Us Online Tools Circuit Cellar Resources Webcasts Careers


Data Sheets App Notes Ask Us
Search Type:
Search for:






Email this Article   |  Printer Friendly Page

Parallel Port Interfacing

Interfacing to the parallel port is quick easy and can provide a quick way to transfer a lot of data to and from your peripheral. Parallel transmission gives you a definite speed advantage over serial communication and usually requires less overhead (sync bits, error checking, parity, etc.).

However, there are some disadvantages. Parallel communication on the PC wasn't designed for long distance communication and is usually limited to 30 ft. or less. Your peripheral will also need to dedicate more pins to communication than with serial devices.

The parallel port was originally designed to be an output only port since printers in the beginning of the computer world were input only type of devices. Today in the world of scanners, Zip Drives, external floppy drives, and smarter printers the parallel port has become bi-directional. Direction control of your parallel port requires two steps. First you need to make sure that your BIOS settings in CMOS allow the bi-directional communication. Then you set/clear bit 5 of the port's control byte. A logic '1' is input mode and a logic '0' is output mode. A word of warning, Don't use your parallel port as an input port before making absolutely sure that it is bi-directional and is in input mode. You can easily burn out the output latches on your parallel port and be stuck with an input only port. If you are worried about your parallel port's input capability, mail me and I will help you with your situation. A cheaper and safer solution is to buy a parallel port card for a few dollars and use it rather than risk damaging the super I/O chip on your motherboard. If your port isn't bi-directional, you can still use the status inputs as inputs.

First things first. You need to find out the address to your parallel port. The address of your parallel port is stored in memory. You can easily find out what that number is by typing the following at a command prompt.

C:> debug
At the prompt "-" type - d 0000:0408 L 4
The computer will print out the contents of the specified memory location.
You will get a response similar to the following:
0000:040078 03 78 02

These are the addresses of LPT1 (378H) and LPT2 (278H). You need that information to write your program to talk to the parallel port. For the rest of the document, we'll assume that the parallel port address is 378H.

There are three bytes for communication with the parallel port; the data byte, the status byte, and the control byte. The data byte is the same as the address returned (378H in our examples). The status byte is the next at the next address (379H). The control byte is two bytes away from the data byte (37AH).

You can use C, C++, Basic, or Assembly to talk to the parallel port. I will talk briefly on how to do this in Assembly and reserve more detail for later articles. If you are looking for information programming in C and such, look in help under the following instructions.

_outp, _outpw, _outpd, _inp, _inpw, inpd, VbInp, VbOut, inb, outb

In assembly, you can use the IN and OUT commands to talk to ports. The IN and OUT commands can only be used in conjunction with the accumulator or AX register. Simply put the address of the port into another register (e.g. DX) and then send or receive from the port.
MOV DX,378H
IN AL, DX
OUT DX, AL
;Get the port address
;Read a byte from the port into AL
;Send AL to the port

Experiment with this a little bit. You can download MASM free of charge here.

A good link: Parallel Port Interfacing.

Embedded Engineering

Guides and Experts   Analog Avenue   PLD EDA Tools   PLD   DSP   EDA   Embedded Systems   Power   Test


Email this Article   |  Printer Friendly Page

Copyright ©2001 eChips
About ChipCenter  Contact Us  Privacy Statement   Advertising Information