新闻  |   论坛  |   博客  |   在线研讨会
PIC24F初始设置代码(Timer)
0750long | 2009-07-11 11:21:42    阅读:2213   发布文章

PIC24F初始设置代码(Timer)

 

void time2()
{
/* The following code example will enable Timer2 interrupts, load the Timer2
Period register and start Timer2.
When a Timer2 period match interrupt occurs, the interrupt service
routine must clear the Timer2 interrupt status flag in software.
*/
T2CON = 0x00; //Stops the Timer2 and reset control reg.
TMR2 = 0x00; //Clear contents of the timer2 register
PR2= 0x4E20; //Load the Period register with the value 0x4E20
T2CONbits.TCKPS = 1;//1:8 prescale value
IPC0bits.T2IP = 0x04; //Setup Timer2 interrupt for desired priority level
// (This example assigns level 4 priority)
IFS0bits.T2IF = 0; //Clear the Timer2 interrupt status flag
IEC0bits.T2IE = 1; //Enable Timer2 interrupts

T2CONbits.TON = 1; //Start Timer2 with prescaler settings at 1:1 and
//clock source set to the internal instruction cycle
/* Example code for Timer2 ISR*/
void __attribute__((__interrupt__, __shadow__)) _T2Interrupt(void)
{
/* Interrupt Service Routine code goes here */
IFS0bits.T2IF = 0; //Reset Timer2 interrupt flag and Return from ISR
}
}

*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。

参与讨论
登录后参与讨论
推荐文章
最近访客