Mail Archives: djgpp/1997/06/04/22:18:56
On 23 May 1997, Jono wrote:
> I'm trying to write a program that will use the parallel port pins to turn
> appliances on and off. I have found the following code, but can't get it
> to compile under djgpp. It's supposed to turn pin 2 on at 10:05 for one
> minute. If anyone can help, how do I tell it which pins to turn on?
>
> #include <stdio.h>
> #include <time.h>
> #include <pc.h>
>
> int main(void)
> {
> struct time t;
> unsigned port = 0x378;
> while()
> {
> gettime(&t);
> if(t.ti_hour==10 && t.ti_min==05) outportb (port,1);
> else outportb (port,0); ^
> }
> }
>
> Thanks,
> Jono
>
That part there with the caret. If you outportb (port,1) you toggle PB0 on
the parallel port. If you outportb (port,2) it's PB1, etc. You have to
look up the pinouts of the parallel port though.
And a cautionary note (if you're using home-brew equipment). Do place an
optoisolator between each bit of your parallel port and whatever equipment
you're running (relays?) so you don't fry your computer if you do
something really bad..
-----------------------------------------------------------------------
Orlando Alcantara Andico
WWW: http://www2.mozcom.com/~orly/ Email: orly AT mozcom DOT com
ICBM: 14 deg. 30' N, 120 deg. 59' E POTS: (+632) 932-2385
- Raw text -