Ubuntu 8.04, I/O control via LPT port
things happened are more than expected. Today, another issue if a replication for the gcc complier to work with the original C-code followings.
/*
* IO_LPT1.c: very simple example of port I/O
*
* This code does nothing useful,
* write 0xFF to LPT1, LED on, a pause, read, display
* write 0x00 to LPT1, LED off, a pause, read, display
* and a port read.
* how to compile : gcc -O2 -o IO_LPT1 IO_LPT1.c
* how to run : sudo ./IO_LPT1
*/
#include < stdio.h >
#include < unistd.h >
#include < /usr/src/linux-headers-2.6.24-17-generic/include/asm-x86/io.h >
#define BASEPORT 0x378 /* LPT1 */
int main()
{
/* Get access to the ports */
if (ioperm(BASEPORT, 3, 1)) {perror("ioperm"); exit(1);}
/* Set the data signals (D0-7) of the port to all high (1), LED on */
outb(0xff, BASEPORT);
/* Sleep for a while (1000000 us = 1 sec, LED on) */
usleep(1000000);
/* Read from the date port (BASE) and display the result */
printf("Printer port 0x378 = %d\n", inb(BASEPORT));
/* Set the data signals (D0-7) of the port to all low (0), LED off */
outb(0, BASEPORT);
/* Sleep for a while (1 sec) */
usleep(1000000);
/* Read from the date port (BASE) and display the result */
printf("Printer port 0x378 = %d\n", inb(BASEPORT));
/* Read from the status port (BASE+1) and display the result */
printf("status port: %d\n", inb(BASEPORT + 1));
/* We don't need the ports anymore */
if (ioperm(BASEPORT, 3, 0)) {perror("ioperm"); exit(1);}
exit(0);
}
/* end of IO_LPT1.c */