English
Language : 

PIC32MX440F256H-80I Datasheet, PDF (566/646 Pages) Microchip Technology – 64/100-Pin General Purpose and USB 32-Bit Flash Microcontrollers
PIC32MX3XX/4XX
EXAMPLE 26-2: SAMPLE CODE TO DETERMINE THE CAUSE OF A WDT EVENT
// sample code to determine the cause of a WDT event
// Unlock the OSCCON register
SYSKEY = 0x12345678;
SYSKEY = 0xAA996655;
SYSKEY = 0x556699AA;
// OSCCON is now unlocked
//write invalid key to force lock
//write Key1 to SYSKEY
//write Key2 to SYSKEY
OSCCONSET = 0x10;
// set power save mode to Sleep
// Alternate relock code in ‘C’
SYSREG = 0x33333333;
// OSCCON is relocked
WDTCONSET = 0x8000;
//Enable WDT
while (1)
{
... user code ...
WDTCONSET = 0x01;// service the WDT
asm volatile ( “wait” );
// put device is selected power save mode
// code execution will resume here after wake
... user code ...
}
// The following code fragment is at the top of the device start-up code
if ( RCON & 0x18 )
{
// The WDT caused a wake from sleep
asm volatile ( “eret” );
}
// return from interrupt
if ( RCON & 0x14 )
{
// The WDT caused a wake from idle
asm volatile ( “eret” );
}
// return from interrupt
if ( RCON & 0x10 )
{
// WDT timed-out
(device may have been awake or may have been in sleep/idle mode)
}
DS61143E-page 564
Preliminary
© 2008 Microchip Technology Inc.