Many Stamp users use the PAK-IV to increase their Stamp I/O. Why not use the PAK with a PC parallel port to expand the I/O possibilities there as well?
Of course, the PAK-IV, like many PAKs, uses a Stamp-friendly protocol that works with SHIFTIN and SHIFTOUT. How can you do that on the PC? It turns out to be easy.
First, if you want to experiment with the PC printer port, get a copy of Jan Axleson's excellent Parallel Port Complete. This is a book I wish I had written -- if you need to know about the printer port, this is the book.
I took a universal PC board from Radio Shack and glued a male DB25 connector to it. The copper Radio Shack logo looked like it might short out some pins, so I burned it off with a soldering iron (hey, its fun to burn traces off a PC board on purpose).
Next, I installed a PAK-IV and its resonator on the board, wired up just like the manual shows with two exceptions. First, there are two resonators in the picture but the one near the top is not actually connected. You only need one resonator! Second, I did not connect pins 4 and 5 of the PAK-IV (SIN and SOUT). The Stamp makes it easy to connect these together, but for the printer port it is easiest to leave them separate. I put a pullup resistor on both pins which is why the PAK schematic shows 2 resistors and the picture has 3. The pin header at the bottom connects the board's busses to +5V and ground.
There are 5 wires connected to the DB25 (2 on the top and 3 on the bottom). Here's the connections:
DB25 pin | PAK-Pin |
1 (strobe) | 4 (SIN) |
2 (D0) | 2 (ENABLE) |
14 (AutoLF) | 6 (CLK) |
15 (nError) | 5 (SOUT) |
25 (Ground) | 8 (VSS) |
I used D0 for enable so that you could actually wire up 8 PAK-IVs to the same port. That would be 128 I/O pins!
All that is left is to write some software to drive it. There are plenty of ways to toggle the bits on and off (check out Jan's book or Web site). I used QuickBasic just to test things out. I'll try to add some VB code later, but the logic is simple enough.
You'll need to set the baseport variable to match your printer port. In addition, tdlay may need some tweaking depending on how fast your machine is. The main code simply toggles an LED on pin 0 of the PAK-IV. Of course, you can use any of the PAK command -- PWM, RCTime, PULSIN, PULSOUT, etc. Almost like having a Stamp available from your PC programs.
DECLARE SUB pakwait () DECLARE SUB delay (n AS INTEGER) DECLARE SUB shiftoutput (b AS INTEGER) DECLARE FUNCTION shiftinput% () DIM SHARED baseport AS INTEGER DIM SHARED tdlay AS INTEGER CLS tdlay = 1 baseport = &H278 ' set for your printer port ' set clock/data low OUT baseport + 2, &HFF OUT baseport, 0 ' enable off ' pulse clock for reset OUT baseport + 2, 0 delay tdlay OUT baseport + 2, 3 PRINT "Press a key to begin" WHILE INKEY$ = "": WEND PRINT "OK" ' turn on enable OUT baseport, 1 delay tdlay * 10 ' wait a bit ' read PAK ID shiftoutput (&HB6) pakwait PRINT HEX$((shiftinput)) agn: shiftoutput (&H41) ' toggle output pakwait x = shiftinput 'wait 1 second x = TIMER + 1 WHILE TIMER <= x: WEND GOTO agn ' Delay SUB delay (n AS INTEGER) WHILE n <> 0: n = n - 1: WEND END SUB ' Wait for PAK to finish SUB pakwait pwait: IF (INP(baseport + 1) AND 8) = 8 THEN GOTO pwait END SUB ' Read a byte FUNCTION shiftinput% DIM inb AS INTEGER DIM b7 AS INTEGER inb = 0 FOR b7 = 0 TO 7 inb = inb * 2 IF (INP(baseport + 1) AND 8) = 8 THEN inb = inb + 1 OUT baseport + 2, 0 delay tdlay OUT baseport + 2, 2 delay tdlay NEXT shiftinput = inb END FUNCTION ' Write a byte SUB shiftoutput (b AS INTEGER) DIM b7 AS INTEGER DIM dout AS INTEGER FOR b7 = 0 TO 7 IF (b AND &H80) <> &H80 THEN dout = 1: ELSE dout = 0 OUT baseport + 2, dout + 2 b = b * 2 b = b AND &HFF OUT baseport + 2, dout delay tdlay OUT baseport + 2, dout + 2 delay tdlay NEXT OUT baseport + 2, 2 END SUB
This article is copyright 1999, 2000 by AWC. All Rights Reserved.
Site contents © 1997-2018 by AWC, Houston TX (281) 334-4341