ATmega48PA Automotive Atmel Corporation, ATmega48PA Automotive Datasheet - Page 53

no-image

ATmega48PA Automotive

Manufacturer Part Number
ATmega48PA Automotive
Description
Manufacturer
Atmel Corporation
9223B–AVR–09/11
Assembly Code Example
C Code Example
Notes:
Atmel ATmega48PA/88PA/168PA [Preliminary]
WDT_off:
void WDT_off(void)
{
}
; Turn off global interrupt
cli
; Reset Watchdog Timer
wdr
; Clear WDRF in MCUSR
in
andi
out
; Write logical one to WDCE and WDE
; Keep old prescaler setting to prevent unintentional time-out
lds r16, WDTCSR
ori
sts WDTCSR, r16
; Turn off WDT
ldi
sts WDTCSR, r16
; Turn on global interrupt
sei
ret
__disable_interrupt();
__watchdog_reset();
/* Clear WDRF in MCUSR */
MCUSR &= ~(1<<WDRF);
/* Write logical one to WDCE and WDE */
/* Keep old prescaler setting to prevent unintentional time-out */
WDTCSR |= (1<<WDCE) | (1<<WDE);
/* Turn off WDT */
WDTCSR = 0x00;
__enable_interrupt();
1. See
2. If the Watchdog is accidentally enabled, for example by a runaway pointer or brown-out
condition, the device will be reset and the Watchdog Timer will stay enabled. If the code is
not set up to handle the Watchdog, this might lead to an eternal loop of time-out resets.
To avoid this situation, the application software should always clear the Watchdog System
Reset Flag (WDRF) and the WDE control bit in the initialization routine, even if the Watch-
dog is not in use.
r16, MCUSR
r16, (0xff & (0<<WDRF))
MCUSR, r16
r16, (1<<WDCE) | (1<<WDE)
r16, (0<<WDE)
Section 6. “About Code Examples” on page 7
(1)
(1)
53

Related parts for ATmega48PA Automotive