Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Parallel Port Programming.

Status
Not open for further replies.

lord loh.

Member
Hi,

Below is a Turbo C code for parallel port testing....

Code:
#include<stdio.h>
#include <conio.h>
#include <dos.h>

int main(void)
{
	int far *LPT1=(int far*)0x408;
	int portID=*LPT1;
	short int inData, outData;
	clrscr();
	printf("LPT1 Address is at %X\n",portID);
	while(!kbhit())
	{
		inData=inportb(portID);
		printf("Read :%X\n",inData);
		outData=inData^0xFF;
		outportb(portID,outData);
		printf("Write :%X\n",outData);
		delay(1000);
	}
	return 0;
}

When I test this code on machines with WindowsXP, I see an output like
Code:
Read : AA
Write: 55
Read: AA
Write: 55

However, when I run this code on win98 systems,
Code:
Read : AA
Write: 55
Read: 55
Write: AA

What could be the reason? I have not tested this on any other OS. How can I get over this problem.
 
The programme compiles and runs without errors....

But does not give the desired results... Moreover, the port address as obtained from the BIOS locations 0x408 and those shown in the device manager is different...
 
I think you're ignoring the fact you have Windows running! - I would suggest you use a Windows program to try and read the ports, unless you have a suitable driver DLL you can't access the ports directly, not even in a DOS window.
 
I figured so.... However, I have to use Turbo C - A requirement of the course underwhich I am developing the project..

However, I have no problems with windows 98. :?

It is not that I am totally denied access to the port in XP. The last outportb is reflected at the port after the programme terminates. I check this using LEDs. The control Register of the EPP is also seems read only. :(
 
This may help:
**broken link removed**

It has loads of info about interfacing to the parallel port and links to some freeware port drivers.
 
hi,
Have you looked at the BIOS settings for the parallel port, during boot up?.

You maybe aware that there are 3 or 4 states the parport can be set to in the BIOS.

The other point about the language you are using, you may still require a dll in the Wiindows/System directory,
to allow full control over the parport.
 
I did look into the BIOS setup to configure the parallel port... I configured it to an EPP at the address 0x378... However, in XP, inspite of this, I find it at the address 0x3BC... But, thde device managaer continues to show 0x378...
 
hi,
Do have an existing printer driver installed?
Check using the 'printer' and 'add printer' dialog boxes.
 
any reason why you need to you C? cause writing it with PYTHON and using the PYparallel module would make you life soo much easier
 
inpout32.DLL makes it easy, at least with Visual C++
You can find inpout32.DLL with code examples at:
**broken link removed**
**broken link removed**
All of these have to be in Project\ Settings\ link\ object/library modules:
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib
shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib inpout32.lib
 
inpout32.DLL makes it easy, at least with Visual C++
You can find inpout32.DLL with code examples at:
**broken link removed**
**broken link removed**
All of these have to be in Project\ Settings\ link\ object/library modules:
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib
shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib inpout32.lib

What should we do if we want to access inpout32.dll and parallel port with Turbo C/C++??
 
any reason why you need to you C? cause writing it with PYTHON and using the PYparallel module would make you life soo much easier


Because OP stated :

I have to use Turbo C - A requirement of the course underwhich I am developing the project..
 
Last edited:
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top