# Parallel Port: Sending the signals as binary

• 08-25-2007
h3ro
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?
• 08-25-2007
matsp
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
• 08-25-2007
h3ro
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.
• 08-25-2007
matsp
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
• 08-25-2007
h3ro
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?
• 08-25-2007
Salem
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.
• 08-25-2007
h3ro
Quote:

Originally Posted by Salem
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
• 08-25-2007
Salem
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.