Atmega4hvd/8hvd – Rainbow Electronics ATmega8HVD User Manual
Page 46

46
8052B–AVR–09/08
ATmega4HVD/8HVD
1.
In the same operation, write a logic one to the Watchdog change enable bit (WDCE)
and WDE. A logic one must be written to WDE regardless of the previous value of the
WDE bit.
2.
Within the next four clock cycles, write the WDE and Watchdog prescaler bits (WDP)
as desired, but with the WDCE bit cleared. This must be done in one operation.
The following code example shows one assembly and one C function for turning off the
Watchdog Timer. The example assumes that interrupts are controlled (e.g. by disabling inter-
rupts globally) so that no interrupts will occur during the execution of these functions.
Note:
1. See
”About Code Examples” on page 5
Assembly Code Example
(1)
WDT_off:
; Turn off global interrupt
cli
; Reset Watchdog Timer
wdr
; Clear WDRF in MCUSR
in
r16, MCUSR
andi
r16, (0xff & (0< out MCUSR, r16 ; Write logical one to WDCE and WDE ; Keep old prescaler setting to prevent unintentional timeout in r16, WDTCSR ori r16, (1< out WDTCSR, r16 ; Turn off WDT ldi r16, (0< out WDTCSR, r16 ; Turn on global interrupt sei ret C Code Example (1) void WDT_off(void) { __disable_interrupt(); __watchdog_reset(); /* Clear WDRF in MCUSR */ MCUSR &= ~(1< /* Write logical one to WDCE and WDE */ /* Keep old prescaler setting to prevent unintentional timeout */ WDTCSR |= (1< /* Turn off WDT */ WDTCSR = 0x00; __enable_interrupt(); }