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.

..<br />

..<br />

BYTE data;<br />

i2c_start();<br />

i2c_write(data);<br />

i2c_stop();<br />

// Data to be transmitted<br />

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

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

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

ADC<br />

These options let the user configure and use the analog to digital converter module. They are<br />

only available on devices with the ADC hardware. The options for the functions and directives<br />

vary depending on the chip and are listed in the device header file. On some devices there are<br />

two independent ADC modules, for these chips the second module is configured using<br />

secondary ADC setup functions (Ex. setup_ADC2).<br />

Relevant Functions:<br />

setup_adc(mode)<br />

setup_adc_ports(value)<br />

set_adc_channel(channel)<br />

read_adc(mode)<br />

adc_done()<br />

Sets up the a/d mode like off, the adc clock etc.<br />

Sets the available adc pins to be analog or digital.<br />

Specifies the channel to be use for the a/d call.<br />

Starts the conversion and reads the value. The mode<br />

can also control the functionality.<br />

Returns 1 if the ADC module has finished its conversion.<br />

Relevant Preprocessor:<br />

#DEVICE ADC=xx<br />

Configures the read_adc return size. For example, using<br />

a PIC with a 10 bit A/D you can use 8 or 10 for xx- 8 will<br />

return the most significant byte, 10 will return the full A/D<br />

reading of 10 bits.<br />

Relevant Interrupts:<br />

INT_AD<br />

INT_ADOF<br />

Interrupt fires when a/d conversion is complete<br />

Interrupt fires when a/d conversion has timed out<br />

Relevant Include Files:<br />

None, all functions built-in<br />

Relevant getenv() parameters:<br />

ADC_CHANNELS<br />

ADC_RESOLUTION<br />

Number of A/D channels<br />

Number of bits returned by read_adc<br />

Example Code:<br />

42

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

Saved successfully!

Ooh no, something went wrong!