beautypg.com

Atmega128rfa1 – Rainbow Electronics ATmega128RFA1 User Manual

Page 182

background image

182



8266A-MCU Wireless-12/09

ATmega128RFA1

Note:

1. The example code assumes that the part specific header file is included.

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 Watchdog is not in use.

The following code example shows one assembly and one C function for changing the
time-out value of the Watchdog Timer.

Assembly Code Example

(1,2)

WDT_Prescaler_Change:

; Turn off global interrupt cli

; Reset Watchdog Timer

wdr

; Start timed sequence

in r16, WDTCSR

ori r16, (1<

out WDTCSR, r16

; --Got four cycles to set the new values from here –

; Set new prescaler(time-out) value = 64K cycles (~0.5 s)

ldi r16, (1<

out WDTCSR, r16

; --Finished setting new values, used 2 cycles –

; Turn on global interrupt

sei

ret

C Code Example

(1,2)

void WDT_Prescaler_Change(void)

{

__disable_interrupt();

__watchdog_reset();

/* Start timed equence */

WDTCSR |= (1<

/* Set new prescaler(time-out) value = 64K cycles (~0.5 s) */

WDTCSR = (1<

__enable_interrupt();

}

Note:

1. The example code assumes that the part specific header file is included.

2. The Watchdog Timer should be reset before any change of the WDP

bits, since a change in the WDP bits can result in a time-out when
switching to a shorter time-out period.