/* * example.c: very simple example of port I/O * * This code does nothing useful, just a port write, a pause, * and a port read. Compile with `gcc -O2 -o example example.c', * and run as root with `./example'. */ #include #include #include #define BASEPORT 0x378 /* lp1 */ int main() { int byte=0; /* Get access to the ports */ if (ioperm(BASEPORT, 3, 1)) {perror("ioperm"); exit(1);} while(1) { /* Set the data signals (D0-7) of the port to all low (0) */ outb(byte, BASEPORT); printf("%i\n",byte); /* Sleep for a while */ usleep(10000000); /* Read from the status port (BASE+1) and display the result */ printf("status: %d\n", inb(BASEPORT + 1)); if(byte) byte=0; else byte=255; } /* We don't need the ports anymore */ if (ioperm(BASEPORT, 3, 0)) {perror("ioperm"); exit(1);} exit(0); } /* end of example.c */