linux

There is slight variation from windows environment and that is due to OS support.

I have tried the code on Fedora and Ubuntu.

Hope it will work similar for you too.

you need to run the program as root .

/*

blink_parallel_port

  • a led attached from pin 2 to 9 will blink after 5 seconds.other terminal of led can be grounded to pin 18 of parallel port. The circuit: led connection: Anode to pin no 2 and Cathode to pin 18.
Source : http://en.wikipedia.org

*/#include <stdio.h>#include <unistd.h>#include <sys/io.h>

//#include <asm/io.h>//can be uncommented if sys/io.h does not give result.

#include <stdlib.h>

delay_s(int a)

{

int i,j,k;

a*=1000;

for(i=0;i<10;i++)

for(j=0;j<100;j++)

usleep(a);

}

int main()

{

/* Get access to the ports */

if (ioperm(0x378,8, 1)) //ioperm(from, num, turn_on=1/ turn_on=0)

{

perror("ioperm");

exit(1);

}

/* Set the data signals (D0-7) of the port to all low (0) */

//outb(0, 0x378);

//printf("%c\n",inb(0x378));

/* Set the data signals (D0-7) of the port to all high (0) */

while(1)

{

outb(0xff, 0x378);

printf("*\t");

delay_s(5);

//usleep(100000);

outb(0x00, 0x378);

delay_s(5);

}

return 0;

}