/*********************************************************************** * upDown.cpp * * Driver program for up/down counter project. * * This program assumes the following: * * Parallel port pin FPGA signal * -------------------- ------------ * D0 Reset * D1 Hold * D2 Up/!Down * * The program allows the user to control the above three parallel port * pins from the keyboard: * * Key Action * -------------------- ------------------------------- * r Toggle D0. * h Toggle D1. * c Toggle D2. * q Exit. * * "Enter" must be pressed after a keystroke. * * This program will first reset the counter, then begin counting up. * * For compilation, this program requires pport.h and pport.cpp. ***********************************************************************/ #include #include "pport.h" /*********************************************************************** * main() ***********************************************************************/ int main() { /* Current values of the parallel port's data pins. */ int reset = 1; int hold = 0; int count = 1; /* Reset counter */ writeDataReg(0x4); /* Begin counting up. */ writeDataReg(0x5); /* Print simple instructions. */ printf("Press 'r' to toggle reset, 'h' to toggle hold, or 'c' to" " toggle count\n"); printf("direction. Press 'q' to quit.\n\n"); /* Action loop. We read a keystroke, act on it, and wait for the next * keystroke. */ while (1) { printf("\rReset: %d, Hold: %d, Count Direction: %d." " Command: ", reset, hold, count); switch (getchar()) { case 'r' : case 'R' : reset = (reset + 1) % 2; break; case 'h' : case 'H' : hold = (hold + 1) % 2; break; case 'c' : case 'C' : count = (count + 1) % 2; break; case 'q' : case 'Q' : printf("\n"); return 0; break; default : break; } /* Write new values to parallel port. */ writeDataReg((reset) | (hold << 1) | (count << 2)); } return 0; }