|
|
我想問(wèn)一下ch554定時(shí)器1控制定時(shí)器0啟動(dòng)的問(wèn)題,單片機(jī)步驟配置控制不了,想請(qǐng)教一下原因
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,2); //T1定時(shí)器模式設(shè)置8位自動(dòng)重裝定時(shí)器
mTimer_x_SetData(0,0xC350); //T0定時(shí)器賦值5MS
mTimer_x_SetData(1,0x0038); //T1定時(shí)器賦值5MS
mTimer0RunCTL(1); //T0定時(shí)器啟動(dòng)
mTimer1RunCTL(1); //T1定時(shí)器啟動(dòng)
ET0 = 1; //T0定時(shí)器中斷開(kāi)啟
ET1 = 1; //T1定時(shí)器中斷開(kāi)啟
EA = 1;
}
void mTimer0Interrupt( void ) interrupt INT_NO_TMR0 using 1 //timer0中斷服務(wù)程序,使用寄存器組1
{
mTimer_x_SetData(0,0xC350); //非自動(dòng)重載方式需重新給TH0和TL0賦值
count++;
if(count==20)
{
count=0;
if(sec==0)
{
if(min!=0)
{
sec=59;
min--;
}
else
{
mTimer0RunCTL(0); //T0定時(shí)器停止
}
}
else sec--;
}
}
void mTimer1Interrupt( void ) interrupt INT_NO_TMR1 using 2
{
cnt++;
if(cnt>=15) //計(jì)時(shí)3s
{
cnt=0;
if(key1==1&&key2==1&&(min>0||sec>0))
{
mTimer0RunCTL(1); //開(kāi)啟定時(shí)器0;
}
}
}
void main( )
{
Time0_Init();
Init_1621(); //初始化HT1621
HT1621_all_off(); //清空LCD顯示
while(1)
{
Write_1621(0,0xF0,4);
if(key1==0)
{
delay_ms(100);
if(key1==0)
{
if(min!=999)
{
min++;
}
}
while(!key2);
delay_ms(1000);
while(!key2);
}
if(key2==0)
{
delay_ms(100);
if(key2==0)
{
if(min!=0)
{
min--;
}
}
while(!key1);
delay_ms(1000);
while(!key1);
}
min0=min/100%10;
min1=min/10%10;
min2=min/1%10;
sec1=sec/10%10;
sec2=sec/1%10;
Display_Init(min0,min1,min2,sec1,sec2);
}
} |
|