Code:
void MCU_init(void){ /* ### MC9S08AW60_64 "Cpu" init code ... */ /* PE initialization code after reset */ /* Common initialization of the write once registers */ /* SOPT: COPE=0,COPT=1,STOPE=0 */ SOPT = 0x53; /* SPMSC1: LVDF=0,LVDACK=0,LVDIE=0,LVDRE=1,LVDSE=1,LVDE=1,BGBE=0 */ SPMSC1 = 0x1C; /* SPMSC2: LVWF=0,LVWACK=0,LVDV=0,LVWV=0,PPDF=0,PPDACK=0,PPDC=0 */ SPMSC2 = 0x00; /* SMCLK: MPE=0,MCSEL=0 */ SMCLK &= (unsigned char)~0x17; /* System clock initialization */ /* ICGC1: HGO=1,RANGE=1,REFS=1,CLKS1=1,CLKS0=0,OSCSTEN=1,LOCD=1 */ ICGC1 = 0xF6; /* ICGC2: LOLRE=0,MFD2=0,MFD1=0,MFD0=0,LOCRE=0,RFD2=0,RFD1=0,RFD0=0 */ ICGC2 = 0x00; while(!ICGS1_ERCS) { /* Wait until external reference is not stable */ } /* Common initialization of the CPU registers */ /* PTASE: PTASE7=1,PTASE6=1,PTASE5=1,PTASE4=1,PTASE3=1,PTASE2=1,PTASE1=1,PTASE0=1 */ PTASE = 0xFF; /* PTBSE: PTBSE7=1,PTBSE6=1,PTBSE5=1,PTBSE4=1,PTBSE3=1,PTBSE2=1,PTBSE1=1,PTBSE0=1 */ PTBSE = 0xFF; /* PTCSE: PTCSE6=1,PTCSE5=1,PTCSE4=1,PTCSE3=1,PTCSE2=1,PTCSE1=1,PTCSE0=1 */ PTCSE |= (unsigned char)0x7F; /* PTDSE: PTDSE7=1,PTDSE6=1,PTDSE5=1,PTDSE4=1,PTDSE3=1,PTDSE2=1,PTDSE1=1,PTDSE0=1 */ PTDSE = 0xFF; /* PTESE: PTESE7=1,PTESE6=1,PTESE5=1,PTESE4=1,PTESE3=1,PTESE2=1,PTESE1=1,PTESE0=1 */ PTESE = 0xFF; /* PTFSE: PTFSE7=1,PTFSE6=1,PTFSE5=1,PTFSE4=1,PTFSE3=1,PTFSE2=1,PTFSE1=1,PTFSE0=1 */ PTFSE = 0xFF; /* PTGSE: PTGSE6=1,PTGSE5=1,PTGSE4=1,PTGSE3=1,PTGSE2=1,PTGSE1=1,PTGSE0=1 */ PTGSE |= (unsigned char)0x7F; /* PTADS: PTADS7=0,PTADS6=0,PTADS5=0,PTADS4=0,PTADS3=0,PTADS2=0,PTADS1=0,PTADS0=0 */ PTADS = 0x00; /* PTBDS: PTBDS7=0,PTBDS6=0,PTBDS5=0,PTBDS4=0,PTBDS3=0,PTBDS2=0,PTBDS1=0,PTBDS0=0 */ PTBDS = 0x00; /* PTCDS: PTCDS6=0,PTCDS5=0,PTCDS4=0,PTCDS3=0,PTCDS2=0,PTCDS1=0,PTCDS0=0 */ PTCDS = 0x00; /* PTDDS: PTDDS7=0,PTDDS6=0,PTDDS5=0,PTDDS4=0,PTDDS3=0,PTDDS2=0,PTDDS1=0,PTDDS0=0 */ PTDDS = 0x00; /* PTEDS: PTEDS7=0,PTEDS6=0,PTEDS5=0,PTEDS4=0,PTEDS3=0,PTEDS2=0,PTEDS1=0,PTEDS0=0 */ PTEDS = 0x00; /* PTFDS: PTFDS7=0,PTFDS6=0,PTFDS5=0,PTFDS4=0,PTFDS3=0,PTFDS2=0,PTFDS1=0,PTFDS0=0 */ PTFDS = 0x00; /* PTGDS: PTGDS6=0,PTGDS5=0,PTGDS4=0,PTGDS3=0,PTGDS2=0,PTGDS1=0,PTGDS0=0 */ PTGDS = 0x00; /* ### Init_GPIO init code */ /* PTBDD: PTBDD2=1,PTBDD1=1,PTBDD0=1 */ PTBDD |= (unsigned char)0x07; /* ### Init_COP init code */ SRS = 0xFF; /* Clear WatchDog counter */ /* ### Init_TPM init code */ /* TPM2SC: TOF=0,TOIE=0,CPWMS=0,CLKSB=0,CLKSA=0,PS2=0,PS1=0,PS0=0 */ TPM2SC = 0x00; /* Stop and reset counter */ TPM2MOD = 0x8954; /* Period value setting */ (void)(TPM2SC == 0); /* Overflow int. flag clearing (first part) */ /* TPM2SC: TOF=0,TOIE=1,CPWMS=0,CLKSB=0,CLKSA=1,PS2=1,PS1=1,PS0=0 */ TPM2SC = 0x4E; /* Int. flag clearing (2nd part) and timer control register setting */ /* ### */ asm CLI; /* Enable interrupts */} /*MCU_init*/
I made a new initialization function, but it cause only that watchdog doesn't overflow but that check of the "external reference" still looping forever ....