17.02.2015 Views

CCS C Compiler Manual PCB / PCM / PCH

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Functional Overview<br />

#DEVICE ADC=10<br />

...<br />

long value;<br />

...<br />

setup_adc(ADC_CLOCK_INTERNAL); //enables the a/d module<br />

//and sets the clock to internal adc clock<br />

setup_adc_ports(ALL_ANALOG); //sets all the adc pins to analog<br />

set_adc_channel(0); //the next read_adc call will read channel 0<br />

delay_us(10);<br />

//a small delay is required after setting the channel<br />

//and before read<br />

value=read_adc();<br />

//starts the conversion and reads the result<br />

//and store it in value<br />

read_adc(ADC_START_ONLY); //only starts the conversion<br />

value=read_adc(ADC_READ_ONLY); //reads the result of the last conversion and store it in<br />

//value. Assuming the device hat a 10bit ADC module,<br />

//value will range between 0-3FF. If #DEVICE ADC=8<br />

had //been used instead the result will yield 0-FF. If<br />

#DEVICE //ADC=16 had been used instead the result<br />

will yield 0-//FFC0<br />

Analog Comparator<br />

These functions set up the analog comparator module. Only available in some devices.<br />

Relevant Functions:<br />

setup_comparator(mode)<br />

Relevant Preprocessor:<br />

None<br />

Relevant Interrupts:<br />

INT_COMP<br />

Relevant Include Files:<br />

None, all functions built-in<br />

Relevant getenv() Parameters:<br />

Returns 1 if the device has a<br />

comparator<br />

Enables and sets the analog comparator module. The options<br />

vary depending on the chip. Refer to the header file for<br />

details.<br />

Interrupt fires on comparator detect. Some chips have more<br />

than one comparator unit, and thus, more interrupts.<br />

COMP<br />

Example Code:<br />

43

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

Saved successfully!

Ooh no, something went wrong!