共2条
1/1 1 跳转至页
44b0 高手进来看下,关于44b0的延时程序
问
实在不理解下面这段代码是如何运作的,那位高手给指点一下撒
小弟先谢了
void Delay(int time)
// time=0: adjust the Delay function by WatchDog timer.//
// time>0: the number of loop time//
// 100us resolution.//
{
int i,adjust=0;
if(time==0)
{
time=200;
adjust=1;
delayLoopCount=400;
rWTCON=((MCLK/1000000-1)<<8)|(2<<3); // 1M/64,Watch-dog,nRESET,interrupt disable//
rWTDAT=0xffff;
rWTCNT=0xffff;
rWTCON=((MCLK/1000000-1)<<8)|(2<<3)|(1<<5); // 1M/64,Watch-dog enable,nRESET,interrupt disable //
}
for(;time>0;time--)
for(i=0;i<delayLoopCount;i++);
if(adjust==1)
{
rWTCON=((MCLK/1000000-1)<<8)|(2<<3);
i=0xffff-rWTCNT; // 1count/16us?????????//
delayLoopCount=8000000/(i*64); //400*100/(i*64/200) //
}
} 答 1: 对着注释讲得很清楚啦延时100us,如Delay(1)为延时100us,Delay(10)为延时1000us...
Delay(0)进行校准,使在各种工作时钟下都能满足延时100us的基准 答 2: 十分感谢阿南我已明白,十分感谢拉
小弟先谢了
void Delay(int time)
// time=0: adjust the Delay function by WatchDog timer.//
// time>0: the number of loop time//
// 100us resolution.//
{
int i,adjust=0;
if(time==0)
{
time=200;
adjust=1;
delayLoopCount=400;
rWTCON=((MCLK/1000000-1)<<8)|(2<<3); // 1M/64,Watch-dog,nRESET,interrupt disable//
rWTDAT=0xffff;
rWTCNT=0xffff;
rWTCON=((MCLK/1000000-1)<<8)|(2<<3)|(1<<5); // 1M/64,Watch-dog enable,nRESET,interrupt disable //
}
for(;time>0;time--)
for(i=0;i<delayLoopCount;i++);
if(adjust==1)
{
rWTCON=((MCLK/1000000-1)<<8)|(2<<3);
i=0xffff-rWTCNT; // 1count/16us?????????//
delayLoopCount=8000000/(i*64); //400*100/(i*64/200) //
}
} 答 1: 对着注释讲得很清楚啦延时100us,如Delay(1)为延时100us,Delay(10)为延时1000us...
Delay(0)进行校准,使在各种工作时钟下都能满足延时100us的基准 答 2: 十分感谢阿南我已明白,十分感谢拉
共2条
1/1 1 跳转至页
回复
| 有奖活动 | |
|---|---|
| 硬核工程师专属补给计划——填盲盒 | |
| “我踩过的那些坑”主题活动——第002期 | |
| 【EEPW电子工程师创研计划】技术变现通道已开启~ | |
| 发原创文章 【每月瓜分千元赏金 凭实力攒钱买好礼~】 | |
| 【EEPW在线】E起听工程师的声音! | |
| 高校联络员开始招募啦!有惊喜!! | |
| 【工程师专属福利】每天30秒,积分轻松拿!EEPW宠粉打卡计划启动! | |
| 送您一块开发板,2025年“我要开发板活动”又开始了! | |
我要赚赏金
