|
目的是想使用定時(shí)器1控制定時(shí)器0的啟動(dòng)(定時(shí)器每隔5檢測(cè)一次是否設(shè)置倒計(jì)時(shí)時(shí)間,如果設(shè)置測(cè)啟動(dòng)定時(shí)器0進(jìn)行倒計(jì)時(shí),否側(cè)不啟動(dòng))
定時(shí)部分程序
void Time0_Init()
{
count = 0;
min = 1;
sec = 0;
mTimer0Clk12DivFsys(); //T0定時(shí)器時(shí)鐘設(shè)置
mTimer1Clk12DivFsys(); //T1定時(shí)器時(shí)鐘設(shè)置
mTimer_x_ModInit(0,1); //T0定時(shí)器模式設(shè)置16位定時(shí)器
mTimer_x_ModInit(1,1); //T1定時(shí)器模式設(shè)置16位定時(shí)器
mTimer_x_SetData(0,0xC350); //T0定時(shí)器賦值5MS
mTimer_x_SetData(1,0xC350); //T1定時(shí)器賦值5MS
mTimer0RunCTL(0); //T0定時(shí)器啟動(dòng)
mTimer1RunCTL(1); //T1定時(shí)器啟動(dòng)
ET0 = 1; //T0定時(shí)器中斷開(kāi)啟
ET1 = 1; //T1定時(shí)器中斷開(kāi)啟
}
void mTimer0Interrupt( void ) interrupt INT_NO_TMR0 using 1 //timer0中斷服務(wù)程序,使用寄存器組1
{
mTimer_x_SetData(0,0xC350); //非自動(dòng)重載方式需重新給TH0和TL0賦值
count++;
if(count==10)
{
count=0;
if(sec==0)
{
if(min!=0)
{
sec=59;
min--;
}
else
{
mTimer0RunCTL(0); //T0定時(shí)器停止
}
}
else sec--;
}
}
//主要是控制定時(shí)器1的中斷程序,如果加入這個(gè)就不能使用,主要是什么問(wèn)題呢,
void mTimer1Interrupt( void ) interrupt INT_NO_TMR1 using 2 //timer1中斷服務(wù)程序,使用寄存器組2
{
mTimer_x_SetData(1,0xC350);
cnt++;
if(cnt>=15) //計(jì)時(shí)3s
{
cnt=0;
if(key1==1&&key2==1&&(min>0||sec>0)) //按鍵松開(kāi),并且有設(shè)置時(shí)間
{
mTimer0RunCTL(1); //開(kāi)啟定時(shí)器0;
}
}
}
|
|