EDN logo


Design Ideas: July 4, 1996

Connector adds plug-and-play capability

Patrick Gueulle,
Le Havre Cedex, France

Centronics parallel ports are now widely used to connect everything but printers to PCs. In most cases, the user must configure the application software for the right port (LPT1: or LPT2:). However, designing in automatic port recognition is a simple matter. The connection of an output line to any spare input pin of the DB25 connector is all that is necessary on the hardware side (Figure 1.)

Listing 1—Plug-and-play centronics connector
10 DEF SEG=0:KEY OFF:CLS
20 S1=PEEK(&H408)+256*PEEK(&H409):E1=S1+1 'read LPT1: address
30 S2=PEEK(&H40A)+256*PEEK(&H40B):E2=S2+1 'read LPT2: address
40 OUT S2,0 'LPT2: test
50 IF (INP(E2) AND 64) <> 0 THEN 90
60 OUT S2,128
70 IF (INP(E2) AND 64) <> 64 THEN 90
80 GOTO 150 'device detected on LPT2:
90 OUT S1,0 'LPT1: test
100 IF (INP(E1) AND 64) <> 0 THEN 140
110 OUT S1,128
120 IF (INP(E1) AND 64) <> 64 THEN 140
130 GOTO 160 'device detected on LPT1:
140 PRINT"device not detected":GOTO 180
150 S=S2:PRINT"device connected to LPT2:":GOTO 170
160 S=S1:PRINT"device connected to LPT1:":GOTO 170
170 PRINT"base address =";S;"(decimal)
180 REM (c)1996 Patrick GUEULLE
A few lines of software can easily send a signal to every available parallel port and particular data line (D7, in this example) and then determine whether or not the signal reaches the expected status line (ACK, in this case). Listing 1's short GWBASIC listing reads the base addresses of LPT1: and LPT2: from the BIOS area to cope with possible variations between true PC compatibles and certain clones. You can test additional parallel ports in the same way, and you can also simply rewrite the program in C, Pascal, or even assembly language.

At least two input lines (ACK and BUSY) and any D0 through D7 output pin lend themselves quite well to this application. Therefore, this method makes it possible not only to detect the particular parallel port on which the device connects, but also to identify any one of several devices, each of which is coded by a unique position of the strap. In the Listing, only the decimal values of 128 (for D7) and 64 (for ACK) need to be adapted, because they act like "masks" for the corresponding input and output lines.

Note that this arrangement does not prevent the device from making normal use of the data line involved in the process. Full bytes can still transmit via D0 through D7 of the parallel port by means of direct OUT instructions. Only the ACK line is no longer available, preventing the device from using the true Centronics handshaking protocol. If this restriction causes trouble, you might prefer to use another status line, such as PE (paper end). (DI #1888)


| EDN Access | feedback | subscribe to EDN! |
| design features | out in front | design ideas | columnist | departments | products |


Copyright © 1996 EDN Magazine. EDN is a registered trademark of Reed Properties Inc, used under license.