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.

Common Questions & Answers<br />

RAM is also used for expression evaluation when the expression is complex. The more complex<br />

the expression, the more scratch RAM locations the compiler will need to allocate to that<br />

expression. The RAM allocated is reserved during the execution of the entire function but may<br />

be re-used between expressions within the function. The total RAM required for a function is the<br />

sum of the parameters, the local variables and the largest number of scratch locations required<br />

for any expression within the function. The RAM required for a function is shown in the call tree<br />

after the RAM=. The RAM stays used when the function calls another function and new RAM is<br />

allocated for the new function. However when a function RETURNS the RAM may be re-used<br />

by another function called by the parent. Sequential calls to functions each with their own local<br />

variables is very efficient use of RAM as opposed to a large function with local variables<br />

declared for the entire process at once.<br />

Be sure to use SHORT INT (1 bit) variables whenever possible for flags and other boolean<br />

variables. The compiler can pack eight such variables into one byte location. The compiler does<br />

this automatically whenever you use SHORT INT. The code size and ROM size will be smaller.<br />

Finally, consider an external memory device to hold data not required frequently. An external 8<br />

pin EEPROM or SRAM can be connected to the PIC® with just 2 wires and provide a great deal<br />

of additional storage capability. The compiler package includes example drivers for these<br />

devices. The primary drawback is a slower access time to read and write the data. The SRAM<br />

will have fast read and write with memory being lost when power fails. The EEPROM will have a<br />

very long write cycle, but can retain the data when power is lost.<br />

What is an easy way for two or more PICs® to communicate?<br />

There are two example programs (EX_PBUSM.C and EX_PBUSR.C) that show how to use a<br />

simple one-wire interface to transfer data between PICs®. Slower data can use pin B0 and the<br />

EXT interrupt. The built-in UART may be used for high speed transfers. An RS232 driver chip<br />

may be used for long distance operations. The RS485 as well as the high speed UART require<br />

2 pins and minor software changes. The following are some hardware configurations.<br />

363

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

Saved successfully!

Ooh no, something went wrong!