Analog and Digital I/O


Functions

void io_set_analog_port_count (unsigned char aports)
unsigned char io_get_analog_port_count (void)
unsigned int io_get_analog (unsigned char port)
unsigned char io_get_digital (unsigned char port)
void io_set_digital (unsigned char port, unsigned char val)
void io_set_direction (unsigned char port, io_dir_t dir)

Function Documentation

unsigned int io_get_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.

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.

unsigned char io_get_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().

void io_set_analog_port_count ( unsigned char  aports  ) 

Set the number of analog ports. On the 18F8520, we cannot arbitrarily set individual ports for analog or digital operation. For any aports between 1 and 14, or 16, ports 1 through aports are analog and the rest are 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 aports. A value of 15 and any value greater than 16 is ignored.

void io_set_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.

void io_set_direction ( unsigned char  port,
io_dir_t  dir 
)

Select the direction (IO_DIR_IN or IO_DIR_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.


Generated on Sat May 23 08:43:58 2009 for LibVexBot by  doxygen 1.5.8