set_CHPCON_IAPEN;
IAPAL = 0x04;
IAPAH = 0x00;
IAPFD = 0x0F;
IAPCN = BYTE_PROGRAM_CONFIG;
set_IAPUEN_CFUEN;
set_IAPTRG_IAPGO; //trigger IAP
_nop_();
_nop_();
while ((CHPCON & SET_BIT6) == SET_BIT6); //check IAPFF (CHPCON.6)
//------------------------死机,无限待----------------
clr_IAPUEN_CFUEN;
clr_CHPCON_IAPEN;
set_CHPCON_SWRST;
//------------------------------------------
_nop_();
_nop_();
TA=0xAA;TA=0x55;WDCON|=0x07; //Setting WDT prescale
set_WDCON_WDCLR; //Clear WDT timer
while((WDCON|~SET_BIT6)==0xFF); //confirm WDT clear is ok before into power down mode
set_WDCON_WDTR;
|