Write select bits (masked and⁄or term) to port B
Description:
This is a function that writes masked values to port B when the port is set as an output. The net result of writing masked values is that only the specified bits will be written. The resulting port condition is the logic combination of the current port state ANDed with the first term and then ORed with the second. This command can affect any number of lines on the port.
Command Syntax: (USBm.dll)
USBm_WriteBBit( device, and_term, or_term )
The USBm_WriteBBit function syntax has these parts:
Part | Description |
device | A zero-based index to address the appropriate USB device. |
and_term | Bits in and_term that are 0 force the line to be a zero. The set bits act as a “don’t care”. Think of the 0 positions in and_term as “turn off”. |
or_term | Bits in or_term that are 1 force the output line high, the bits set to 0 are don’t-cares. Think of the 1 positions in or_term as “turn on”. |
Remarks:
Port A does not have to have all 8 bits set to output for this to work. You can have a mix of inputs and outputs on the port and this command will set high or low only those lines that are output.
For setting (to 1) and resetting (to 0) individual output lines one line at a time use the SetBit and ResetBit commands.
VB Declaration
Public Declare Function USBm_WriteBBit _ Lib “USBm.dll” _ (ByVal device As Byte, _ ByVal and_term As Byte, _ ByVal or_term As Byte) _ As Integer |
VB Example
USBm_WriteBBit 2, &H0F, &H00 |
This code fragment addresses port B of device 2 It sets the uppor nibble (higher 4 lines) low while allowing the lower nibble to remain unchanged.
C Prototype
int USBm_WriteBBit( unsigned char device, unsigned char andterm, unsigned char orterm ); |
C Example
RobotBASIC
usbm_WriteBBit(ne_DeviceNumber,ne_AndingMask, ne_OringMask)
Returns true if successful, false otherwise. This function reads the current status of the pins in the A⁄B port and then ands the value with the anding mask, then the new value is ored with the oring mask, then the result is written to port A⁄B. Note: you can also use the ReadA⁄B() function then manipulate the byte returned using RB functions or operators and then use Write⁄AB() to write the result to the port. This perfoms the same action.
Raw Command Format:
Byte Number | Description |
0 | 04h: WriteBBitCmd |
1 | AND term (off term) |
2 | OR term (on term) |
3 | <not used> |
4 | <not used> |
5 | <not used> |
6 | <not used> |
7 | <not used> |
Raw Command Format Details:
Byte 0 contains the command. Byte 1 is the AND term, byte 2 is the OR term. Byte 3 through byte 7 are unused.
Bits in the AND term that are 0 force the line to be a zero. The set bits act as a “don’t care”. Think of the 0 positions in the AND term as “turn off”.
Bits in the OR term that are 1 force the output line high, the bits set to 0 are don’t-cares. Think of the 1 positions in the OR term as “turn on”.
Raw Command Response Format:
Byte Number | Description |
0 | 04h: InitPortsCmd |
1 | <not used> |
2 | <not used> |
3 | <not used> |
4 | <not used> |
5 | <not used> |
6 | <not used> |
7 | <not used> |
Raw Command Response Format Details:
Byte 0 contains the command. Byte 1 through byte 7 are unused.
Raw Command Example Usage:
Set every line in the port to output using the direction command. Set the entire port to FFh using the port write command.
Now set the lower nibble (lower 4 lines) low. The AND term should be F0h, the OR term would then be 00h (or even F0h).