AVR watchdog use

/ / Observe the difference between feeding the dog and not feeding the dog, use the LED indicator of the PB port to make the status indication.

//Switch the LED indicator enable switch of the PB port to the "ON" state.

#include

#define DISP_DDR DDRB

#define DISP_PORT PORTB

//Watchdog WDT initialization program

Void wdt_init(void)

{

Asm("wdr"); //clr wdt

WDTCR=0 x0F; //enable wdt,clk = 2048,2.1S

}

Void main(void)

{

Uint8 i;

DISP_DDR = 0 xFF;

Wdt_init();

While(1)

{

DISP_PORT++; / / data display up, for the AVR normal operation instructions

Asm ("wdr"); / / feed the dog, remove this sentence will cause the dog to starve, AVR reset

Delay50ms(20);

}

}

Void WDT_off(void)

{

Asm("cli");

Asm ("wdr"); / / reset the watchdog, that is, feed the dog

MCUSR &= ~(1<

WDTCR |= (1<

WDTCR = 0 x00;

}

Void WATCHDOG_Feed()

{

Asm ("wdr"); / / reset the watchdog, that is, feed the dog

}

/ / In the AVR running program set to let the PB display port self-plus. If the AVR is working properly,

/ / Feed the dog in time, the display port set by the microcontroller is normally added.

/ / Remove the statement: asm ("wdr"); MCU keep reset, the program is not allowed, self-added data is not displayed up.


Initialize, then feed the dog, feed the dog before the watchdog bites, (feed the dog before resetting)
Note: The clear dog command cannot be placed in the timer interrupt, so no matter where the program flies, where it is executed, the interrupt function will be executed after the interrupt is generated, so the clear dog command in the timer will make the WDT useless (invalid). .

LCD Display Panel

Lcd Display Panel,Flat Panel Monitor,Lcd Touch Screen,Lcd Tv Panel

Huangshan Kaichi Technology Co.,Ltd , https://www.kaichitech.com

Posted on