Example, Io_set_direction( ) built-in function, Syntax – Echelon Neuron C User Manual

Page 124

Advertising
background image

104

Functions

cannot specify TCCLK_40MHz or TCCLK_20MHz – no

error is issued, but the effective value used in this case is
TCCLK_10MHz).

Example

IO_1 output pulsecount clock(3) pcout;

when(...)
{
io_set_clock(pcout, 5);
// equivalent to io_set_clock(pcout, TCCLK_156k2Hz);
...
}

io_set_direction( )

Built-in Function

The io_set_direction( ) built-in function allows the application to change the
direction of any bit, nibble, or byte type I/O pin at runtime. The

dir

parameter is

optional. If not provided, io_set_direction( ) sets the direction based on the
direction specified in the declaration of

io-object-name

.

A program can define multiple types of I/O objects for a single pin. When

directions conflict and a timer/counter object is defined, the direction of the
timer/counter object is used, regardless of the order of definition. However, if the

program uses the io_set_direction( ) function for such an object, the direction is

changed as specified.

To change the direction of overlaid I/O objects, at least one of the objects must be

one of the allowed types for io_set_direction( ) and that I/O object must be used to

change directions, even if the subsequent I/O object used is a different one.

For example, if you overlaid a bit input with a oneshot output, you only can use

the bit I/O object with io_set_direction( ) to change the direction from input to

output, thus enabling the oneshot output.

Any io_changes events requested for input objects can trigger when the object is

redirected as an output, because the Neuron firmware returns the last value
output on an output object as the input value. Thus, the user might want to

qualify io_changes events with flags maintained by the program to indicate the

current direction of the device.

Syntax

typedef enum {IO_DIR_IN=0, IO_DIR_OUT=1} io_direction;

void io_set_direction (

io-object-name

, [io_direction

dir

]);

io-object-name

The I/O object name that corresponds to

io-object-name

in

the I/O declaration. This built-in function is used only for

direct I/O objects such as bit, nibble, and byte.

dir

An optional direction, using a value from the io_direction
enum shown above. If omitted, uses the declared

direction of the I/O device to set the pin direction.

Advertising