樓主局部變量int x=0,y=0;,也就是每次進入中斷都清0,永遠也加不到想要的數。只有把x、y設為全局變量或局部靜態變量才能達到樓主想要的效果。
void timer () interrupt 1
{
static unsigned char x=0,y=0;
TH0=0x3C; //計數初值重裝載
TL0=0xB0;
if(led2==0)
{
x++;
if(x==40)
{
led2=1;
x=0;
}
}
if(led2==1)
{
y++;
if(y==200)
{
led2=0;
y=0;
}
}
} |