WinPort [SPP]: A Parallel Port Application

By Pete Nowalski

WinPort [SPP] is a Windows 9x application designed to demonstrate basic programming of a Standard IBM/PC parallel printer port. The program re-configures the registers of LPT1 into two 8-bit bytes, an input and output byte, and allows the user to read and write data to these bytes. With program modification, and a user designed hardware interface, the PC parallel port can be used to remotely monitor and control real world devices.

The parallel port must be set to Standard or SPP mode in bios for this program to function properly and prevent equipment damage.

Windows NT, 2000, and XP prevent user applications from accessing hardware. WinPort will fail on Windows NT, 2000 and XP. A driver or DLL would be required to access ports on these operating systems.

A Note of Caution

The PC parallel port is designed to operate at TTL voltage levels. An electrical high is +2.4 to +5 volts, and an electrical low is 0 to +0.8 volts. Output current is limited. Without specific port documentation, and using no input/output buffering, I would limit current to around 5 milliamps output low (sink) current, and -.2 milliamps source (output high) current. So, without any type of buffering, don't attempt to drive more than LED's from the port's output bits.

Disclaimer

This application was intended to operate with experimental circuits connected to the parallel port, not printers, scanners, or other conventional hardware. Exceeding the voltage and current limitations of your parallel port could damage the port or associated hardware. Until you read this help file for all recommended operating practices, don't use this program with hardware connected to the parallel port. I assume no responsibility for loss or damages incurred from use of this application.

Bytes Defined

WinPort Byte Definitions for LPT1 standard parallel port DB25 connector. (Bios configuration = Normal or SPP)

Output Byte

Bit

7

6

5

4

3

2

1

0

Pin

9

8

7

6

5

4

3

2

Input Byte

Bit

7

6

5

4

3

2

1

0

Pin

11

10

12

13

17

16

14

1

Note

Different parallel ports have their inputs hard wired high or low, and some a combination of both. It may be necessary to use an inverter; an IC7404 or equivalent, to achieve desired active high or low operation.

 

Operation

Read

WinPort's input and output bytes can be read from the port menu, or by hitting the F12 key. Port data is displayed in binary and decimal, along with the time.

Write

The output byte can be written to from the port menu, or with the F9 key. A binary or decimal value from 0-255 can be entered in the dialog box. All write operations are automatically followed by a read operation. The escape key will cancel a write, and the enter key will send a selected value to the port.

Exit

Exit from the menu or by pressing the control and 'Q' keys.

 

Hardware

It is highly advisable to electrically isolate the parallel port from whatever circuit you decide to connect to it. One way to do this would be with a couple of 74LS367 buffer chips. These are Tri-State devices with an enable pin that electrically isolates the chip from anything connected to its output. These chips can sink about 24 milliamps (output low) and source -2.6 milliamps (output high) per pin. They are relatively cheap, about 70 cents apiece from DigiKey.

Optically isolated solid state relays are another alternative. Although more expensive, they can provide 2000v - 5000v of isolation, and are ideal for power line switching.

Another consideration would be to add an ISA parallel port card to your computer. They go for about 15-20 dollars.

Precautions

Never make or break connections to the computer while it is on.

Apply power to the computer and your circuit after your connections have been made.

This application was intended to operate with experimental circuits connected to the parallel port, not printer's scanners, or other conventional hardware.

 

Theory

This is a brief overview of the PC parallel printer port, and how WinPort programs the port. This application utilizes the port in its basic configuration or Standard mode. Bio-directional, EPP and ECP modes are not covered. Parallel ports integrated on the motherboard usually allow the modes to be changed in BIOS, otherwise a card may require a jumper change.

Definition

The parallel port is defined by its by its LPT port number, and its I/O base address. LPT1 = base address 0x378 = parallel port #1

Composition

The port consists of three 8-bit registers at adjacent addresses.

Data register = base address + 0

Status register = base address + 1

Control register = base address + 2

Data register

Bit

7

6

5

4

3

2

1

0

Pin

9

8

7

6

5

4

3

2

In the port's standard mode, the data register is an output byte and can be written to. WinPort uses the data register as its output byte. Here is a C code snippet used to write the register with the value 255:

#Define BASEPORT 0x378

int DATA, STATUS, CONTROL;

DATA = _outp((BASEPORT), 255);

 

Some compilers/languages may use a different variation of the _outp command.

 

Status register

Bit

7

6

5

4

3

2

1

0

Pin

11

10

12

13

15

NC

NC

NC

The status register is an input, or read only register. A read returns the state of the five pins connected to the DB25 connector. Bit 7 is inverted. A 1 or electrical high on pin 11 will return as a 0 when read. Bits 2-0 are undefined, and have no connection. A read of the status register may return 111 for bits 2-0, which should be ignored. To read the status register:

STATUS = _inp(BASEPORT + 1);

 

Control register

Bit

7

6

5

4

3

2

1

0

Pin

NC

NC

NC

NC

17

16

14

1

On a Standard parallel port the control register can be used as an input or output register, and can be read or written to.

A read returns the state of the four pins connected to the DB25 connector. Bits 3, 1, and 0 are inverted. So a 1 or electrical high on these pins will return zeros when read, and a 0 on these pins will read as ones. Bits 7-4 are undefined, and have no connection. A read of the status register may return 1111 for bits 7-4, which should be ignored.

Bits 3-0 are open collector outputs with pull-up resistors. They are used as inputs by writing them high, and letting an external device pull them low. So accounting for the inverted bits, writing 0100 will set bits 3-0 high. To read the status register:

_outp((BASEPORT +2), 4); /* write control bit high */

CONTROL = _inp(BASEPORT+ 2); /* read control bits */

Warning

Only parallel ports that can be configured as Standard will allow the control register to be used as an input. Use caution to prevent equipment damage.

 

WinPort's input byte

Bit

7

6

5

4

3

2

1

0

Pin

11

10

12

13

17

16

14

1

WinPort uses the status and control registers to form its input byte. Bits 7-4 of the status register are used as the high nibble, and bits 3-0 of the control register as the low nibble.

We read the status register, then logically AND the result with 240 to remove the undefined bits and bit3, pin15.

Then read the control register, logically AND the result with 15 to remove the undefined bits.

Logically OR them together to form an eight bit byte.

Do an EXCLUSIVE OR on the byte with 139 to reverse the value of the inverted bits.

The code could look like this:

int High_Nibble, Low_Nibble, Input_Byte;

High_Nibble = _inp(BASEPORT + 1)& 240;

Low_Nibble = _inp(BASEPORT + 2) & 15;

Input_Byte = (High_Nibble | Low_Nibble) ^ 139;

 

The Xbit

Winport's Xbit is Pin 15 or bit 3 of the control register. The X is for extra, as it was not used in formation of the input byte. A one is displayed when the bit is high, zero when low.

 

Conclusion

So that wraps it up. This program was written in C using the free lcc-Win32 compiler downloaded from http://www.cs.virginia.edu/~lcc-win32/

 

 

Home

1