1.須要調用oop
#include <avr/wdt.h>
2.設置看門狗復位時間測試
wdt_enable(WDTO_2S);
代碼時間定義的底層查看spa
#define WDTO_15MS 0 /** \ingroup avr_watchdog See \c WDT0_15MS */ #define WDTO_30MS 1 /** \ingroup avr_watchdog See \c WDT0_15MS */ #define WDTO_60MS 2 /** \ingroup avr_watchdog See \c WDT0_15MS */ #define WDTO_120MS 3 /** \ingroup avr_watchdog See \c WDT0_15MS */ #define WDTO_250MS 4 /** \ingroup avr_watchdog See \c WDT0_15MS */ #define WDTO_500MS 5 /** \ingroup avr_watchdog See \c WDT0_15MS */ #define WDTO_1S 6 /** \ingroup avr_watchdog See \c WDT0_15MS */ #define WDTO_2S 7 if defined(__DOXYGEN__) || defined(WDP3) /** \ingroup avr_watchdog See \c WDT0_15MS Note: This is only available on the ATtiny2313, ATtiny24, ATtiny44, ATtiny84, ATtiny84A, ATtiny25, ATtiny45, ATtiny85, ATtiny261, ATtiny461, ATtiny861, ATmega48, ATmega88, ATmega168, ATmega48P, ATmega88P, ATmega168P, ATmega328P, ATmega164P, ATmega324P, ATmega644P, ATmega644, ATmega640, ATmega1280, ATmega1281, ATmega2560, ATmega2561, ATmega8HVA, ATmega16HVA, ATmega32HVB, ATmega406, ATmega1284P, ATmega256RFR2, ATmega128RFR2, ATmega64RFR2, ATmega2564RFR2, ATmega1284RFR2, ATmega644RFR2, AT90PWM1, AT90PWM2, AT90PWM2B, AT90PWM3, AT90PWM3B, AT90PWM216, AT90PWM316, AT90PWM81, AT90PWM161, AT90USB82, AT90USB162, AT90USB646, AT90USB647, AT90USB1286, AT90USB1287, ATtiny48, ATtiny88. */ #define WDTO_4S 8 /** \ingroup avr_watchdog See \c WDT0_15MS Note: This is only available on the ATtiny2313, ATtiny24, ATtiny44, ATtiny84, ATtiny84A, ATtiny25, ATtiny45, ATtiny85, ATtiny261, ATtiny461, ATtiny861, ATmega48, ATmega48A, ATmega48PA, ATmega88, ATmega168, ATmega48P, ATmega88P, ATmega168P, ATmega328P, ATmega164P, ATmega324P, ATmega644P, ATmega644, ATmega640, ATmega1280, ATmega1281, ATmega2560, ATmega2561, ATmega8HVA, ATmega16HVA, ATmega32HVB, ATmega406, ATmega1284P, ATmega256RFR2, ATmega128RFR2, ATmega64RFR2, ATmega2564RFR2, ATmega1284RFR2, ATmega644RFR2, AT90PWM1, AT90PWM2, AT90PWM2B, AT90PWM3, AT90PWM3B, AT90PWM216, AT90PWM316, AT90PWM81, AT90PWM161, AT90USB82, AT90USB162, AT90USB646, AT90USB647, AT90USB1286, AT90USB1287, ATtiny48, ATtiny88, ATxmega16a4u, ATxmega32a4u, ATxmega16c4, ATxmega32c4, ATxmega128c3, ATxmega192c3, ATxmega256c3. */ #define WDTO_8S 9
3.喂狗操做3d
wdt_reset();
4.關閉看門狗code
wdt_disable();
測試代碼:blog
#include <avr/wdt.h> int test = 0; void setup() { Serial.begin(9600); Serial.println("in setup"); Serial.print("test="); Serial.println(test); delay(1000); wdt_enable(WDTO_2S); } void loop() { int testLoop; test++; // wdt_reset(); Serial.println("in loop"); Serial.print("test="); Serial.println(test); delay(1000); Serial.print("testLoop="); Serial.println(testLoop++); }