Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parallel port at address 0x378 to 0x37F wont work????

Status
Not open for further replies.

Oxymoron

Technical User
Dec 17, 2000
168
GB
Hi,

The title of my question is a little misleading. I am currently playing about with parallel port programming in windows xp using the C and the inpout32.dll (needed for access to the port).

I have an LED connected to pin 25 (ground) and pin 5 (one of 8 data outs), and using a program I have written that uses the oup32(loca, data) function in the inpout32.dll I can make the led turn on and off.

The wierd thing is that if i set 0x37A to 0xFF the led turns off. If I set 0x37A to 0x00 the led turns on!

I dont understand why this is; surely it should be the other way around. I know some pins are inverted, but none of the data lines are.

Also, could someone explain to me what the memory address 0x378 to 0x37F is used for. Obviously most of it is used for the 25 data pins, but what about the rest???

Any and all suggestions or help would be greatly appreciated.

Many thanks,
jOe

we are all of us living in the gutter.
But some of us are looking at the stars.
 
> Also, could someone explain to me what the memory address 0x378 to 0x37F is used for.
There are a lot of holes in the I/O address space. Not all addresses correspond to useful bits of hardware.

If (for example, the parallel port used just 4 addresses (0x378 to 0x37B), then the other 4 addresses would be unused.
Now depending on how good your hardware is, the other 4 addresses (0x37C to 0x37F) could either result in nothing happening, some hardware fault, or accesses to 0x378 to 0x37B (ie ghosts of earlier registers).

Anyway, for lots of low level detail on the PC hardware, try this site



--
 
Thankyou for your help. I'm still having trouble with my program though.

This is my C code:
-----------------------------------------------------------

#include <stdio.h>
#include <windows.h>

/* Definitions in the build of inpout32.dll are: */
/* short _stdcall Inp32(short PortAddress); */
/* void _stdcall Out32(short PortAddress, short data); */


/* prototype (function typedef) for DLL function Inp32: */
int read_all(void);
int write_all(int x);
int flash(void);

typedef short _stdcall (*inpfuncPtr)(short portaddr);
typedef void _stdcall (*oupfuncPtr)(short portaddr, short datum);
HINSTANCE hLib;
inpfuncPtr inp32;
oupfuncPtr oup32;

short x;
int i;

int main(void)
{

/* Load the library */
hLib = LoadLibrary("inpout32.dll");

if (hLib == NULL) {
printf("LoadLibrary Failed.\n");
return -1;
}

/* get the address of the function */

inp32 = (inpfuncPtr) GetProcAddress(hLib, "Inp32");

if (inp32 == NULL) {
printf("GetProcAddress for Inp32 Failed.\n");
return -1;
}


oup32 = (oupfuncPtr) GetProcAddress(hLib, "Out32");

if (oup32 == NULL) {
printf("GetProcAddress for Oup32 Failed.\n");
return -1;
}

/* Try to read 0x378..0x37F, LPT1: */
read_all();

i=0x378;
x = 0xFF;
for(;i <= 0x037F;i++) {
(oup32)(i,x);
}

printf("press return when you want me to test!\n\n");
getc(stdin);
write_all(0x00);
printf("\n\n");
read_all();
flash();

FreeLibrary(hLib);
return 0;
}

int read_all() {
i=0x0378;
for(;i <= 0x037F;i++) {
x = (inp32)(i);
printf("port read (%04X)= %04X (d=%d)\n",i,x, x);
}
return 0;

}

int write_all(int x) {
i=0x0378;
x=0x00;
for (;i <= 0x37F;i++) {
printf("turning on 0x%X, datum=0x%2X\n",i,x);
(oup32)(i,x);
system("sleep 2");

}
return 0;

}

int flash() {
do {
i=0x378;
x = 0x00;
for(;i <= 0x037F;i++) {
(oup32)(i,x);
}

system("sleep 1");

i=0x378;
x = 0xFF;
for(;i <= 0x037F;i++) {
(oup32)(i,x);
}

system("sleep 1");
} while(1);
return 0;
}

----------------------------------------------------------

This program when run, outputs the following:

----------------------------------------------------------

Joseph@trinculo ~/io
$ ./io
port read (0378)= 00FF (d=255)
port read (0379)= 007F (d=127)
port read (037A)= 00CE (d=206) <---------LED turns on!!!!
port read (037B)= 00CE (d=206)
port read (037C)= 00FF (d=255)
port read (037D)= 00FF (d=255)
port read (037E)= 00FF (d=255)
port read (037F)= 00FF (d=255)
press return when you want me to test!


turning on 0x378, datum=0x 0
turning on 0x379, datum=0x 0
turning on 0x37A, datum=0x 0
turning on 0x37B, datum=0x 0
turning on 0x37C, datum=0x 0
turning on 0x37D, datum=0x 0
turning on 0x37E, datum=0x 0
turning on 0x37F, datum=0x 0


port read (0378)= 0000 (d=0)
port read (0379)= 007F (d=127)
port read (037A)= 00C2 (d=194)
port read (037B)= 00C2 (d=194)
port read (037C)= 00FF (d=255)
port read (037D)= 00FF (d=255)
port read (037E)= 00FF (d=255)
port read (037F)= 00FF (d=255)

----------------------------------------------------------

This illustrates my problem; I'm sending 0x00 to each address 0x378...0x37F, but when I then read the data back from these addresses I get a variety of different values.

I just can't understand why????

Hope with this extra information someone might know something.
Many thanks again,

jOe

we are all of us living in the gutter.
But some of us are looking at the stars.
 
You need to read the port information I posted.
These are not normal memory locations which you can just read and write to in any old manner. Some locations are read only, some locations are write only.


--
 
The reason the LED turns on when you write to 0x37A is because you have hit the data strobe (bit 0), which causes the previous write of 0xFF to 0x378 to go out onto the connector.

Whenever you write to the data register, it holds it there in a latch but does not push the value onto the pins, until the data strobe is toggled.

The registers are as follows:

0x378 -- SPP data port
0x379 -- SPP status port
bit 3 -- error
bit 4 -- select in
bit 5 -- paper end
bit 6 -- acknowledge
bit 7 -- busy (active low)
0x37A -- SPP control port
bit 0 -- data strobe (active low)
bit 1 -- auto feed (active low)
bit 2 -- initialize (active high)
bit 3 -- select (active low)
0x37B -- EPP address port
0x37C -- EPP data port

Here are some links to where Google pointed me to find this info.
 
Thankyou both, I understand it alot better now!
Will get back to you if I have any further problems.
(Have studied alot of the links given also)

Many thanks,
jOe

we are all of us living in the gutter.
But some of us are looking at the stars.
 
Hi again.

I've just taken the case off my parallel port wire and have found that pins 2-4 (D0-D2) are not connected to any wires!

How then do I send data of < 8???

Also, I'm still having problems sending specific data amounts to the data port. If I send 0x00 to the data register then toggle strobe, my LED on D3 turns off. And if i send 0xFF then toggle strobe, the LED turns on. But if I send 0x0F (16) only D4 should turn on, but D3 still turns on!

Very sorry if I'm missing something very simple, but i've read loads on the net about it and still can't figure it out.

Any suggestions welcome!
Thankyou all.

jOe

we are all of us living in the gutter.
But some of us are looking at the stars.
 
0x0F is 15, not 16. So it will turn on D0, D1, D2, and D3. You need 0x10 instead.

About pins 2-4, did you follow the diagram on this page? Beware, the figure at the bottom is for the female end. If you're looking at the male end, it will be the mirror-image of that. Maybe you were actually looking at pins 10-12? If D0-D2 really wasn't connected, there's on way you could get anything to work with it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top