B&B Electronics PPIO manual

Page 24

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.

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

Image 24
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 Controlling the Ppio Using Pascal BeginElse 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 Hexadecimal Numbers AppendixBinary Numbers