/* Program to write a character to the parallel port */ #include #include #include #define ON 1 #define OFF 0 // address of LPT1 #define lptBase 0x378 // address offsets from the base-address, on the lp port #define dataAdd lptBase #define statAdd lptBase + 1 #define cntlAdd lptBase + 2 void main(int argc, char *argv[]) { char c; if (argc == 2) { c = argv[1][0]; } else { c = 'A'; } // Get access to parallel port registers if (ioperm(lptBase,3,ON) == -1) { fprintf(stderr,"Cannot get permission to access parallel port.\n"); fprintf(stderr,"You need to be superuser to do this.\n"); perror("ioperm"); exit(1); } printf("Writing a \'%c\' to the parallel port\n",c); outb(c,dataAdd); printf("Parallel port returns a \'%c\'\n",inb(dataAdd)); // No longer need to use parallel port ioperm(lptBase,3,OFF); }