Refer to the figure titled Figure #4 - Printer Port Test Circuitry.
This illustrates a very simple test fixture to allow you to figure out
what inversions are taking place in the hardware associated with the
printer port. Program test_prt.c sequentially turns each of the 12 LED's
on and then off and then continually loops to display the settings on
the five input switches.
/* File TEST_PRT.C ** ** Program to exercise 12 outputs and five inputs. ** ** Program sequentially turns off LEDs on Bits 7, 6, 5, ... 0 on the ** Data Port, and then Bits #, 2, 1 and 0 on the Control Port. Each ** LED is held off for nominally 1 second. Note that an LED is turned ** off with a logic one. This process is executed once. ** ** Program then loops, scanning the highest five bits on the Status Port ** and continuously displays the content in hexadecimal. ** ** P.H. Anderson, Dec 25, '95 */
#include <stdio.h> #include <dos.h> /* required for delay function */
#define DATA 0x03bc /* for the PC I used */ #define STATUS DATA+1 #define CONTROL DATA+2
void main(void) { int in, n;
outportb(DATA,0x00); /* turn on all LEDs on Data Port */ outportb(CONTROL, 0x00^0x0b); /* same with Control Port */
/* now turn off each LED on Data Port in turn by positioning a logic one in each bit position and outputing. */ for (n=7; n>=0; n++) { outportb(DATA, 0x01 << n); delay(1000); } outportb(DATA, 0x00);
/* now turnoff each LED on control port in turn ** note exclusive-or to compensate for hardware inversions */
outportb(CONTROL, 0x08^0x0b); /* bit 3 */ delay(1000); outportb(CONTROL, 0x04^0x0b); /* bit 2 */ delay(1000); outportb(CONTROL, 0x02^0x0b); /* bit 1 */ delay(1000); outportb(CONTROL, 0x01^0x0b); /* bit 0 */ delay(1000);
outportb(CONTROL, 0x00);
/* Continuously scan switches and print result in hexadecimal */
while(1) { in = (inportb(STATUS)^0x80)&0xf8; /* Note that BUSY (msbit) is inverted and only the ** five most significant bits on the Status Port are displayed. */ printf("%x\n", in); } }