B&B Electronics PPIO manual

Page 23

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:

PPIO2899 Manual

21

B&B Electronics Mfg Co Inc – 707 Dayton Rd - PO Box 1040 - Ottawa IL 61350 - Ph 815-433-5100 - Fax 815-433-5104

Image 23
Contents Not Recommended for New Installations Table of Contents Introduction Packing List PC Parallel Port Description Page BIT PPIO2899 Manual Ppio Description & Connection PPIO2899 Manual Controlling the Ppio Using Gwbasic Bit Force I/O on Force I/O OFF Low High Page Begin Controlling the Ppio Using PascalElse Mask Value Function OutputBit BitNumberBYTE Byte Procedure SetOutputBit BitNumber,OutputBYTE XOR Controlling the Ppio Using C Void SetIRQOffvoid Outport ControlAddress Mask Value Page Page New PPIO2899 Manual Page Interfacing to the Ppio PPIO2899 Manual Example USE of the Ppio Page REM IB is the Input Byte and OB is the Output Byte Appendix Hexadecimal NumbersBinary Numbers