|
仿真的时候看延时程序的时钟周期,如不准确可加NOP调整
/***************************************/
void Delay_S(unsigned int nValue)//秒为单位,8MHz为主时钟
{
unsigned int nCount;
unsigned int ii;
unsigned int jj;
nCount = 50000;//50000,调整为49999,当nValue=3秒时为24000034个Tj,较为精确
nValue <<= 4;//输入的数值*16
for(ii = nValue;ii > 0;ii--)
{
for(jj = nCount;jj > 0;jj--)//共10个Tj
{
_NOP();//1Tj
_NOP();//1Tj
_NOP();//1Tj
_NOP();//1Tj
}
}
return;//8000000/50000/(6+4)/16个Tj=1
}
void Delay_ms(unsigned int nValue)//毫秒为单位,8MHz为主时钟
{
unsigned int nCount;
unsigned int ii;
unsigned int jj;
nCount = 1331;//8000000*0.001/1332/6个Tj=1
for(ii = nValue;ii > 0;ii--)
{
for(jj = nCount;jj > 0;jj--);
}
return;
}
void Delay_us(unsigned int nValue)//微秒为单位,8MHz为主时钟
{
unsigned int ii;
for(ii = nValue;ii > 0;ii--)
{
_NOP();//1Tj
_NOP();//1Tj
}
return;//8000000*0.000001/(6+2)=1
} |
|