Set direction of port A
Description:
This is a function that sets the i⁄o direction of port A.
Command Syntax: (USBm.dll)
USBm_DirectionA( device, dir0, dir1 )
The USBm_DirectionA 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_DirectionAOut(device)
The USBm_DirectionAOut function syntax has these parts:
Part | Description |
device | A zero-based index to address the appropriate USB device. |
USBm_DirectionAIn(device)
The USBm_DirectionAIn function syntax has these parts:
Part | Description |
device | A zero-based index to address the appropriate USB device. |
USBm_DirectionAInPullup(device)
The USBm_DirectionAInPullup 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_DirectionAOut will set all of the lines of port A to outputs.
USBm_DirectionAIn will set all of the lines of port A to inputs.
USBm_DirectionAInPullup will set all of the lines of port A to inputs with the internal pull up resistors enabled.
USBm_DirectionA is in all versions of the DLL. The variations are present in version 65 or newer.
VB Declaration
Public Declare Function USBm_DirectionA _ Lib “USBm.dll” _ (ByVal device As Byte, _ ByVal dir0 As Byte, _ ByVal dir1 As Byte) _ As Integer Public Declare Function USBm_DirectionAOut _ Lib “USBm.dll” _ (ByVal device As Byte) _ As Integer Public Declare Function USBm_DirectionAIn _ Lib “USBm.dll” _ (ByVal device As Byte) _ As Integer Public Declare Function USBm_DirectionAInPullup _ Lib “USBm.dll” _ (ByVal device As Byte) _ As Integer |
VB Example
USBm_DirectionA 1, 0, 0 |
This code fragment sets port A of device 1 to input.
C Prototype
int USBm_DirectionA( unsigned char device, unsigned char dir0, unsigned char dir1 ); int USBm_DirectionAOut( unsigned char device ); int USBm_DirectionAIn( unsigned char device ); int USBm_DirectionAInPullup( unsigned char device ); |
C Example
USBm_DirectionAInPullup( 0 ); |
This code fragment sets port A of device 0 to input, with the internal pull up resistors enabled.
RobotBASIC
usbm_DirectionA(ne_DeviceNumber,ne_PinsDirection,ne_PinsFormat)
Returns true if successful, false otherwise. This function sets the direction of each specific pin in the port. A 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 | 09h: DirectionACmd |
1 | direction0 The most significant bit of the byte value is associated with A.7 |
2 | direction1 The most significant bit of the byte value is associated with A.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 | 09h: DirectionACmd |
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 09-00-00-00-00-00-00-00 will set the port to all input, the command 09-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 09-0F-0F-00-00-00-00-00.