Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 4 Apr 2003 09:45:06 +0200
From:      "Daan Vreeken [PA4DAN]" <Danovitsch@Vitsch.net>
To:        Dtseven@gmx.at
Cc:        FreeBSD-questions@FreeBSD.org
Subject:   Re: LPT1 Port in ASM or C
Message-ID:  <200304040945.06653.Danovitsch@Vitsch.net>
In-Reply-To: <200304040931.34722."Dtseven@gmx.at">
References:  <200304040931.34722."Dtseven@gmx.at">

next in thread | previous in thread | raw e-mail | index | archive | help
On Friday 04 April 2003 09:31, Dtseven@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 th=
e=20
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 =3D 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 =3D Data;
             =20
      __asm __volatile("outb %0,%%dx" : : "a" (D), "d" (Port) );
}

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

With the following command you should create a nice 1-0-1-0 bit pattern o=
n the=20
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200304040945.06653.Danovitsch>