Parallel Port: Sending the signals as binary

This is a discussion on Parallel Port: Sending the signals as binary within the Tech Board forums, part of the Community Boards category; I am having trouble understanding how to send signals to the parallel port. It is working, I just dont understand ...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485

    Parallel Port: Sending the signals as binary

    I am having trouble understanding how to send signals to the parallel port.
    It is working, I just dont understand how to send a signal to the correct port. Right now it looks kind of random to me

    This is how I think it works:
    11111111 means that I am addressing all the ports. Where I use 0 or 255 to turn them on/off.
    00000000 means that I am not addressing any of them.

    00110000 means that I am addressing port 3 and 4.

    I know I have to convert the binary number into a int in order to send it (using the windows calculator for this)

    But it does not work as expected. Any thoughts on what I am doing wrong?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Can you describe in a few more words what's actually happening on the parallel port? What do you have connected on the "other end"?

    What do you mean by "addressing all ports, adressing port 3 and 4", etc?

    --
    Mats

  3. #3
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485
    I thought that all the 8 output ports were written as this "xxxxxxxx", and that the ones I want to send a signal to has to be addressed with a 1, and the others with a 0.

    So if I want to address port 1 and non of the others I have to write:
    10000000

    and If I want to address port 1 and 8:
    10000001

    Not sure if this is right?

    On the other end I only have some LED lights, connected to the ground and to the ports.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Pins are numbered 1 to 8, but the bits are bit 0 to 7 (just to make life interesting).

    To write bits 0 and 7, you could use
    Code:
    out(0x378, (1 << 7) | (1 << 0));
    (assuming port number is the first item - particularly Linus swaps the arguments for "out" to have the port number as second argument). [The valus is 0x81 or 129 (128 + 1)].

    By the way, I usually start counting with the lowest bit to the right, rather than to the left - it makes life a bit simpler that way.

    --
    Mats

  5. #5
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485
    Is the first argument which parallel port I am sending to? (Remember seeing 0x378 as the address to the first parallel port I think)

    If thats the case, that clears things up a lot. I think I might have been mixing pin and port

    So to turn pin 1 on I have to write out32(0x378,0)?

    Edit:
    I have never seen the (1 << 7) | ( 1 << 0) before, what does it mean?
    Last edited by h3ro; 08-25-2007 at 10:24 AM.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,821
    Your other problem to overcome is if you're using a protected OS which doesn't allow any Tom Dick or Harry free reign over the I/O address space.

    In most modern desktop operating systems, all access to the hardware is via a driver under control of the OS. Mere user level programs don't see the hardware directly.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485
    Quote Originally Posted by Salem View Post
    Your other problem to overcome is if you're using a protected OS which doesn't allow any Tom Dick or Harry free reign over the I/O address space.

    In most modern desktop operating systems, all access to the hardware is via a driver under control of the OS. Mere user level programs don't see the hardware directly.
    I know, but I am using the Output32.dll which solves this. It the simple problem of understanding what to send to the port to open/close the pin which is my problem.

    Right now I can send signals, but I dont understand fully what to do in order to open port X. Right now it looks kinda random to me.

    EDIT:
    I made a small program which goes something like this:
    Code:
    	int key = 0;
    
    	while (key != -1)
    	{ 	 
    		std::cout << " \n  Enter a number between 0 and 7 to open/close a port" << std::endl;
    
    		std::cin >> key;
    
    		if (key == 0)
    		{
    			Out32(888,0);
    		}
    
    		if (key == 1)
    		{
    			Out32(888,1);
    		}
    
    		if (key == 2)
    		{
    			Out32(888,2);
    		}
                    .................
    But the number does not open the correct pin. Also, when converting to binary it makes no sens to the output I get on the LEDs
    Last edited by h3ro; 08-25-2007 at 12:35 PM.

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,821
    I thought you also had to mess around with some of the control registers as well to make sure the data pins are outputs, and not inputs.

    Something to read.
    http://www.lvr.com/parport.htm
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 02-29-2008, 01:29 PM
  2. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 06:49 PM
  3. Segmentation Fault - Trying to access parallel port
    By tvsinesperanto in forum C Programming
    Replies: 3
    Last Post: 05-24-2006, 04:28 AM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 04:00 PM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21