你想用定時器來延時嗎?很好處理呀比如
#include
#define uchar unsigned char;
#define uint unsigned int;
uchar times;
uint delaytime;
bit flag=00h;
void t0isr() interrupt 1
{
TH0=(65536-delaytime)/256;
TL0=(65536-delaytime)%256;
times--;
if(times==0) flag=1;
}
main()
TMOD=0x01;
ET0=1;
EA=1;
//比如延時100s
delaytime=1000;//1ms
times=100;//調整delaytime,times來調整延時時間
TR0=1;
flag=0;
while(flag==0);//等待延時時間到
while(1);
你想用定時器來延時嗎?很好處理呀比如
#include
#define uchar unsigned char;
#define uint unsigned int;
uchar times;
uint delaytime;
bit flag=00h;
void t0isr() interrupt 1
{
TH0=(65536-delaytime)/256;
TL0=(65536-delaytime)%256;
times--;
if(times==0) flag=1;
}
main()
{
TMOD=0x01;
ET0=1;
EA=1;
//比如延時100s
delaytime=1000;//1ms
times=100;//調整delaytime,times來調整延時時間
TR0=1;
flag=0;
while(flag==0);//等待延時時間到
while(1);
}