Hello, I have been having troubles reading values from the control port
(base + 2 == 0x37A) the following code sets all the pins on the control
port high. I do this by "poking" the value 4 to 0x37A. Seeing the two
least significant and the last bit are all inverted, to set the line high
you poke a zero. bit 2 is non-inverted so to set the pin high, set the bit
to 1 (which happens to be 4). Then I put it in an infinite loop... waiting
for an external device to pull a pin low. Seeing that the control port has
read/write access I should be able to tell when something pulls the line
low. Can anyone help me with this?
#define BASE_PORT 0x378
int main(int argc, char * argv)
ioperm(BASE_PORT + 2,1,1);
//Set BASE_PORT + 2 to 0100 = 0x4 (I,N,I,I)
outb(0x4,BASE_PORT + 2);
//Set up i and last state. These two will be compared
//to determine if the bits have changed.
int laststate = inb(BASE_PORT + 2)&0xF;
//display that everything is set... and the current
//value of the port.
printf("\nReady: %d\n", laststate);
//get the 4 least signifigant bits of 0x37A
i = inb(BASE_PORT + 2)&0xF;
//If all the bits are being pulled low ...
if (i == 11)
ioperm(BASE_PORT + 2,1,0);
//determine if anything has changed.
if (i != laststate)
printf("Something has changed!");
if ((i & 1) != (laststate & 1))
printf("\nBit 0 changed!\n");
if ((i & 2) != (laststate & 2))
printf("\nBit 1 changed!\n");
if ((i & 4) != (laststate & 4))
printf("\nBit 2 changed!\n");
if ((i & 8) != (laststate & 8))
printf("\nBit 3 changed!\n");
//set last state equal to i.
laststate = i;
// Samuel Ace Winchenbach
// University of Maine
// Electrical Engineering
// (207) 571-7535
-- To unsubscribe, send mail to: email@example.com --
-- with the single word "unsubscribe" in the body of the message. --
This archive was generated by hypermail 2b29 : Thu Apr 06 2000 - 22:40:52 EDT