pref home next
day1: test parallel out

First find some information about parallel ports on the internet.
http://www.linuxjournal.com/article.php?sid=2662
http://www.beyondlogic.org/
these 2 sites were good enough and helped me to make the first program and a test circuit.

the resistors are 330 ohm and the diodes are red leds. The led at pin 1 will always be on (in normal operation)


The Source codes:
Linux:

// should work  http://cscene.org

#include stdio.h>
#include unistd.h> /* needed for ioperm() */
#include asm/io.h> /* for outb() and inb() */

#define PORT 0x378
#define DATA 0x378
#define STATUS DATA+1
#define CONTROL DATA+2


   int main(int argc, char **argv)
   {
   int i,n=0;
   //int value = 0;
   int x = 0x32;
   int y = 0x08;

   for (i=1;i=argc-1;i++) {
        sscanf(argv[i],"%x",&n);
        //sscanf(argv[++i],"%x",&v);
	}

   if (ioperm(DATA,3,1)) {
        printf("Sorry, you were not able to gain access to the ports\n");
        printf("You must be root to run this program\n");
        exit(1);
        }

   outb(n,PORT);
   //outb(DATA, x); /* Sends 0011 0010 to the Data Port */
   //outb(CONTROL, y^0x0b);

   /* SELECT_IN = 1, INIT = 0, /AUTO_FEED = 0, /STROBE = 0 */

   return (0);
   }
   

Mind that you have to be root to control the parallel port.

Windows:
#include stdio.h>
#include windows.h>
#include pt_ioctl.c>

void __cdecl main(void)
{
    unsigned char value;
    //printf("IoExample for PortTalk V2.0\n http://www.beyondlogic.org\n");
    OpenPortTalk();
    outportb(0x378, 0xFF);
    value = inportb(0x378);
    printf("Value returned = 0x%02X \n",value);
    // sleep(1);
    outp(0x378, 0x00);
    value = inp(0x378);
    printf("Value returned = 0x%02X \n",value);
    ClosePortTalk();
}

Mind that for windows Porttalk has to be installed, you can find it at beyondlogic.org.


the test circuit...


pref home next
day1: test parallel out