Arduino只要有定义中断函数,delay()就完全不能用了?
主循环中有下面一段程序:noInterrupts();
for(byte i=0;i<10;i++)
{
delay(1000);
}
interrupts();
实际运行是该段远没有10s延时这么长,1s都不到感觉,我在外面定义了外部中断,这里忽略中断,但是仍然不行。这个delay()一直困扰,貌似一旦定义中断函数,就不能用了,还望大家指教? 另,delay的函数原型在什么位置,一直想找到,仔细瞅瞅是何面貌…… 可以在 https://code.google.com/p/arduino/downloads/list 下载到code
\hardware\arduino\firmwares\wifishield\wifiHD\src\SOFTWARE_FRAMEWORK\SERVICES\DELAY\delay.c
有下面的定义
void delay_ms(unsigned long delay)
{
#if (defined FREERTOS_USED)
vTaskDelay( (portTickType)TASK_DELAY_MS(delay) );
#elif (defined NUTOS_USED)
NutSleep(delay);
#else
cpu_delay_ms(delay, s_fcpu_hz);
#endif
}
在\hardware\arduino\firmwares\wifishield\wifiHD\src\SOFTWARE_FRAMEWORK\DRIVERS\CPU\CYCLE_COUNTER\cycle_counter.h 有下面的代码
#if (defined __GNUC__)
__attribute__((__always_inline__))
#endif
extern __inline__ void cpu_delay_ms(unsigned long delay, unsigned long fcpu_hz)
{
t_cpu_time timer;
cpu_set_timeout( cpu_ms_2_cy(delay, fcpu_hz), &timer);
while( !cpu_is_timeout(&timer) );
}
同样的文件中 有如下定义
//! Structure holding private information, automatically initialized by the
//! cpu_set_timeout() function.
typedef struct
{
//! The cycle count at the begining of the timeout.
unsigned long delay_start_cycle;
//! The cycle count at the end of the timeout.
unsigned long delay_end_cycle;
//! Enable/disable the timout detection
unsigned char timer_state;
#define CPU_TIMER_STATE_STARTED 0
#define CPU_TIMER_STATE_REACHED 1
#define CPU_TIMER_STATE_STOPPED 2
} t_cpu_time;
但是不熟悉 avr 这个代码就看不懂了,建议你自己下载研究一下哈 Arduino视频教程(10/15)中断和硬件去抖
http://v.youku.com/v_show/id_XNzEzMzM2MjI4.html zoologist 发表于 2014-5-24 20:43 static/image/common/back.gif
可以在 https://code.google.com/p/arduino/downloads/list 下载到code
\hardware\arduino\firmwares\wi ...
非常感谢,都摘过来了,不过看着还真有点费劲,虽然我一直玩avr
页:
[1]