1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
#include <stdio.h>
#include <conio.h>
#include <iostream>
#include <windows.h>
using namespace std;
/* prototype (function typedef) for DLL function Oup32fp: */
typedef void (_stdcall *oupfuncPtr)(short portaddr, short datum);
#define PPORT_BASE 0x378 // identify port address
// After successful initialization, this variable will contain function pointer.
oupfuncPtr oup32fp;
// Wrapper function for the function pointer - call these functions to perform I/O.
void Out32 (short portaddr, short datum)
{
(oup32fp)(portaddr,datum);
}
HINSTANCE hLib;
int initialize()
{
/* Load the library */
hLib = LoadLibrary("inpout32.dll");
if (hLib == NULL) {
fprintf(stderr,"LoadLibrary Failed.\n");
getch();
return -1;
}
/* get the address of the function */
oup32fp = (oupfuncPtr) GetProcAddress(hLib, "Out32");
if (oup32fp == NULL) {
fprintf(stderr,"GetProcAddress for Oup32 Failed.\n");
getch();
return -1;
}
return 0;
}
// ---------------- DO NOT CHANGE ANY OF THE ABOVE CODE --------------------------
int main()
{
short value; // smaller integer type for port data
int port = PPORT_BASE; // memory address for parallel port
initialize(); // call function to set up port for output
for (int counter = 1; counter <= 5; counter ++)
{
Out32(port,9);// Turn North/South GREEN & Hold WEST/EAST RED
cout << "---North & South = ON East & West = OFF---\n";
Sleep(3000);// Holds Green Light for 3 sec
Out32(port,4);// WEST/EAST RED and NORTH/SOUTH YELLOW
cout << "---North & South = BLINKING East & West = OFF---\n";
Sleep(1000);//Holds YELLOW NORTH/SOUTH
Out32(port,3); // Turn all light RED
cout << "---North & South = OFF East & West = OFF---\n";
Sleep(500); // Hold RED half sec
Out32(port,34);// Turn EAST/ WESTGREEN GREEB AND NORTH/SOUTH RED
cout << "---North & South = OFF East & West = ON---\n";
Sleep(3000);// Holds Green Light for 3 sec
Out32(port,18);// Turns all lights RED and EAST/WEST YELLOW
cout << "---North & South = OFF East & West = BLINKING---\n";
Sleep(2000);//Holds YELLOW EAST/WEST
Out32(port,3); // Turn all light RED
cout << "---North & South = OFF East & West = OFF---\n";
cout << "" << endl;
cout << "Times ran = " << counter << endl;
Sleep(500); // Hold RED half sec
}
FreeLibrary(hLib);
cout << endl;
system("PAUSE");
return(0);
}
|