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.

FUNCTIONAL OVERVIEW<br />

I2C<br />

I2C is a popular two-wire communication protocol developed by Phillips. Many PIC<br />

microcontrollers support hardware-based I2C. <strong>CCS</strong> offers support for the hardware-based<br />

I2C and a software-based master I2C device. (For more information on the hardware-based<br />

I2C module, please consult the datasheet for you target device; not all PICs support I2C.)<br />

Relevant Functions:<br />

i2c_start()<br />

i2c_write(data)<br />

i2c_read()<br />

i2c_stop()<br />

i2c_poll()<br />

Issues a start command when in the I2C master mode.<br />

Sends a single byte over the I2C interface.<br />

Reads a byte over the I2C interface.<br />

Issues a stop command when in the I2C master mode.<br />

Returns a TRUE if the hardware has received a byte in the<br />

buffer.<br />

Relevant Preprocessor:<br />

#USE I2C<br />

Configures the compiler to support I2C to your<br />

specifications.<br />

Relevant Interrupts:<br />

#INT_SSP<br />

I2C or SPI activity<br />

#INT_BUSCOL<br />

Bus Collision<br />

#INT_I2C I2C Interrupt (Only on 14000)<br />

#INT_BUSCOL2<br />

Bus Collision (Only supported on some PIC18's)<br />

#INT_SSP2<br />

I2C or SPI activity (Only supported on some PIC18's)<br />

Relevant Include Files:<br />

None, all functions built-in<br />

Relevant getenv() Parameters:<br />

I2C_SLAVE<br />

I2C_MASTER<br />

Returns a 1 if the device has I2C slave H/W<br />

Returns a 1 if the device has a I2C master H/W<br />

Example Code:<br />

#define Device_SDA PIN_C3<br />

#define Device_SLC PIN_C4<br />

#use i2c(master,<br />

sda=Device_SDA,<br />

scl=Device_SCL)<br />

// Pin defines<br />

// Configure Device as Master<br />

41

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

Saved successfully!

Ooh no, something went wrong!