Code:
void MCU_init(void){ asm SEI; /* Disable interrupts */ /* ### MC9S08QE128_80 "Cpu" init code ... */ /* PE initialization code after reset */ /* Common initialization of the write once registers */ /* SOPT1: COPE=0,COPT=1,STOPE=0,RSTOPE=0,BKGDPE=1,RSTPE=0 */ SOPT1 = 0x42; /* SOPT2: COPCLKS=0,SPI1PS=0,ACIC2=0,IIC1PS=0,ACIC1=0 */ SOPT2 = 0x00; /* SPMSC1: LVDF=0,LVDACK=0,LVDIE=0,LVDRE=1,LVDSE=1,LVDE=1,BGBE=0 */ SPMSC1 = 0x1C; /* SPMSC2: LPR=0,LPRS=0,LPWUI=0,PPDF=0,PPDACK=0,PPDE=1,PPDC=0 */ SPMSC2 = 0x02; /* SPMSC3: LVDV=0,LVWV=0,LVWIE=0 */ SPMSC3 &= (unsigned char)~0x38; /* System clock initialization */ /* ICSC1: CLKS=0,RDIV=0,IREFS=0,IRCLKEN=0,IREFSTEN=0 */ ICSC1 = 0x00; /* Initialization of the ICS control register 1 */ /* ICSC2: BDIV=1,RANGE=0,HGO=0,LP=0,EREFS=1,ERCLKEN=0,EREFSTEN=0 */ ICSC2 = 0x44; /* Initialization of the ICS control register 2 */ while(!ICSSC_OSCINIT) { /* Wait until the initialization of the external crystal oscillator is completed */ } /* ICSSC: DRST_DRS=2,DMX32=1 */ ICSSC = (ICSSC & (unsigned char)~0x40) | (unsigned char)0xA0; /* Initialization of the ICS status and control */ while((ICSSC & 0xC4) != 0x80) { /* Wait until the FLL switches to High range DCO mode */ } /* Common initialization of the CPU registers */ /* SCGC1: TPM3=1,TPM2=1,TPM1=1,ADC=1,IIC2=1,IIC1=1,SCI2=1,SCI1=1 */ SCGC1 = 0xFF; /* SCGC2: DBG=1,FLS=1,IRQ=1,KBI=1,ACMP=1,RTC=1,SPI2=1,SPI1=1 */ SCGC2 = 0xFF; /* PTAPE: PTAPE0=0 */