Online Development Notebook > Index > Programming Overview > Device Commands > DirectionB (and variations)

DirectionB (and variations) - Set direction of port B


Description:

This is a function that sets the i⁄o direction of port B.

Command Syntax: (USBm.dll)

USBm_DirectionB( device, dir0, dir1 )

The USBm_DirectionB function syntax has these parts:

Part Description
device A zero-based index to address the appropriate USB device.
dir0 Port direction.
dir1 Port direction.

 

USBm_DirectionBOut(device)

The USBm_DirectionBOut function syntax has these parts:

Part Description
device A zero-based index to address the appropriate USB device.

 

USBm_DirectionBIn(device)

The USBm_DirectionBIn function syntax has these parts:

Part Description
device A zero-based index to address the appropriate USB device.

 

USBm_DirectionBInPullup(device)

The USBm_DirectionBInPullup function syntax has these parts:

Part Description
device A zero-based index to address the appropriate USB device.

Remarks:

The individual pins of the ports can be set to input, or output. Input is set when both bits associated with a particular line are set to 0. There are different types of outputs available for the board, but generally setting both of the direction bits to 1 will suffice.

To set all pins in the port to input, set dir0 = 00h and dir1 = 00h. To set the highest port pin to output set the highest bit in both registers, dir0 = 80h and dir1 = 80h.

USBm_DirectionBOut will set all of the lines of port B to outputs.

USBm_DirectionBIn will set all of the lines of port B to inputs.

USBm_DirectionBInPullup will set all of the lines of port B to inputs with the internal pull up resistors enabled.

USBm_DirectionB is in all versions of the DLL. The variations are present in version 65 or newer.


VB Declaration

Public Declare Function USBm_DirectionB _
    Lib "USBm.dll" _
        (ByVal device As Byte, _
        ByVal dir0 As Byte, _
        ByVal dir1 As Byte) _
    As Integer

Public Declare Function USBm_DirectionBOut _
    Lib "USBm.dll" _
        (ByVal device As Byte) _
   As Integer

Public Declare Function USBm_DirectionBIn _
    Lib "USBm.dll" _
        (ByVal device As Byte) _
    As Integer

Public Declare Function USBm_DirectionBInPullup _
    Lib "USBm.dll" _
        (ByVal device As Byte) _
    As Integer

VB Example

USBm_DirectionB 1, 0, 0

This code fragment sets port B of device 1 to input.


C Prototype

int USBm_DirectionB( unsigned char device, unsigned char dir0, unsigned char dir1 );
int USBm_DirectionBOut( unsigned char device );
int USBm_DirectionBIn( unsigned char device );
int USBm_DirectionBInPullup( unsigned char device );

C Example

USBm_DirectionBInPullup( 0 );

This code fragment sets port B of device 0 to input, with the internal pull up resistors enabled.


RobotBASIC

usbm_DirectionB(ne_DeviceNumber,ne_PinsDirection,ne_PinsFormat)

Returns true if successful, false otherwise. This function sets the direction of each specific pin in the port. B 1 in the pin position means output, a 0 is input. The format byte should contain a 1 for each pin's position if it is output. If it is input you can have a 1 if you want an input pin with a pull up resistor, a 0 if you want the pin to have no pull up resistor.


Raw Command  Format:

Byte Number Description
0 0Ah: DirectionBCmd
1 direction0 The most significant bit of the byte value is associated with B.7
2 direction1 The most significant bit of the byte value is associated with B.7
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 written to the direction0 control register, byte 2 is written to the direction1 control register appropriate for this port. Byte 3 through byte 7 are unused.

The individual pins of the ports can be set to input, or output. Input is set when both bits associated with a particular line are set to 0. There are different types of outputs available for the board, but generally setting both of the direction bits to 1 will suffice.

Raw Command Response Format:

Byte Number Description
0 0Ah: DirectionBCmd
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:

The command 0A-00-00-00-00-00-00-00 will set the port to all input, the command 0A-FF-FF-00-00-00-00-00 will set the port to all output. To have the upper nibble be input and the lower nibble output, use the command 0A-0F-0F-00-00-00-00-00.


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 63 of 126)

This page is created with TreePad