View Single Post
  #1 (permalink)  
Old October 25th, 2011, 03:12 PM
amador-batalha amador-batalha is offline
Registered User
 
Join Date: Oct 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Can´t read from parallel port

Hello.

I am trying to write a program for ms-dos 6.22, with Turbo C++ 3.0, that detects some push buttons connected to the data pins of the parallel port.
All the program does, at this stage, is read the data register 5 times per second and output it to the screen as a 2-digit hexadecimal code. So, when you press a button, the code should change. But it doesn't. The program just keeps printing code AA, which is odd, because when all the buttons are off, the code should be FF. Here's the code:
Code:
#include <dos.h>
#include <stdio.h>
#include <conio.h>


#define PORT    0x378

#define DATA    (PORT+0)
#define STATUS  (PORT+1)
#define CONTROL (PORT+2)


int main(void)
{
	outportb(CONTROL, 0x20); // Put parallel port in reading mode

	puts("Press any key to quit\n");

	while (!kbhit()) {
		int data = inportb(DATA); // Read the data register
		printf("%02X  ", data);
		delay(200);
	}

	outportb(CONTROL, 0x00); // Put parallel port in writing mode

	return 0;
}
I have adapted this program for Windows 7 and Visual C++ 2010 Express, using inpout32.dll, and it still doesn't work.

Does anyone know why I am failing to read the parallel port?
Reply With Quote