B&B Electronics Parallel Port Input/Output Converter PPIO User Manual

Page 23

Advertising
background image

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

21

Notice that in the binary representation of the mask value, line

zero’s mask has bit number zero set, and line one’s mask has bit
number one set, etc. So, instead of retrieving the mask value from a
table, the value is calculated by shifting 00000001b (1 decimal, 01
hexadecimal) right the same number of times as the desired line
number. Once the mask value is calculated, it is bitwise ANDed with
Input_Byte. If the resulting value is non-zero, the line is ON and a
boolean TRUE is returned, otherwise a boolean FALSE is returned.

For example:
Line_Number = 3
Status Register Value =

01010101b

Control Register Value =

10101010b


01010101b (Status Register)

AND 11110000b (F0h mask)

01010000b

10101010b (Control Register)

AND 00001111b (0Fh mask)

00001010b ——> OR

00001010b

01011010b


00000001b (1 decimal)
shift-right 3 (Line_Number) = AND 00001000b (bit mask)

00001000b


The function, Output_Bit(), returns the status of the selected

output line. The function is defined as:

boolean Output_Bit(unsigned char Line_Number)
{

return (((Output_Byte & (1 << Line_Number)) != 0));

}

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:

Advertising