SetDirection Method

void SetDirection(int port, int direction)

Summary

This method sets the direction register for a digital I/O port, which configures each pin (bit) of the port as an input or output. The direction of each bit of the port can be set individually, meaning that some bits of the port can be inputs at the same time that other bits on the same port are outputs. A 1-bit in the direction register causes the corresponding bit of the port to be put into output mode, while a 0-bit specifies input mode. For example, a value of 0xF0 would put bits 0-3 into input mode and bits 4-7 into output mode.

Parameters

  • port - The port number (0-5).

  • direction - The new direction register for the port.

Return Value

This method does not return a value.

Remarks

Port 3 shares its pins with the analog channels. When the ADC is enabled, all pins of port 3 are forced into input mode. The direction register of port 3 cannot be modified while the ADC is enabled.

The valid range for the direction parameter is any 8-bit number (ranges from 0 to 255). However, note that because ports 4 and 5 are single-bit ports, only bit 0 will have any effect on those ports.

For your convenience, constants for the direction parameter are provided that configure the port bits to be all inputs or all outputs. These are, respectively, Eth32.DirInput and Eth32.DirOutput.

Example
Eth32 dev = new Eth32();

try
{
	// .... Your code that establishes a connection here
	
	// Configure all odd bits of port 0 as inputs and even bits as outputs
	//  Direction parameter of 10101010 binary, which is 0xAA hex or 170 decimal
	dev.SetDirection(0, 170);
}
catch (Eth32Exception e)
{
	// Handle Eth32 errors here
}
        
See Also

GetDirection Method, GetDirectionBit Method, SetDirectionBit Method