极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 29986|回复: 3

Arduino只要有定义中断函数,delay()就完全不能用了?

[复制链接]
发表于 2014-5-24 20:16:46 | 显示全部楼层 |阅读模式
主循环中有下面一段程序:

     noInterrupts();
     for(byte i=0;i<10;i++)
     {
       delay(1000);
     }
    interrupts();

实际运行是该段远没有10s延时这么长,1s都不到感觉,我在外面定义了外部中断,这里忽略中断,但是仍然不行。这个delay()一直困扰,貌似一旦定义中断函数,就不能用了,还望大家指教? 另,delay的函数原型在什么位置,一直想找到,仔细瞅瞅是何面貌……
回复

使用道具 举报

发表于 2014-5-24 20:43:39 | 显示全部楼层
可以在 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 这个代码就看不懂了,建议你自己下载研究一下哈
回复 支持 反对

使用道具 举报

发表于 2014-5-24 21:05:34 | 显示全部楼层
Arduino视频教程(10/15)中断和硬件去抖

回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-5-24 21:21:48 | 显示全部楼层
zoologist 发表于 2014-5-24 20:43
可以在 https://code.google.com/p/arduino/downloads/list 下载到code

\hardware\arduino\firmwares\wi ...

非常感谢,都摘过来了,不过看着还真有点费劲,虽然我一直玩avr
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-14 19:43 , Processed in 0.036470 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表