/* *************************************************************** This function determines whether a bit within the requested port is set. The value (1 or 0) is returned in the variable pointer sent to the function. Port may be PORTA, PORTB, PORTCL or PORTCH. BitNum must be in the range 0-7. ****************************************************************** */ int DBitIn(int Port, int BitNum, int *BitData) { int mask, data; if ((Port==PORTA) || (Port==PORTB) || (Port==PORTCL) || (Port==PORTCH) || (Port==AUXPORT)) data = inb(Port); else return(2); /* error - illegal port */ switch(BitNum) { case 0: mask = 0x01; /* bit zero mask */ break; case 1: mask = 0x02; /* bit one mask */ break; case 2: mask = 0x04; /* bit two mask */ break; case 3: mask = 0x08; /* bit three mask */ break; case 4: mask = 0x10; /* bit four mask */ break; case 5: mask = 0x20; /* bit five mask */ break; case 6: mask = 0x40; /* bit six mask */ break; case 7: mask = 0x80; /* bit seven mask */ break; default: return(4); /* error - bit range must be 0-7 */ break; } *BitData = Logic(mask, data); /* determine if bit is on or off */ return(0); /* no errors detected */ } /* ******************************************************************* This function determines whether the requested bit is a one or a zero by using the mask and data values from the previous function. ********************************************************************** */ int Logic(int mask, int data) { int x; unsigned y; y = data & mask; /* mask out all but the requested bit */ if (y == mask) x=1; /* bit is set */ else x=0; /* bit is not set */ return(x); /* return the value of the requested bit */ }