LPT1 Port in ASM or C

Daan Vreeken [PA4DAN] Danovitsch at Vitsch.net
Thu Apr 3 23:44:03 PST 2003


On Friday 04 April 2003 09:31, Dtseven at gmx.at wrote:
> Hi all!
> I want to know how I can control the lpt1 port in asm or C.
> I'm a newbie.
> Any help would be greatly appreciated.

There are two ways to do that.
1. Directly poke around with the ports
2. open /dev/lpt0 and communicate with that

I have never looked at the second way, but I can tell you how to do it the 
first way :)
In FreeBSD to have direct port-access you application needs to open /dev/io
Once it has done that, it can directly write to any port it wants.

Opening /dev/io should look something like :
FILE      *IO;
IO = fopen("/dev/io","rw");

And then you can write/read ports with this little piece of assembly :

void outp(unsigned short Port, unsigned char Data)
{
      unsigned char   D = Data;
              
      __asm __volatile("outb %0,%%dx" : : "a" (D), "d" (Port) );
}

unsigned char inp(unsigned short Port)
{
        unsigned char   Data = 0;
        
        __asm __volatile("inb %%dx,%0" : "=a" (Data) : "d" (Port) );
        return Data;
}

With the following command you should create a nice 1-0-1-0 bit pattern on the 
parallel port :
outp(0x378,0xaa);


I have some example code (that does much more than controlling the port) here:
http://danovitsch.dnsq.org/cgi-bin/gpl/cat.cgi/lampd/v1.0?lampd.c

grtz & good luck,
Daan


More information about the freebsd-questions mailing list