As with the function, In_Byte, the mask value is calculated by shifting 00000001b right the same number of times as the desired line number. Once the mask value is calculated, it is bitwise ANDed with Output_Byte. If the resulting value is non-zero, the line is ON and a boolean TRUE is returned, otherwise a boolean FALSE is returned. Notice that this function gets its value from Output_Byte that is set when we use the function, Set_Output_Bit. The value is not read from the port.

For example:

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:

PROCEDURE Set_Output_Bit ( Bit_Number,Output:BYTE ) ;

BEGIN

Output_Byte := ( (Output_Byte AND ( ( 1 SHL Bit_Number)

XOR $FF) ) OR (Output SHL Bit_Number) ) ;

Port [Base_Address] : = Output_Byte;

END; {Set_Output_Bit}

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.

16

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

Page 18
Image 18
B&B Electronics PPIO manual Procedure SetOutputBit BitNumber,OutputBYTE