PIC 定時器中斷1(外設(shè)中斷)
#include
__CONFIG(1,XT) ; //晶振為外部4M
__CONFIG(2,WDTDIS) ; //看門狗關(guān)閉
__CONFIG(4,LVPDIS) ; //禁止低電壓編程
#define uchar unsigned char
#define uint unsigned int
char shuma[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
int count=0;
char sec=0;
//中斷函數(shù)
void interrupt k(void)
{
if(TMR1IF==1) //判斷是否產(chǎn)生中斷
{
TMR1IF=0;
TMR1H=0xff; //注意要重新裝初值
TMR1L=0x06;
count++;
if(count==4000)
{
count=0;
sec++;
if(sec>9)
sec=0;
}
}
}
void display()
{
PORTD=shuma[sec];
}
void main(void)
{
ADCON1=0X06;
TRISD=0B00000000;
IPEN=0; //關(guān)閉中斷優(yōu)先級
PEIE=1; //允許所有未被關(guān)閉的外設(shè)中斷
T1CON=0x01; //使能定時器中斷1
TMR1IE=1; //使能當(dāng)前定時器中斷1
TMR1IF=0; //軟件清中斷標(biāo)志位
TMR1H=0xff; //必須手動計算,不能靠左移,右移等完成
TMR1L=0x06; //必須手動計算,不能靠左移,右移等完成
GIE=1; //開總中斷
while(1)
{
display();
}
}
評論