不知道你的i=0,i
# include
unsigned char ms = 0;
void main(void)
{
TMOD = 0x10;//选择T1方式1
EA = 1;
ET1 = 1;//开中断
TL1 = (65536-50000)%256;
TH1 = (65536-50000)/256;
TR1 = 1; //开定时
P0 = 0xff;//开始全亮
while(1);
}
void Time1(void) interrupt 1 using 3
{
TH1 = (65536-50000)/256;
TL1 = (65536-50000)%256;
ms++;
if(ms == 10)//0.5S
P0 = 0x00;//全灭
if(ms == 20)//1s
{
P0 = 0xff;//全亮
ms = 0;
}
}
不明白为什么非要用for语句,换换行不,看我的程序能用不。
void clock_T0(void) interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-u_50000)%256;
if(i++==10) //10次中断后定时约0.5S
{
i=0; //次数归0
P0=~P0;//执行语句
}
}
这个是T0定时器中断函数,该成T1不难。
设置1个全局变量
unsigned char i;
void main()
{
i=0;
TMOD=0x02;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
IE=0x82;
TR0=1;
while(1);
}
void Timer0_Inter () interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
if(i<10)
{
i++;
return;
}
i=0;
//定时0.5s处理程序
}