The goal is to perform simple control via the parallel port.
You will finish it in one evening or die laughing.

What were going to do here is combine 3 things:
1)First the software library:
URL:  http://www.logix4u.net/inpout32.htm
Download: inpout32_source_and_bins.zip
Install:   Copy the inpout32_source_and_bins/binaries/Dll/inpout32.dll to your system32 folder (usually C:\WINDOWS\system32 or so) (recommended if you'll stick with this library and want it globally accessible)
2)MSVC 2k8
MSVC 2k8 Express Edition Download (You can grab the other language IDEs if you want, but grab Visual C++ for this tutorial):  http://www.microsoft.com/express/download/ And follow the installation instructions.
3) The hardware gizmo:
URL: if you insist,  http://eds.dyndns.org:81/Pages/Schematics.html
Assemble: here is the schematic, I'm going to assume you know how to build it.


The resistors should be about 220 to 330 ohms (lets say orange orange brown gold)
And here is a crude photo of the one that I built:



It shouldn't be possable to damage your computer with this, but dont let any of the wires touch, and I don't take responsibility if your computer has a spontanious combustion episode while you happen to be working on this project. That said you don't have to turn your computer off to install this, just plug it in.

There!
    Now all we have to do it tie it all togethor. So:

4)

Start up MSVC 2k8
File, New, Project



Under C++ go to Win32 and click Win32 Console Application
give it a name, and click OK.



Click on Application Settings and make sure Console Application is active and "Empty project" is checked.
Click Finish when you're done.




Click on Project -> Add New Item




Select C++ File (.cpp) and give the file a name; click Add when you're finished







now, paste in the following code into the file:


/*
DAn Williams
Aug 14 2004
Demo of parallel port access and controll.
uses inpout.dll
Enjoy.
Code Modified by James Marcelin November 20, 2008
*/
#include <conio.h>
#include <stdio.h>
#include <windows.h>

/* definitions on what port is what base address depends, so use this */
#define LPT1 0x378
#define LPT2 0x278
#define LPT3 0x3BC

/* register offsets */
#define DATA 0
#define STATUS 1
#define CONTROLL 2

#define BASE_ADDRESS LPT1
/* this is the address we use (modify here if you need to) */

typedef short (__stdcall *INP32)(short PortAddress);
typedef void (__stdcall *OUT32)(short PortAddress, short Data);

int main(void) {

short value;

HINSTANCE hLib;
INP32 Inp32;
OUT32 Out32;

/******************** LIBRARY INIT ***********************/

if ((hLib = LoadLibrary(TEXT("inpout32.dll"))) == NULL) {
printf("Unable to load inpout32.dll, did you copy it to the system folder?\n");
return 0;
}

if ((Inp32 = (INP32)GetProcAddress(hLib, "Inp32")) == NULL) {
printf("Unable to establish handle to input function.\n");
return 0;
}

if ((Out32 = (OUT32)GetProcAddress(hLib, "Out32")) == NULL) {
printf("Unable to establish handle to output function.\n");
return 0;
}


/*********************** MAIN CODE **************************/

// Write to the data register
value = 0x55;
printf("Writing 0x%2X to port 0x%X...\n" ,value ,BASE_ADDRESS );
Out32( BASE_ADDRESS , value );

// Read it back
value = Inp32(BASE_ADDRESS);
printf("\n(Reading) Port %04X = %04X\n", BASE_ADDRESS, value);

// Now use a different value
value = 0xAA;
printf("\nWriting 0x%2X to port 0x%X...\n" ,value ,BASE_ADDRESS );
Out32(BASE_ADDRESS, value);

// Read it back
value = Inp32(BASE_ADDRESS);
printf("\n(Reading) Port %04X = %04X\n\n", BASE_ADDRESS, value);

/******************** CLEANUP ******************************/

// GO FREEE LITTLE LIBRARIES!, GO FREEEEE!!!
FreeLibrary(hLib);

// were done.
printf("Press any key to exit.\n");
_getch();

return 1;
}



Now click file, save <your file's name> (I named my file main.cpp so mine says "save main.cpp")
You could also press Ctrl + S




Now, click Build, Build Solution or press F7




If all goes well, you get one of these: If not, I have no idea what could have gone wrong.




Now, click Debug, Start Without Debugging



You should have a command console window come up thats like this:



If you don't have an 'any' key on your keyboard, then click the X in the top right to close the program. Some time in the next year we will cover the addition of the 'any' key to your keyboard, we may also make an 'exit' key, as it would made more sense (escape is not close enough)

that about wraps this project up.

ah wait!

you will notice some lights are on on your gizmo
 you use calc (in scientific mode) to convert between binary and hexdecimal....
Do some playing with the 'value' values (try 0x01 0x02 0x04 0x08 0x10 0x20 0x40 and 0x80) then you can start to get a handle on controlling specific lights.

   Have fun!
        Dan

Page Modified by James Marcelin November 20, 2008