?? delay_51.c
字號:
#define _DELAY_51_C_
#include "DELAY_51.H" //用戶自己定義的頭文件
//==========================向以前版本兼容部分函數==============================
/*
********************************************************************
** 函數名:nus延時函數
** 注意 :注意延時為 0 < n < 256,
** 說明 :此版本主要是對前面的驅動兼容, 實際上可調度約為2us, 不做多
** 說明,以后盡量用新版本delay_2us(uchar n)代替。
********************************************************************
*/
void delay_nus( uchar n )
{
while( --n )
{;}
}
/*
********************************************************************
** 函數名:nus延時函數
** 注意 :注意延時為 0 < n < 256,
** 說明 :此版本主要是對前面的驅動兼容, 實際上可調度約為2us, 不做多
** 說明,以后盡量用新版本delay_50us(uint n)代替。
********************************************************************
*/
void delay_nms( uchar n )
{
uchar i;
uchar j;
uchar t;
for( t = 0; t < n; t++ )
{
for( j = 0; j < 15; j ++ )
{
for( i = 0; i < 21; i++ )
{;}
}
}
}
//==============================================================================
//==============================================================================
/*
********************************************************************
** 函數名 :2us延時函數
** 注意項 :注意延時為 0 < t < 256
** 例子提示:調用delay_2us(1),得到1ms延時
** 說明 :
** delay2(0):延時518us 518-2*256=6
** delay2(1):延時7us
** delay2(10):延時25us 25-20=5
** delay2(20):延時45us 45-40=5
** delay2(100):延時205us 205-200=5
** delay2(200):延時405us 405-400=5
** 可調度為2us,而最大誤差為6us
********************************************************************
*/
/*
void delay_2us( uchar t )
{
while( --t )
{;}
}
*/
/*------------------------------------------------------------------
函數全稱:50us 延時
注意事項:AT89系列對應12M晶振
例子提示:調用delay_50us(20),得到1ms延時
輸 入:
返 回:無
delay_50us(1):延時63us 63-50=13
delay_50us(10):延時513us 503-500=13
delay_50us(100):延時5013us 5013-5000=13
delay_50us(1000):延時50022us 50022-50000=22
誤差最大在22us, 很準確了。
------------------------------------------------------------------*/
/*
void delay_50us(uint t)
{
uchar j;
for( ; t > 0; t-- )
for( j = 19; j > 0; j-- )
{;}
}
*/
/*
********************************************************************
** 函數全稱:50ms 延時
** 注意事項:基于1MIPS,AT89系列對應12M晶振
** 例子提示:調用delay_50ms(20),得到1s延時
** 全局變量:無
** 返回: 無
** 說明 : 參考網絡
** delay_50ms(1):延時50 010 10us
** delay_50ms(10):延時499 983 17us
** delay_50ms(100):延時4 999 713 287us
** delay_50ms(1000):延時4 997 022 2.978ms
** 延時50s,誤差僅僅2.978ms,可以接受
********************************************************************
*/
/*
void delay_50ms( uint t )
{
uint j;
for( ; t > 0; t-- )
for( j = 6245; j > 0; j-- )
{;}
}
*/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -