C Board  

Go Back   C Board > Community Boards > Tech Board

Reply
 
LinkBack Thread Tools Display Modes
Old 08-25-2007, 08:22 AM   #1
Registered User
 
Join Date: Oct 2006
Location: UK/Norway
Posts: 464
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?
h3ro is offline   Reply With Quote
Old 08-25-2007, 08:37 AM   #2
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
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
matsp is offline   Reply With Quote
Old 08-25-2007, 09:04 AM   #3
Registered User
 
Join Date: Oct 2006
Location: UK/Norway
Posts: 464
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.
h3ro is offline   Reply With Quote
Old 08-25-2007, 09:15 AM   #4
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
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
matsp is offline   Reply With Quote
Old 08-25-2007, 09:22 AM   #5
Registered User
 
Join Date: Oct 2006
Location: UK/Norway
Posts: 464
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 09:24 AM.
h3ro is offline   Reply With Quote
Old 08-25-2007, 09:39 AM   #6
and the hat of vanishing
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,214
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.
Up to 8Mb PlusNet broadband from only £5.99 a month!
Salem is offline   Reply With Quote
Old 08-25-2007, 09:44 AM   #7
Registered User
 
Join Date: Oct 2006
Location: UK/Norway
Posts: 464
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 11:35 AM.
h3ro is offline   Reply With Quote
Old 08-25-2007, 12:22 PM   #8
and the hat of vanishing
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,214
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.
Up to 8Mb PlusNet broadband from only £5.99 a month!
Salem is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Parallel Port I/O in Windows XP - my program crashes when I run it Z'Ha'Dum C Programming 3 02-29-2008 01:29 PM
brace-enclosed error jdc18 C++ Programming 53 05-03-2007 05:49 PM
Segmentation Fault - Trying to access parallel port tvsinesperanto C Programming 3 05-24-2006 03:28 AM
Binary Search Trees Part III Prelude A Brief History of Cprogramming.com 16 10-02-2004 03:00 PM
Request for comments Prelude A Brief History of Cprogramming.com 15 01-02-2004 10:33 AM


All times are GMT -6. The time now is 06:46 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

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