24M
晶振T0最大只能4096us,所以需要用定时器累加。
#include "reg51.h"
unsigned char ms=0;
void initTimer(void)
{
TMOD=0x0;
TH0=0xc1;
TL0=0x10;
}
void timer0(void) interrupt 1
{
TH0=0xc1;
TL0=0x10;
//add your code here.
ms++;
if(ms>5)
{
// 这里5ms时间到了。
ms = 0;
}
}
void main(void)
{
initTimer();
TR0=1;
ET0=1;
//EA=1;
}