智能车制作
标题:
用PE生成的一个比较精确的100微秒延时函数
[打印本页]
作者:
chiusir
时间:
2010-8-3 09:35
标题:
用PE生成的一个比较精确的100微秒延时函数
本帖最后由 chiusir 于 2010-8-3 09:37 编辑
用PE生成的一个比较精确的100微秒延时函数,供大家参考,如果需要其它频率的,可以留言请求。
开发环境:
CW:5.0
CRYSTAL:16MHZ
PLLCLK:32MHZ
void Cpu_Delay100US(word us100)
{
/* irremovable overhead (ignored): 13 cycles */
/* ldd: 2 cycles overhead (load parameter into register) */
/* jsr: 4 cycles overhead (call this function) */
/* rts: 7 cycles overhead (return from this function) */
/* irremovable overhead for each 100us cycle (counted): 13 cycles */
/* dbne: 3 cycles overhead (return from this function) */
asm {
loop:
/* 100 us delay block begin */
/*
* Delay
* - requested : 100 us @ 16MHz,
* - possible : 1600 c, 100000 ns
* - without removable overhead : 1597 c, 99812.5 ns
*/
pshd /* (2 c: 125 ns) backup D */
ldd #530 /* (2 c: 125 ns) number of iterations */
label0:
dbne d, label0 /* (3 c: 187.5 ns) repeat 530x */
puld /* (3 c: 187.5 ns) restore D */
/* 100 us delay block end */
dbne d, loop /* us100 parameter is passed via D register */
rts /* return from subroutine */
}
}
作者:
vgjkl
时间:
2011-5-27 12:39
学习,谢谢分享
作者:
zhjb1
时间:
2011-5-27 20:00
程序占用CPU资源,建议还是用时钟中断较好。
作者:
chiusir
时间:
2011-5-27 22:57
看用在什么地方,有些地方就是需要等待的话,用这个也无所谓,如果还需要处理大量数据,可以考虑中断或者别的方式。
作者:
wkhuahuo
时间:
2013-3-11 18:13
f(bus)=64m
该怎么写?求教~
欢迎光临 智能车制作 (http://111.231.132.190/)
Powered by Discuz! X3.2