30.10.2014 Views

o_195h4n6al16jb186b1b2qs7fgssa.pdf

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

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

Language Tools Libraries<br />

DS51456B-page 114 2004 Microchip Technology Inc.<br />

ReadTimer23<br />

ReadTimer45<br />

Description: This function reads the contents of the 32-bit Timer register.<br />

Include: timer.h<br />

Prototype: unsigned long ReadTimer23(void);<br />

unsigned long ReadTimer45(void);<br />

Arguments: None<br />

Return Value: None<br />

Remarks: This function returns the contentsof the 32-bit TMR register.<br />

Source File: ReadTimer23.c<br />

ReadTimer45.c<br />

Code Example: unsigned long timer23_value;<br />

timer23_value = ReadTimer23();<br />

WriteTimer1<br />

WriteTimer2<br />

WriteTimer3<br />

WriteTimer4<br />

WriteTimer5<br />

Description: This function writes the 16-bit value into the Timer register.<br />

Include: timer.h<br />

Prototype: void WriteTimer1(unsigned int timer);<br />

void WriteTimer2(unsigned int timer);<br />

void WriteTimer3(unsigned int timer);<br />

void WriteTimer4(unsigned int timer);<br />

void WriteTimer5(unsigned int timer);<br />

Arguments: timer This is the 16-bit value to be stored into TMR register.<br />

Return Value: None<br />

Remarks: None<br />

Source File: WriteTimer1.c<br />

WriteTimer2.c<br />

WriteTimer3.c<br />

WriteTimer4.c<br />

WriteTimer5.c<br />

Code Example: unsigned int timer_init = 0xAB;<br />

WriteTimer1(timer_init);<br />

dsPIC Peripheral Libraries<br />

2004 Microchip Technology Inc. DS51456B-page 115<br />

# include<br />

# include<br />

int timer_value;<br />

khoảng trống __attribute __ ((__ interrupt__)) _T1Interrupt (void)<br />

{<br />

PORTDbits.RD1 = 1; / * Tắt đèn LED trên RD1 * /<br />

(0) WriteTimer1;<br />

IFS0bits.T1IF = 0; / * Thơi gian gián đoạn rõ ràng cờ * /<br />

}<br />

int main (void)<br />

{<br />

int match_value;<br />

TRISDbits.TRISD1 = 0;<br />

PORTDbits.RD1 = 1; / * Tắt đèn LED trên RD1 * /<br />

/ * Cho phép ngắt Timer1 và ưu tiên để "1" * /<br />

ConfigIntTimer1 (T1_INT_PRIOR_1 & T1_INT_ON);<br />

(0) WriteTimer1;<br />

match_value = 0xFFF;<br />

OpenTimer1 (T1_ON & T1_GATE_OFF & T1_IDLE_STOP &<br />

T1_PS_1_1 & T1_SYNC_EXT_OFF &<br />

T1_SOURCE_INT, match_value);<br />

/ * Chờ cho đến khi bộ đếm thời gian phù hợp với giá trị khoảng thời gian * /<br />

trong khi (1)<br />

{<br />

timer_value = ReadTimer1 ();<br />

if (timer_value> = 0x7FF)<br />

{<br />

PORTDbits.RD1 = 0; / * Bật đèn LED trên RD1 * /<br />

}<br />

}<br />

CloseTimer1 ();<br />

}<br />

SetPriorityIntT1<br />

SetPriorityIntT2<br />

SetPriorityIntT3<br />

SetPriorityIntT4<br />

SetPriorityIntT5<br />

Mô tả: Điều này đặt ra ưu tiên vĩ mô cho giờ gián đoạn.<br />

Bao gồm: timer.h

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

Saved successfully!

Ooh no, something went wrong!