Online Development Notebook > Index > Programming Overview > Device Commands > WriteABit

WriteABit - Write select bits (masked and⁄or term) to port A


Description:

This is a function that writes masked values to port A 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_WriteABit( device, and_term, or_term )

The USBm_WriteABit 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_WriteABit _
    Lib "USBm.dll" _
        (ByVal device As Byte, _
        ByVal and_term As Byte, _
        ByVal or_term As Byte) _
    As Integer

VB Example

frmStatus.lstDevices.AddItem " "
USBm_WriteABit 5, &HFF, &H0F

This code fragment addresses port A of device 5 It sets the lower nibble (lower 4 lines) high. The AND term can be FFh (all don't-cares), the OR term would then be 0Fh.


C Prototype

int USBm_WriteABit( unsigned char device, unsigned char andterm, unsigned char orterm );

C Example


RobotBASIC

usbm_WriteABit(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 WriteA⁄B() to write the result to the port. This perfoms  the same action.


Raw Command  Format:

Byte Number Description
0 03h: WriteABitCmd
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 03h: WriteABitCmd
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 00h using the port write command.

Now set the lower nibble (lower 4 lines) high. The AND term can be FFh (all don't-cares), the OR term would then be 0Fh.


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

Previous  |  Next ]     [ Up  |  First  |  Last ]     (Article 56 of 126)

This page is created with TreePad