|Online Development Notebook > Index > Programming Overview > Device Commands > WriteBBit|
WriteBBit - Write select bits (masked and⁄or term) to port B
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:
|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".|
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.
|Public Declare Function USBm_WriteBBit _|
Lib "USBm.dll" _
(ByVal device As Byte, _
ByVal and_term As Byte, _
ByVal or_term As Byte) _
|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.
|int USBm_WriteBBit( unsigned char device, unsigned char andterm, unsigned char orterm );|
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:
|1||AND term (off term)|
|2||OR term (on term)|
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:
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).
Hardware: U401 USB Interface U421 USB Interface U451 USB Interface
Programming: USBm DLL Programming Download Files
Application Notes: U4x1 Application Notes Misc Applications and Information FAQ
While every effort has been made to make sure that the information posted on this site is correct, the author can not be held liable for any damages whatsoever for losses as a result of the application of this information. Use this information at your own risk.
USBmicro can design your custom and semi-custom USB product. Email about USB design can be directed to " Robert " at usbmicro.com.
Copyright © USBmicro, L.L.C., 2002-2010