void MCU_init(void)
{
/* ### MC9RS08KA2_8 "Cpu" init code ... */
/* PE initialization code after reset */
/* Common initialization of the write once registers */
/* SOPT: COPE=0,COPT=1,STOPE=1,BKGDPE=0,RSTPE=0 */
SOPT = 0x60;
/* SPMSC1: LVDF=0,LVDACK=0,LVDIE=0,LVDRE=1,LVDSE=1,LVDE=0,BGBE=0 */
SPMSC1 = 0x18;
/* System clock initialization */
if (*(unsigned char* __paged)CONVERT_TO_PAGED(0x3FFA) != 0xFF) { /* Test if the device trim value is stored on the specified address */
ICSTRM = *(unsigned char* __paged)CONVERT_TO_PAGED(0x3FFA); /* Initialize ICSTRM register from a non volatile memory */
ICSSC = *(unsigned char* __paged)CONVERT_TO_PAGED(0x3FFB); /* Initialize ICSSC register from a non volatile memory */
}
/* ICSC1: CLKS=0,IREFSTEN=0 */
ICSC1 = 0x00; /* Initialization of the ICS control register 1 */
/* ICSC2: BDIV=0,LP=0 */
ICSC2 = 0x00; /* Initialization of the ICS control register 2 */
/* Common initialization of the CPU registers */
/* PTAPE: PTAPE5=1,PTAPE4=1,PTAPE2=1,PTAPE1=1,PTAPE0=1 */
PTAPE |= (unsigned char)0x37;
/* PTAPUD: PTAPUD5=0,PTAPUD4=0,PTAPUD2=0,PTAPUD1=0,PTAPUD0=0 */
PTAPUD &= (unsigned char)~0x37;
/* PTASE: PTASE5=1,PTASE4=1,PTASE3=1,PTASE1=1,PTASE0=1 */
PTASE |= (unsigned char)0x3B;
/* ### Init_KBI init code */
/* KBISC: KBIE=0 */
KBISC &= (unsigned char)~0x02;
/* KBIES: KBEDG5=0,KBEDG4=0,KBEDG2=0,KBEDG1=0,KBEDG0=0 */
KBIES = 0x00;
/* KBISC: KBIMOD=0 */
KBISC &= (unsigned char)~0x01;
/* KBIPE: KBIPE5=1,KBIPE4=1,KBIPE2=1,KBIPE1=1,KBIPE0=1 */
KBIPE = 0x37;
/* KBISC: KBACK=1 */
KBISC |= (unsigned char)0x04;
/* KBISC: KBIE=1 */
KBISC |= (unsigned char)0x02;
/* ### Init_MTIM init code */
/* MTIMMOD: MOD7=0,MOD6=1,MOD5=1,MOD4=0,MOD3=1,MOD2=1,MOD1=0,MOD0=1 */
MTIMMOD = 0x6D;
/* MTIMCLK: CLKS1=0,CLKS0=0,PS3=0,PS2=1,PS1=0,PS0=1 */
MTIMCLK = 0x06;
(void)(MTIMSC == 0); /* Overflow int. flag clearing (first part) */
/* MTIMSC: TOF=0,TOIE=1,TRST=1,TSTP=0 */
MTIMSC = 0x60; /* Int. flag clearing (2nd part) and timer control register setting */
/* ### Init_GPIO init code */
/* PTAD: PTAD3=0 */
PTAD &= (unsigned char)~0x08;
/* ### */
} /*MCU_init*/
The mcu just enter in stop mode one time, but i want that he enter every time that the KBI ends.