17.02.2015 Views

CCS C Compiler Manual PCB / PCM / PCH

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Built-in Functions<br />

i2c_write( )<br />

Syntax:<br />

Parameters:<br />

Returns:<br />

Function:<br />

Availability:<br />

Requires:<br />

Examples:<br />

i2c_write (data)<br />

i2c_write (stream, data)<br />

data is an 8 bit int<br />

stream - specify the stream defined in #USE I2C<br />

This function returns the ACK Bit.<br />

0 means ACK, 1 means NO ACK, 2 means there was a collision if in<br />

Multi_Master Mode.<br />

This does not return an ACK if using i2c in slave mode.<br />

Sends a single byte over the I2C interface. In master mode this function will<br />

generate a clock with the data and in slave mode it will wait for the clock from<br />

the master. No automatic timeout is provided in this function. This function<br />

returns the ACK bit. The LSB of the first write after a start determines the<br />

direction of data transfer (0 is master to slave). Note that specific I2C protocol<br />

depends on the slave device.<br />

All devices.<br />

#USE I2C<br />

long cmd;<br />

...<br />

i2c_start();<br />

// Start condition<br />

i2c_write(0xa0);// Device address<br />

i2c_write(cmd);// Low byte of command<br />

i2c_write(cmd>>8);// High byte of command<br />

i2c_stop(); // Stop condition<br />

Example Files: ex_extee.c with 2416.c<br />

Also See:<br />

i2c_poll, i2c_speed, i2c_start, i2c_stop, i2c_slaveaddr, i2c_isr_state, i2c_read,<br />

#USE I2C, I2C Overview<br />

input( )<br />

Syntax:<br />

Parameters:<br />

value = input (pin)<br />

Pin to read. Pins are defined in the devices .h file. The actual value is a bit<br />

address. For example, port a (byte 5 ) bit 3 would have a value of 5*8+3 or 43<br />

. This is defined as follows: #define PIN_A3 43 .<br />

The PIN could also be a variable. The variable must have a value equal to<br />

one of the constants (like PIN_A1) to work properly. The tristate register is<br />

205

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!