日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁 > 單片機(jī) > 單片機(jī)
[導(dǎo)讀]#ifndef _DELAY_51_H_#define _DELAY_51_H_#include #define uint unsigned int#define uchar unsigned char//nus延時(shí)void delay_nus( uchar n );//nms延時(shí)void delay_nms( uchar n );//2us延時(shí)void delay_2us( ucha

#ifndef _DELAY_51_H_
#define _DELAY_51_H_
#include

#define uint unsigned int
#define uchar unsigned char

//nus延時(shí)
void delay_nus( uchar n );
//nms延時(shí)
void delay_nms( uchar n );
//2us延時(shí)
void delay_2us( uchar t );
//50us延時(shí)
void delay_50us(uint t);
//50ms延時(shí)
void delay_50ms( uint t );


#endif //

/*
********************************************************************
** 文件名 : C51延時(shí)驅(qū)動(dòng)
********************************************************************
*/

#define _DELAY_51_C_
#include "DELAY_51.H" //用戶自己定義的頭文件

//==========================向以前版本兼容部分函數(shù)==============================
/*
********************************************************************
** 函數(shù)名:nus延時(shí)函數(shù)
** 注意 :注意延時(shí)為 0 < n < 256,
** 說明 :此版本主要是對前面的驅(qū)動(dòng)兼容, 實(shí)際上可調(diào)度約為2us, 不做多
** 說明,以后盡量用新版本delay_2us(uchar n)代替。
********************************************************************
*/
void delay_nus( uchar n )
{
while( --n )
{;}
}

/*
********************************************************************
** 函數(shù)名:nus延時(shí)函數(shù)
** 注意 :注意延時(shí)為 0 < n < 256,
** 說明 :此版本主要是對前面的驅(qū)動(dòng)兼容, 比較準(zhǔ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++ )
{;}
}
}
}
//==============================================================================
//==============================================================================
/*
********************************************************************
** 函數(shù)名 :2us延時(shí)函數(shù)
** 注意項(xiàng) :注意延時(shí)為 0 < t < 256
** 例子提示:調(diào)用delay_2us(1),得到1ms延時(shí)
** 說明 :

** delay2(0):延時(shí)518us 518-2*256=6
** delay2(1):延時(shí)7us
** delay2(10):延時(shí)25us 25-20=5
** delay2(20):延時(shí)45us 45-40=5
** delay2(100):延時(shí)205us 205-200=5
** delay2(200):延時(shí)405us 405-400=5

** 可調(diào)度為2us,而最大誤差為6us
********************************************************************
*/
void delay_2us( uchar t )
{
while( --t )
{;}
}


/*------------------------------------------------------------------
函數(shù)全稱:50us 延時(shí)
注意事項(xiàng):AT89系列對應(yīng)12M晶振
例子提示:調(diào)用delay_50us(20),得到1ms延時(shí)
輸 入:
返 回:無

delay_50us(1):延時(shí)63us 63-50=13
delay_50us(10):延時(shí)513us 503-500=13
delay_50us(100):延時(shí)5013us 5013-5000=13
delay_50us(1000):延時(shí)50022us 50022-50000=22

誤差最大在22us, 很準(zhǔn)確了。

------------------------------------------------------------------*/
void delay_50us(uint t)
{
uchar j;
for( ; t > 0; t-- )
for( j = 19; j > 0; j-- )
{;}
}

/*
********************************************************************
** 函數(shù)全稱:50ms 延時(shí)
** 注意事項(xiàng):基于1MIPS,AT89系列對應(yīng)12M晶振
** 例子提示:調(diào)用delay_50ms(20),得到1s延時(shí)
** 全局變量:無
** 返回: 無
** 說明 : 參考網(wǎng)絡(luò)

** delay_50ms(1):延時(shí)50 010 10us
** delay_50ms(10):延時(shí)499 983 17us
** delay_50ms(100):延時(shí)4 999 713 287us
** delay_50ms(1000):延時(shí)4 997 022 2.978ms

** 延時(shí)50s,誤差僅僅2.978ms,可以接受
********************************************************************
*/
void delay_50ms( uint t )
{
uint j;
for( ; t > 0; t-- )
for( j = 6245; j > 0; j-- )
{;}
}


本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時(shí)聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關(guān)閉