Programming a "PARALLEL PORT" in C using "inb " and "outb()"


   
                           For programming a parallel port in C,the user program is supposed to get the permission for accesing  the I/O port using the call

iopl(permission value)

which changes the previlege of the calling process.
By default the user program has a permission value of 0.So for accessing the parallel port,the user program  is supposed to have a permission value of 3

iopl(3);

  • outb()

For porting a value onto the parallel – port,the function outb() is used .

outb(value,0x378); 


parallel port the out pins are from 2 to 9 pin.


outb(value,portaddr);

will port a byte to the portaddr address.
the port address is to be selected as follows 

for 
/dev/lp0     ——    0x378 
/dev/lp1     ——–   0x3bc

 
a simple program in C to port a value to the parallel port


inb(portaddr)

parallel port register set


there are three main registers for a parallel port

  • status register
  • controll register
  • status  register

so these registers are used to read  the values of specific pins

the address of the status register
/dev/lp0 — >  0x378
/dev/lp1 — >  0x

Advertisements
  1. #1 by Rick on September 20, 2011 - 8:18 AM

    Hello, how can i read the value of pins so that if the value of a pin is “x” i’ll type another command..

    • #2 by nairrohit on November 17, 2011 - 6:17 AM

      @Rick : Try using ‘inb’ for reading the values from the pin.

  2. #3 by Emma on July 1, 2012 - 7:55 AM

    but the inb give segmentation fault

  3. #4 by iain m on November 19, 2012 - 8:13 PM

    I suggest the iopl(3) failed; print out the result of it?
    fprintf(stderr,”%d\n”,iopl(3));
    you need a zero for iopl to have been ok; if you dont get zero then something else has the parallel port; rmmod parport?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: