设51单片机晶振频率为12MHZ,延时1m的子程序
1个回答
展开全部
猜想你问的是1ms.
下面为你写出1ms的程序:
用的是11.0592M的,你如果真的需要是12M的,那自己直接修改成12M就可以了。调用的时候直接把uinsigned int ms改成1就是1ms.
void ConfigTimer0(unsigned int ms)
{
unsigned long tmp;
tmp = 11059200/12;
tmp = (tmp * ms)/1000;
tmp = 65536 - tmp;
tmp = tmp + 18;
T0RH = (unsigned char)(tmp >> 8);
T0RL = (unsigned char)tmp;
TMOD &= 0xF0;
TMOD |= 0x01;
TH0 = T0RH;
TL0 = T0RL;
ET0 =1;
TR0 = 1;
}
下面为你写出1ms的程序:
用的是11.0592M的,你如果真的需要是12M的,那自己直接修改成12M就可以了。调用的时候直接把uinsigned int ms改成1就是1ms.
void ConfigTimer0(unsigned int ms)
{
unsigned long tmp;
tmp = 11059200/12;
tmp = (tmp * ms)/1000;
tmp = 65536 - tmp;
tmp = tmp + 18;
T0RH = (unsigned char)(tmp >> 8);
T0RL = (unsigned char)tmp;
TMOD &= 0xF0;
TMOD |= 0x01;
TH0 = T0RH;
TL0 = T0RL;
ET0 =1;
TR0 = 1;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询