reset()

描述

重置看门狗计时器(使看门狗计时器的计数值归零)。

此函式主要在看门狗模式中使用,进行俗称的喂狗动作(kicking the dog),避免 CPU 被看门狗重置。

语法


TimerWDT.reset()

参数

回传

无回传值

范例

设定看门狗计时器为看门狗模式,计时 30 秒自动重置系统,并另外且在程式中每隔 10 秒重置一次看门狗计时器。(正常情况下,系统重置事件将永远不发生,但如果系统受到外力干扰在执行中当机,那麽 30 秒后看门狗计时器将会重置系统,让系统重开机执行。)

#include <TimerWDT.h>
unsigned long currentTime;  
void setup() 
{
  TimerWDT.initialize(30000000, true); // 设定 30 秒时间週期
  currentTime = millis();
}

void loop() {
  // 每 10 秒喂狗一次,避免系统被看门狗重置
  if((millis() - currentTime) > 10000)
  {
    TimerWDT.reset(); // 重置看门狗计时器
    currentTime = millis();
  }
  // 使用者程式 ...
}

See also

isResetByWDT()


函式库参考主页面

The text of the 86Duino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.