Drive the parallel port from C in Linux

In the C programming language one can do as follows: pp.c
    #include <stdio.h>
    #include <unistd.h>     /* For sleep(), ioperm(), inb() and outb(). */
    #include <sys/io.h>     /* Perhaps <asm/io.h> on other systems. */

    /* See your BIOS to find the base address of the port. */
    #define kDATA_REG (0x0378)          /* Data register (base address). */
    #define kSTAT_REG (DATA_REG + 1)    /* Status register. */
    #define kCONT_REG (DATA_REG + 2)    /* Control register. */

    int main()
    {
        int i;

        if (ioperm(kDATA_REG, 1, 1))
            {
            printf("ioperm(%x) failed.\nYou must be root!\n", kDATA_REG);
            return 1;
            }

        for (i = 0; i < 10; i++)  /* Let the LED(s) blink. */
            {
            outb(255, kDATA_REG);       /* All 8 datalines high. */
            sleep(1);
            outb(0, kDATA_REG);         /* All 8 datalines low.  */
            sleep(1);
            }

        return 0;
    }
Put a LED on dataline 0 (pin 2) of the Centronics port (+).
Pins 18 through 25 are ground (-).
A series-resistor must be included (anything greater than 1000 Ohm will be safe).

The LED blinks 10 times.

Pieter Suurmond, august 4, 2009.