Ah the weekend, again. I feel like tinkering a bit, so let’s tinker with Parallel ports. Actually, the idea got embedded when a few days earlier when I read a post on channel 9. So the first thing was to build an LED probe – I couldn’t find my old one, but building a new one won’t be hard.
About 15 years ago, I did some work looking at ways of producing good, but ‘cheap’ sound from the Business computers of the day – for the young amongst you, back then sound cards where optional, as they typically cost over $150.00 each (probably more like $250). After quite a bit of (snail) research (the Internet was just starting up here, in Australia), I ended up producing initial designs which used the Parallel port. I might dig up the design I did using the, then, new low-voltage Microchip PIC device. Anyway, my memory is not that good, so I did have to double check that I was about to use the right pins.
Pin # | Return | Name | Description |
1 | 18 | /STROBE | Data Strobe |
2 | 19 | D0 | Data bit 0 |
3 | 19 | D1 | Data bit 1 |
4 | 20 | D2 | Data bit 2 |
5 | 20 | D3 | Data bit 3 |
6 | 21 | D4 | Data bit 4 |
7 | 21 | D5 | Data bit 5 |
8 | 22 | D6 | Data bit 6 |
9 | 22 | D7 | Data bit 7 |
10 | 23 | /ACK | Acknowledge |
11 | 23 | BUSY | Busy |
12 | 24 | PE | Paper Empty |
13 | 24 | SEL | Select |
14 | 24 | /AUTOFD | Autofeed |
15 | 25 | /ERROR | Error |
16 | 25 | /INIT | Initialise |
17 | 25 | /SELIN | Select In |
I dug through my box-of-bits, and dug out the eight 3mm LEDs and resistors, some vero board and a DB25m connector. A couple hours later (funny how time flies when your doing menial tasks like bending the LED leads to the right height, etc), I had a simple Parallel LED probe. The eight LEDs being directly driven by each of the eight data bit signals through 360 Ohm resistors (these unusual resistors where scored from a surplus box, about 20 years ago – big bag).
OK, that’s my Electronics appetite appeased. Now for a light show.
With Windows NT and later versions of Windows, user-mode applications can no longer access the hardware directly. But as I noted in my channel 9 response, you can use a Virtual Machine running the older Windows 9x operating systems, and just let the Virtualisation software translate it for you. As I wasn’t sure wether Microsoft’s Virtual PC would also work, I installed Virtual PC 2007 on the now familiar, 1.7GHz Celeron System running Vista Enterprise. After some stuffing about, I managed to convert one of my VMWare disk images, etc. I then looked into wether I could install Visual C++ 2005 Express into the Windows 98 SE virtual machine, but then chickened out, and installed Dev-C++, instead.
As it turned out, I needed to hack one of the headers, in this case conio.h, as I wanted to match Microsoft – the whole idea of Mingw and therefore Dev-C++ is to compile using Microsoft’s MSVCRT DLL(s):
#if defined(__MSVCRT__ || __MINGW32__ ) int __cdecl _inp(unsigned short); unsigned short __cdecl _inpw(unsigned short); unsigned long __cdecl _inpd(unsigned short); int __cdecl _outp(unsigned short, int); unsigned short __cdecl _outpw(unsigned short, unsigned short); unsigned long __cdecl _outpd(unsigned short, unsigned long); #endif
Here is a simple program to get you started. I simply hard-coded the I/O port address for the first Printer port (LPT1:). I’ve embedded a link to a soapbox video, so lets see how good you are figuring out why the LEDs turn on and off the way they do:
#include <windows.h> #include <conio.h> #include <stdio.h> int main(int argc, char *argv[]) { int i, n = 8 * 10; _outp( 0x378, 0 ); Sleep(3000); for(i=0; i < n; i++) { _outp( 0x378, 1<<(i & 0x7) ); Sleep(150); } _outp( 0x378, 0xff ); Sleep(150); for(i=0; i < n; i++) { int d = i & 0x7; d = (i & 8) ? (7 - d) : d; _outp( 0x378, 1<<d ); Sleep(150); } _outp( 0x378, 0xff ); Sleep(150); for(i=0; i < n; i++) { int d = (i & 0x3)<<1; d = (i & 4) ? (7 - d) : d; _outp( 0x378, 1<<d ); Sleep(150); } // Done. puts("\nPress enter to exit"); getchar(); return 0; }
Now a further challenge.
In the last two loops, I have a ‘?:’ conditional expression. eg d = (i & 8) ? (7 – d) : d; Can you think of equivalent expression(s) which do not have conditionals ?