delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/06/04/22:18:56

Date: Thu, 5 Jun 1997 10:07:27 +0800 (GMT)
From: Orlando Andico <orly AT gibson DOT eee DOT upd DOT edu DOT ph>
To: Jono <pistils AT hotmail DOT com>
cc: djgpp AT delorie DOT com
Subject: Re: Parallel port program help
In-Reply-To: <01bc672f$b73bba80$b40000c8@Ppro>
Message-ID: <Pine.SGI.3.93.970605100539.5557A-100000@gibson.eee.upd.edu.ph>
MIME-Version: 1.0

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019