OpenVex  0.5.0
Enumerations | Functions
Analog and Digital I/O

Enumerations

enum  io_dir_t { IO_DIRECTION_OUT =0, IO_DIRECTION_IN =1 }
 

Functions

status_t io_set_analog_port_count (unsigned char ports)
 
unsigned char io_get_analog_port_count (void)
 
unsigned int io_read_analog (unsigned char port)
 
unsigned char io_read_digital (unsigned char port)
 
status_t io_write_digital (unsigned char port, unsigned char val)
 
status_t io_set_direction (unsigned char port, io_dir_t dir)
 

Detailed Description

These functions provide basic input, output, and configuration for digital and analog I/O ports.

Enumeration Type Documentation

◆ io_dir_t

enum io_dir_t

Digital I/O direction constants for use with io_set_direction().

Enumerator
IO_DIRECTION_OUT 

Set digital port for output

IO_DIRECTION_IN 

Set digital port for input

Function Documentation

◆ io_get_analog_port_count()

unsigned char io_get_analog_port_count ( void  )

Returns the current number of I/O ports configured for analog input. See io_set_analog_port_count() for more information.

Returns
The number of analog ports currently configured.

◆ io_read_analog()

unsigned int io_read_analog ( unsigned char  port)

Read analog input from I/O port "port". The port must be among those configured for analog input (see io_set_analog_port_count()). The analog value returned contains 10 significant bits of data, and ranges from 0x000 to 0x3ff. The meaning of the value returned is dependent on the sensor connected to the port. See the sensor documentation, or figure it out by trial and error.

Parameters
portThe analog port to be read.
Returns
Analog value from 1 to 0x3ff on success, OV_BAD_PARAM if the specified port is not valid or not configured for analog input.

◆ io_read_digital()

unsigned char io_read_digital ( unsigned char  port)

Return the sampled value (0 or 1) from port. The port must be among those configured for digital input (see io_set_analog_port_count()) and the port must have been configured for output using io_set_port_direction().

Parameters
portThe digital port to be read.
Returns
0 or 1 on success, OV_BAD_PARAM if the port is invalid or not configured for digital input.

◆ io_set_analog_port_count()

status_t io_set_analog_port_count ( unsigned char  ports)

Set the number of analog ports. On the 18F8520, we cannot arbitrarily set individual ports for analog or digital operation. For any value of ports between 1 and 14, or 16, ports 1 through ports are set for analog operation and the rest are set for digital. It is not possible to set the controller for 15 analog ports. The number of analog/digital ports is specified by 4 bits in hardware, which means there are 16 possible values. There are 17 possible numbers of analog ports (0 to 16 inclusive). The PIC hardware designers chose to support values of 0 through 14 and 16 analog ports. Hence, these are the allowed values for ports. A value of 15 and any value greater than 16 is ignored.

Parameters
portsThe number of I/O ports to use for analog input.
Returns
OV_OK on success, OV_BAD_PARAM for invalid port count.

◆ io_set_direction()

status_t io_set_direction ( unsigned char  port,
io_dir_t  dir 
)

Select the direction (IO_DIRECTION_IN or IO_DIRECTION_OUT) for the given port. The port must be among those configured for digital I/O (See io_set_analog_port_count()). On the Vex, analog ports are input only.

Parameters
portPort to configure.
dirIO_DIRECTION_IN or IO_DIRECTION_OUT.
Returns
OV_OK on success, OV_BAD_PARAM if port is invalid or not configured for digital I/O.

◆ io_write_digital()

status_t io_write_digital ( unsigned char  port,
unsigned char  val 
)

Set the output value of "port". Port must be among those configured for digital I/O (see io_set_analog_port_count()) and must have been previously configured for digital output using io_set_direction(). The argument "val" must be 0 or 1.

Parameters
portDigital port to write to.
valValue of 0 or 1 to write to port.
Returns
OV_OK on success, OV_BAD_PARAM if port is invalid or not configured for digital output.