WinAVR avr/delay函数的用法

WinAVR avr/delay函数的用法 在avr GCC的函数库中包有个非常有用的精确延时函数, #include 其中包括4个函数 _delay_loop_1( ); _delay_loop_2( ); _delay_us( ); _delay_ms( ); _delay_loop_1(uint8_t __count); 参数 __count 为8bit 长度,1-256,256表示为0。 每个循环花费3个CPU周期。 所以当晶振为1Mhz时,最长延时为768us(microseconds) _delay_loop_2(uint16_t __count); 参数 __count 为 16bit 长度,1-65536,65536被认为是0。 每个循环花费4个CPU周期。 所以当晶振为1Mhz时,最长延时为262.1 ms (milliseconds) 1*4*65536=262144 us _delay_us(double __us); us的精确延时,参数为double,最长为768 us。 原头文件中定义了晶振频率为1Mhz。在makefile中默认为F_CPU=8000000 #ifndef F_CPU /* prevent compiler error by supplying a default */ # warning "F_CPU not defined for " # define F_CPU 1000000UL #endif 原函数为: static __inline__ void _delay_us(double __us) { uint8_t __ticks; double __tmp = ((F_CPU) / 3e6) * __us; if (__tmp < 1.0) __ticks = 1; else if (__tmp > 255) __ticks = 0; /* i.e. 256 */ else __ticks = (uint8_t)__tmp; _delay_loop_1(__ticks); } _delay_ms(double __ms); ms的精确延时,参数为double,最长为262.14 ms。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值