delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/01/29/19:18:19

Date: Mon, 29 Jan 1996 19:12:20 -0500 (EST)
From: Mark Lee <mlee AT heart DOT rri DOT uwo DOT ca>
Subject: Parallel/Serial port programming
To: djgpp AT delorie DOT com
Cc: mlee AT heartlab DOT rri DOT uwo DOT ca

Hi,

I'm having troubling writing a small program to access the parallel port. 
I can easily write to it, but reading is a no a go. What the program 
should do is request a control byte from another PC and acknowledge that 
a byte is read by setting the CONTROL REGISTER.
----------------------------------------------------------------------------------
#include <stdio.h>  
#include <conio.h>  
#include <string.h> 
#include <stdlib.h>  
#include <pc.h>

/* Printer port definitions */

#define nPort   0x378   /* LPT1 Definition */

#define DATA_PORT     (nPort)
#define STATUS_PORT   (nPort + 1)
#define CONTROL_PORT  (nPort + 2)

#define STATUS_NORESP    0x01
#define STATUS_UNUSED1   0x02
#define STATUS_UNUSED2   0x04
#define STATUS_ERROR     0x08
#define STATUS_SELECTED  0x10
#define STATUS_NOPAPER   0x20
#define STATUS_ACK       0x40
#define STATUS_NOTBUSY   0x80

#define CONTROL_STROBE   0x01
#define CONTROL_AUTOFEED 0x02
#define CONTROL_INIT     0x04
#define CONTROL_SELECT   0x08
#define CONTROL_IRQ7     0x10
#define CONTROL_UNUSED1  0x20
#define CONTROL_UNUSED2  0x40
#define CONTROL_UNUSED3  0x80

/* End printer port definitions. */


void main(void)
{
  int read=1;
  outportb(DATA_PORT,0);      /* clear the data bits               */
  outportb(CONTROL_PORT,0);   /* initialize  other PC to send DATA */
  while(read)
  {
      while(inportb(STATUS_PORT))      /* check DATA is beening sent */
      {                                /* read DATA and print        */
 	   fprintf(stderr," DATA READ %d \n",inportb(DATA_PORT)); 
      }
      outportb(CONTROL_PORT,1);       /* Send Stop Request          */
                                      /* End reading                */       
       read=0;
  }
    
}

-----------------------------------------------------------------------------------

I compiled with gcc -Wall -O3 para.c -o para -lm -lpc. Is there 
something stupid I'm doing or missing ? Any help would be appriecated.


-Thanks
 Mark 

          __         
 ________/\ \  __  Mark Lee                   "There is thin line between 
/\  __  __ \ \/\_\ mlee AT irus DOT rri DOT uwo DOT ca        Genuis and Insanity and 
\ \ \ \ \ \ \/ / / Advanced Imaging Group      I'm stuck in a singularity"
 \ \ \ \ \ \_\/ /  Robarts Research Institute   
  \/_/\/_/\/___/   London, Ontario   Canada 

- Raw text -


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