?? p18f4610.c
字號:
#include <p18f4610.h>
void timer0 (void);
unsigned char time20;
void main (void)
{
unsigned char a,b,c;
a=0;
b=0;
c=0;
RCONbits.IPEN = 1;
INTCON2bits.TMR0IP = 1;//TMRO為高優先級HH
IPR2bits.TMR3IP=1;//TMR3為高優先級
INTCON = 0X20;//TMROIE使能,其它中斷關閉,總中斷關閉HH
PIE2bits.TMR3IE=1;//TMR3IE使能
T1CON=0X8F;
TMR0H=0X63;
TMR0L=0Xbf;//20ms
T0CON = 0X88;//TMRO計數開始。不分頻即Tosc/4 HH
INTCONbits.GIE= 1;//開所有中斷HH INTCON.GIE=1;//開所有中斷HH
while(1)
{
if(time20==1)
{
time20=0;
c++;
if(c==100)
{
a++;
c=0;
}
if(a==60)
{
b++;
a=0;
}
if(b==250)
b=0;
}
}
}
//高優先級中斷處理
#pragma code high_vector=0x008
void
high_vector (void)
{
_asm
goto timer0
_endasm
}
//高優先級中斷處理
//timer0中斷處理
#pragma code
#pragma interrupt timer0
void
timer0 (void)
{
if (INTCONbits.TMR0IF)
{
INTCONbits.TMR0IF = 0;
TMR0H=0X63;
TMR0L=0Xbf;//重裝20ms
time20 = 1;
}
}
//timer0中斷處理
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -