新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > ICC AVR精確定時的編程實驗

ICC AVR精確定時的編程實驗

作者: 時間:2016-11-10 來源:網(wǎng)絡(luò) 收藏
#include

/*======================================
微秒級精確延時函數(shù),晶振8M:
Delay = 0.125 *((tt*4-1)+9)微秒
其中9包括了調(diào)用方的r16賦值1t
rcall 3t nop 1t ret 4t
brne指令在當判斷條件不成立時是單周期
最后一次判斷只有1個周期,補一個nop
簡化計算= 0.5tt + 1 (us)
======================================*/
voidshortdelay(unsigned chartt)
{
asm("_L2: subi R16,1"); // 1+
asm("nop") //1+
asm("brne _L2");// 2t/1t
asm("nop");// 1t
asm("ret");// 4t
}

voidmain()
{
shortdelay(18); // 延時10us
while(1)
{
shortdelay(48);// 25us
}
}

本文引用地址:http://butianyuan.cn/article/201611/317365.htm

說明:用ICC編譯時會警告,因為延時函數(shù)的參數(shù)沒用直接應(yīng)用,但是它會直接傳遞到R16中,所以程序是對的。



關(guān)鍵詞: ICCAVR精確定時編程實

評論


技術(shù)專區(qū)

關(guān)閉