/* DAn Williams Aug 14 2004 RifRaf 2007 Demo of parallel port access and controll. uses inpout.dll Enjoy. */ #include #include #include #include /* 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("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 **************************/ int x = 0; while (x <= 10) { // Write to the data register value = 0xC0; Out32( BASE_ADDRESS , value ); Sleep(100); // Now use a different value value = 0x60; Out32(BASE_ADDRESS, value); Sleep(100); value = 0x30; Out32(BASE_ADDRESS, value); Sleep(100); value = 0x18; Out32(BASE_ADDRESS, value); Sleep(100); value = 0x0C; Out32(BASE_ADDRESS, value); Sleep(100); value = 0x06; Out32(BASE_ADDRESS, value); Sleep(100); value = 0x03; Out32(BASE_ADDRESS, value); Sleep(100); value = 0x01; Out32(BASE_ADDRESS, value); Sleep(100); value = 0x06; Out32(BASE_ADDRESS, value); Sleep(100); value = 0x0C; Out32(BASE_ADDRESS, value); Sleep(100); value = 0x18; Out32(BASE_ADDRESS, value); Sleep(100); value = 0x30; Out32(BASE_ADDRESS, value); Sleep(100); value = 0x60; Out32(BASE_ADDRESS, value); Sleep(100); value = 0xC0; Out32(BASE_ADDRESS, value); Sleep(100); value = 0x80; Out32(BASE_ADDRESS, value); Sleep(100); x++; } /******************** CLEANUP ******************************/ // GO FREEE LITTLE LIBRARIES!, GO FREEEEE!!! FreeLibrary(hLib); // were done. printf("Press any key to exit.\n"); getch(); return 1; }