22
PPIO2899 Manual
B&B Electronics Mfg Co Inc – 707 Dayton Rd - PO Box 1040 - Ottawa IL 61350 - Ph 815-433-5100 - Fax 815-433-5104
Line_Number = 3
Output_Byte = 10101010b
00000001b
shift-right 3 (Line_Number) =
00001000b
AND 10101010b (Output_Byte)
00001000b
The function, Set_Output_Bit(), sets the selected output line ON
of OFF. The function is defined as:
void Set_Output_Bit(unsigned char Line_Number, boolean Status)
{
Output_Byte = (Output_Byte & ((1 << Line_Number) ^ 0xFF))
| (Status << Line_Number);
outport(Base_Address, Output_Byte);
}
The variable, Output_Byte, stores the status of the output lines.
When a bit in Output_Byte is set to a one, its corresponding output
line is ON, when it is set to a zero, the line is OFF. To set a bit to the
specified status, the bit must first be cleared. To do this, 00000001b
is shifted right for the desired line number and bitwise exclusive
ORed with FFh (255 decimal, 11111111 binary) to produce a mask
value. This mask value has all bits set to one except for the desired
line. It is bitwise ANDed with Output_Byte to clear the desired bit.
Now, having cleared the bit, it can be set to the specified state.
Since the state is either a zero or one, we can shift it right for the
desired line number to get another mask value. This value is then
bitwise ORed with the cleared value to obtain the new value of
Output_Byte. The final step is to write Output_Byte to the parallel
port.