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 />

Relevant Interrupts:<br />

INT_TIMER1<br />

Interrupt fires when timer1 overflows<br />

Relevant Include Files:<br />

None, all functions built-in<br />

Relevant getenv() parameters:<br />

TIMER1<br />

Returns 1 if the device has timer1<br />

Example Code:<br />

For PIC18F452<br />

setup_timer_1(T1_DISABLED);<br />

//disables timer1<br />

or<br />

setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); //sets the internal clock as source<br />

//and prescale as 8. At 20Mhz timer1 will<br />

increment<br />

//every 1.6us in this setup and overflows every<br />

//104.896ms<br />

set_timer1(0); //this sets timer1 register to 0<br />

time=get_timer1();<br />

//this will read the timer1 register value<br />

Timer2<br />

These options lets the user configure and use timer2. The clock/counter is 8-bit on pic16s and<br />

pic18s. It counts up and also provides interrupt on overflow. The options available differ and are<br />

listed in the device header file.<br />

Relevant Functions:<br />

setup_timer_2<br />

(mode,period,postscale)<br />

set_timer2(value)<br />

value=get_timer2<br />

Disables or sets the prescale, period and a postscale for<br />

timer2<br />

Initializes the timer2 clock/counter<br />

Returns the value of the timer2 clock/counter<br />

Relevant Preprocessor:<br />

None<br />

Relevant Interrupts:<br />

INT_TIMER2<br />

Interrupt fires when timer2 overflows<br />

Relevant Include Files:<br />

71

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

Saved successfully!

Ooh no, something went wrong!