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.

PreProcessor<br />

TICK=xx<br />

Sets the desired time for 1 tick. xx can be used with ns(nanoseconds), us<br />

(microseconds), ms (milliseconds), or s (seconds). If the desired tick time can't be<br />

achieved it will set the time to closest achievable time and will generate a warning<br />

specifying the exact tick time. The default value is 1us.<br />

BITS=x<br />

Sets the variable size used by the get_ticks() and set_ticks() functions for<br />

returning and setting the tick time. x can be 8 for 8 bits, 16 for 16 bits or 32 for<br />

32bits. The default is 32 for 32 bits.<br />

ISR<br />

Uses the timer's interrupt to increment the upper bits of the tick timer. This mode<br />

requires the the global interrupt be enabled in the main program.<br />

NOISR<br />

The get_ticks() function increments the upper bits of the tick timer. This requires<br />

that the get_ticks() function be called more often then the timer's overflow rate.<br />

NOISR is the default mode of operation.<br />

STREAM=id<br />

Associates a stream identifier with the tick timer. The identifier may be used in<br />

functions like get_ticks().<br />

DEFINE=id<br />

Creates a define named id which specifies the number of ticks that will occur in<br />

one second. Default define name if not specified is TICKS_PER_SECOND.<br />

Define name must start with an ASCII letter 'A' to 'Z', an ASCII letter 'a' to 'z' or an<br />

ASCII underscore ('_').<br />

COUNTER or COUNTER=x<br />

Sets up specified timer as a counter instead of timer. x specifies the prescallar to<br />

setup counter with, default is1 if x is not specified specified. The function<br />

get_ticks() will return the current count and the function set_ticks() can be used to<br />

set count to a specific starting value or to clear counter.<br />

Purpose:<br />

This directive creates a tick timer using one of the PIC's timers. The tick timer is<br />

initialized to zero at program start. This directive also creates the define<br />

TICKS_PER_SECOND as a floating point number, which specifies that number of<br />

ticks that will occur in one second.<br />

Examples:<br />

#USE TIMER(TIMER=1,TICK=1ms,BITS=16,NOISR)<br />

unsigned int16 tick_difference(unsigned int16 current, unsigned int16 previous) {<br />

return(current - previous);<br />

}<br />

void main(void) {<br />

unsigned int16 current_tick, previous_tick;<br />

current_tick = previous_tick = get_ticks();<br />

while(TRUE) {<br />

current_tick = get_ticks();<br />

if(tick_difference(current_tick, previous_tick) > 1000) {<br />

147

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

Saved successfully!

Ooh no, something went wrong!