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.

Multiple Compilation Units<br />

Multiple compilation units are only supported in the IDE compilers PCW, PCWH,<br />

PCWHD and PCDIDE. When using multiple compilation units, care must be given<br />

that pre-processor commands that control the compilation are compatible across all<br />

units. It is recommended that directives such as #FUSES, #USE and the device<br />

header file all put in an include file included by all units. When a unit is compiled it<br />

will output a relocatable object file (*.o) and symbol file (*.osym).<br />

There are several ways to accomplish this with the <strong>CCS</strong> C <strong>Compiler</strong>. All of these<br />

methods and example projects are included in the MCU.zip in the examples<br />

directory of the compiler.<br />

Full Example Program<br />

Here is a sample program with explanation using <strong>CCS</strong> C to read adc samples over rs232:<br />

///////////////////////////////////////////////////////<br />

/// This program displays the min and max of 30, ///<br />

/// comments that explains what the program does, ///<br />

/// and A/D samples over the RS-232 interface. ///<br />

///////////////////////////////////////////////////////<br />

#include <br />

#fuses NOPROTECT<br />

#use delay(crystal=20mhz)<br />

// preprocessor directive that selects<br />

// the chip PIC16F887<br />

// Code protection turned off<br />

// preprocessor directive that<br />

// specifies the clock type and speed<br />

#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) // preprocessor directive that<br />

includes<br />

// the rs232 libraries<br />

void main() {<br />

int i, value, min, max;<br />

printf("Sampling:");<br />

the<br />

}<br />

setup_port_a( ALL_ANALOG );<br />

setup_adc( ADC_CLOCK_INTERNAL );<br />

set_adc_channel( 0 );<br />

do {<br />

min=255;<br />

max=0;<br />

for(i=0; i

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

Saved successfully!

Ooh no, something went wrong!