![]() |
| | #1 |
| Registered User Join Date: Oct 2006 Location: UK/Norway
Posts: 464
| Parallel Port: Sending the signals as binary 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 | |
| | #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 | |
| | #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 | |
| | #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)); 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 | |
| | #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 | |
| | #6 |
| and the hat of vanishing 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 | |
| | #7 | |
| Registered User Join Date: Oct 2006 Location: UK/Norway
Posts: 464
| Quote:
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);
}
.................
Last edited by h3ro; 08-25-2007 at 11:35 AM. | |
| h3ro is offline | |
| | #8 |
| and the hat of vanishing 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 | |
![]() |
| Thread Tools | |
| Display Modes | |
|
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 |