initialize()
描述
初始化 86Duino 的看門狗計時器,並指定其工作模式。
語法
TimerWDT.initialize()
TimerWDT.initialize(time)
TimerWDT.initialize(time, mode)
參數
time
:設定看門狗計時器的時間週期,單位為微秒(us)。可以設定的最長時間為 512 秒(512000000us);如果沒有指定,其預設值為 500ms(等於 500000us)。
mode
:設定看門狗計時器工作模式。型別為 boolean
,說明如下,預設值為 false
:
true
:看門狗模式(即到達指定時間便將 86Duino 重新開機)。false
:計時中斷模式(即到達指定時間便執行使用者 ISR 一次,為預設模式)。
回傳
無回傳值
範例
設定看門狗計時器為計時中斷模式,每隔 100ms 點亮和熄滅 LED:
#include <TimerWDT.h> void setup() { pinMode(13, OUTPUT); TimerWDT.initialize(100000); // 設定 100ms 時間週期 TimerWDT.attachInterrupt( timerIsr ); // 掛載使用者 ISR,每隔 100ms 執行一次 } void loop() {} // 使用者 ISR void timerIsr() { // 交替點亮和熄滅 LED 燈 digitalWrite( 13, digitalRead( 13 ) ^ 1 ); }
設定看門狗計時器為看門狗模式,每隔 30 秒重置一次系統:
#include <TimerWDT.h> void setup() { TimerWDT.initialize(30000000, true); // 設定 30s 時間週期 } void loop() { // 使用者程式 ... }
See also
- attachInterrupt()()
- detachInterrupt()
- setPeriod()
- reset()
- isResetByWDT()
- stop()
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.