/* ** =================================================================== ** Method : timer_Init (component Init_RTC) ** ** Description : ** This method initializes registers of the RTC module ** according to this Peripheral Initialization Bean settings. ** Call this method in the user code to initialize the ** module. By default, the method is called by PE ** automatically; see "Call Init method" property of the ** bean for more details. ** Parameters : None ** Returns : Nothing ** =================================================================== */ void timer_Init(void) { /* RTCMOD: RTCMOD=0x7A */ setReg8(RTCMOD, 0x7A); /* Set modulo register */ /* RTCSC: RTIF=1,RTCLKS=2,RTIE=1,RTCPS=5 */ setReg8(RTCSC, 0xD5); /* Configure RTC */ }
/* ** =================================================================== ** Method : IFsh1_Init (component IntFLASH) ** ** Description : ** Description_Init - Initializes the associated peripheral(s) ** and the component's internal variables. The method is called ** automatically as a part of the application initialization code. ** This method is internal. It is used by Processor Expert only. ** =================================================================== */ void IFsh1_Init(void) { /* FSTAT: FCBEF=0,FCCF=0,FPVIOL=1,FACCERR=1,??=0,FBLANK=0,??=0,??=0 */ setReg8(FSTAT, 0x30U); /* Clear FPVIOL & FACERR flag */ /* FCDIV: DIVLD=0,PRDIV8=1,DIV5=0,DIV4=0,DIV3=1,DIV2=1,DIV1=1,DIV0=1 */ setReg8(FCDIV, 0x4FU); /* Initialize FCDIV register */ }
/* ** =================================================================== ** Method : Byte1_SetDir (bean ByteIO) ** ** Description : ** This method sets direction of the bean. ** Parameters : ** NAME - DESCRIPTION ** Dir - Direction to set (FALSE or TRUE) ** FALSE = Input, TRUE = Output ** Returns : Nothing ** =================================================================== */ void Byte1_SetDir(bool Dir) { if (Dir) { setReg8(PORTB, Shadow_B); /* PB0-PB7=Shadow_B[bits 0-7] */ setReg8(DDRB, 255); /* DDRB7=1, DDRB6=1, DDRB5=1, DDRB4=1, DDRB3=1, DDRB2=1, DDRB1=1, DDRB0=1 */ } else { /* !Dir */ setReg8(DDRB, 0); /* DDRB7=0, DDRB6=0, DDRB5=0, DDRB4=0, DDRB3=0, DDRB2=0, DDRB1=0, DDRB0=0 */ } /* !Dir */ }
/* ** =================================================================== ** Method : Timer_Init (component TimerInt) ** ** Description : ** Initializes the associated peripheral(s) and the component ** internal variables. The method is called automatically as a ** part of the application initialization code. ** This method is internal. It is used by Processor Expert only. ** =================================================================== */ void Timer_Init(void) { /* RTCSC: RTIF=0,RTCLKS=0,RTIE=0,RTCPS=0 */ setReg8(RTCSC, 0x00U); /* Stop HW */ Timer_SetCV(0x00U); /* Initialize appropriate value to the compare/modulo/reload register */ RTCMOD = RTCMOD; /* Reset HW counter */ /* RTCSC: RTIF=1,RTCLKS=2,RTIE=1,RTCPS=8 */ setReg8(RTCSC, 0xD8U); /* Run RTC (select clock source, set frequency and enable interrupt) */ }
/* ** =================================================================== ** Method : AS1_Init (bean AsynchroSerial) ** ** Description : ** Initializes the associated peripheral(s) and internal ** variables of the bean. The method is called automatically as a ** part of the application initialization code. ** This method is internal. It is used by Processor Expert only. ** =================================================================== */ void AS1_Init(void) { SerFlag = 0; /* Reset flags */ /* SCICR1: LOOPS=0,SCISWAI=1,RSRC=0,M=0,WAKE=0,ILT=0,PE=0,PT=0 */ setReg8(SCICR1, 64); /* SCISR2: ??=0,??=0,??=0,??=0,??=0,BRK13=0,TXDIR=0,RAF=0 */ setReg8(SCISR2, 0); (void) SCISR1; /* Reset interrupt request flags */ /* SCICR2: SCTIE=0,TCIE=0,RIE=0,ILIE=0,TE=0,RE=0,RWU=0,SBK=0 */ SCICR2 = 0; /* Disable error interrupts */ SCIBD = 104; /* Set prescaler bits */ SCICR2 |= (SCICR2_TE_MASK | SCICR2_RE_MASK | SCICR2_RIE_MASK); /* Enable transmitter, Enable receiver, Enable receiver interrupt */ }
/* ** =================================================================== ** Method : B_1_Init (component KBI) ** ** Description : ** Initializes the associated peripheral(s) and the component ** internal variables. The method is called automatically as a ** part of the application initialization code. ** This method is internal. It is used by Processor Expert only. ** =================================================================== */ void B_1_Init(void) { /* KBI1ES: KBEDG7=0,KBEDG6=0,KBEDG5=0,KBEDG4=0,KBEDG3=0,KBEDG2=0,KBEDG1=0,KBEDG0=0 */ setReg8(KBI1ES, 0x00U); /* KBI1SC: ??=0,??=0,??=0,??=0,KBF=0,KBACK=0,KBIE=0,KBIMOD=0 */ setReg8(KBI1SC, 0x00U); /* KBI1PE: KBIPE2=1 */ setReg8Bits(KBI1PE, 0x04U); /* Enable appropriate interrupt pin(s) */ /* KBI1SC: KBACK=1 */ setReg8Bits(KBI1SC, 0x04U); /* Clear the interrupt flag */ /* KBI1SC: KBIE=1 */ setReg8Bits(KBI1SC, 0x02U); /* Enable interrupts */ }
/* ** =================================================================== ** Method : M_1_Init (component PWM) ** ** Description : ** Initializes the associated peripheral(s) and the components ** internal variables. The method is called automatically as a ** part of the application initialization code. ** This method is internal. It is used by Processor Expert only. ** =================================================================== */ void M_1_Init(void) { /* TPM1SC: TOF=0,TOIE=0,CPWMS=0,CLKSB=0,CLKSA=0,PS2=0,PS1=0,PS0=0 */ setReg8(TPM1SC, 0x00U); /* Disable device */ /* TPM1C1SC: CH1F=0,CH1IE=0,MS1B=1,MS1A=1,ELS1B=1,ELS1A=1,??=0,??=0 */ setReg8(TPM1C1SC, 0x3CU); /* Set up PWM mode with output signal level low */ ActualRatio.Value = 0xFFFFU; /* Store initial value of the ratio */ /* TPM1MOD: BIT15=1,BIT14=1,BIT13=1,BIT12=1,BIT11=0,BIT10=1,BIT9=0,BIT8=1,BIT7=1,BIT6=1,BIT5=0,BIT4=0,BIT3=0,BIT2=0,BIT1=1,BIT0=0 */ setReg16(TPM1MOD, 0xF5C2U); /* Set modulo register */ SetRatio(); /* Calculate and set up new values of the compare according to the selected speed CPU mode */ (void)getReg8(TPM1SC); /* Dummy read of the TPM1SC register to reset flag */ /* TPM1SC: TOF=0,TOIE=1 */ clrSetReg8Bits(TPM1SC, 0x80U, 0x40U); /* Clear Overflow interrupt flag and enable Overflow interrupt */ }
/* ** =================================================================== ** Method : hwExpIn_Init (bean AsynchroSerial) ** ** Description : ** Initializes the associated peripheral(s) and the bean internal ** variables. The method is called automatically as a part of the ** application initialization code. ** This method is internal. It is used by Processor Expert only. ** =================================================================== */ void hwExpIn_Init(void) { SerFlag = 0; /* Reset flags */ EnUser = TRUE; /* Enable device */ /* SCI2C1: LOOPS=0,SCISWAI=0,RSRC=0,M=0,WAKE=0,ILT=0,PE=0,PT=0 */ setReg8(SCI2C1, 0x00); /* Configure the SCI */ /* SCI2C3: R8=0,T8=0,TXDIR=0,TXINV=0,ORIE=0,NEIE=0,FEIE=0,PEIE=0 */ setReg8(SCI2C3, 0x00); /* Disable error interrupts */ /* SCI2S2: LBKDIF=0,RXEDGIF=0,??=0,RXINV=0,RWUID=0,BRK13=0,LBKDE=0,RAF=0 */ setReg8(SCI2S2, 0x00); /* SCI2C2: TIE=0,TCIE=0,RIE=0,ILIE=0,TE=0,RE=0,RWU=0,SBK=0 */ setReg8(SCI2C2, 0x00); /* Disable all interrupts */ hwExpIn_SetHigh(); /* Initial speed CPU mode is high */ }
void __initialize_hardware(void) { /*** !!! Here you can place your own code using property "User code before PE initialization" on the build options tab of the CPU component. !!! ***/ /* ### MCF51QE128_64 "Cpu" init code ... */ /* PE initialization code after reset */ /* Common initialization of the write once registers */ /* SOPT1: COPE=0,COPT=1,STOPE=0,WAITE=1,??=0,RSTOPE=0,BKGDPE=1,RSTPE=1 */ setReg8(SOPT1, 0x53U); /* SPMSC1: LVDF=0,LVDACK=0,LVDIE=0,LVDRE=1,LVDSE=1,LVDE=0,??=0,BGBE=0 */ setReg8(SPMSC1, 0x18U); /* SPMSC2: LPR=0,LPRS=0,LPWUI=0,??=0,PPDF=0,PPDACK=0,PPDE=1,PPDC=0 */ setReg8(SPMSC2, 0x02U); /* SPMSC3: LVDV=0,LVWV=0,LVWIE=0 */ clrReg8Bits(SPMSC3, 0x38U); /* Initialization of CPU registers */ /*lint -save -e950 Disable MISRA rule (1.1) checking. */ asm { /* VBR: ??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,ADDRESS=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0 */ clr.l d0 movec d0,VBR /* CPUCR: ARD=0,IRD=0,IAE=0,IME=0,BWD=0,??=0,FSD=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0 */ clr.l d0 movec d0,CPUCR } /*lint -restore Enable MISRA rule (1.1) checking. */ /* System clock initialization */ /*lint -save -e923 Disable MISRA rule (11.3) checking. */ if (*(unsigned char*)0x03FFU != 0xFFU) { /* Test if the device trim value is stored on the specified address */ ICSTRM = *(unsigned char*)0x03FFU; /* Initialize ICSTRM register from a non volatile memory */ ICSSC = (unsigned char)((*(unsigned char*)0x03FEU) & (unsigned char)0x01U); /* Initialize ICSSC register from a non volatile memory */ } /*lint -restore Enable MISRA rule (11.3) checking. */ /* ICSC1: CLKS=0,RDIV=0,IREFS=1,IRCLKEN=1,IREFSTEN=0 */ setReg8(ICSC1, 0x06U); /* Initialization of the ICS control register 1 */ /* ICSC2: BDIV=0,RANGE=0,HGO=0,LP=0,EREFS=0,ERCLKEN=0,EREFSTEN=0 */ setReg8(ICSC2, 0x00U); /* Initialization of the ICS control register 2 */ while(ICSSC_IREFST == 0U) { /* Wait until the source of reference clock is internal clock */ } /* ICSSC: DRST_DRS=2,DMX32=0 */ clrSetReg8Bits(ICSSC, 0x60U, 0x80U); /* Initialization of the ICS status and control */ while((ICSSC & 0xC0U) != 0x80U) { /* Wait until the FLL switches to High range DCO mode */ } /*** End of PE initialization code after reset ***/ /*** !!! Here you can place your own code using property "User code after PE initialization" on the build options tab of the CPU component. !!! ***/ }
/* ** =================================================================== ** Method : ADC_Init (component ADC) ** ** Description : ** Initializes the associated peripheral(s) and the component's ** internal variables. The method is called automatically as a ** part of the application initialization code. ** This method is internal. It is used by Processor Expert only. ** =================================================================== */ void ADC_Init(void) { /* ADCSC1: COCO=0,AIEN=0,ADCO=0,ADCH4=1,ADCH3=1,ADCH2=1,ADCH1=1,ADCH0=1 */ setReg8(ADCSC1, 0x1FU); /* Disable the module */ /* ADCSC2: ADACT=0,ADTRG=0,ACFE=0,ACFGT=0,??=0,??=0,??=0,??=0 */ setReg8(ADCSC2, 0x00U); /* Disable HW trigger and autocompare */ EnUser = TRUE; /* Enable device */ ADC_EnEvent = TRUE; /* Enable events */ OutFlg = 0U; /* No measured value */ ModeFlg = STOP; /* Device isn't running */ /* ADCCFG: ADLPC=0,ADIV1=1,ADIV0=0,ADLSMP=0,MODE1=0,MODE0=1,ADICLK1=0,ADICLK0=0 */ setReg8(ADCCFG, 0x44U); /* Set prescaler bits */ ADC_HWEnDi(); /* Enable/disable device according to the status flags */ }
/* ** =================================================================== ** Method : MotorD1_Init (component PWM) ** ** Description : ** Initializes the associated peripheral(s) and the components ** internal variables. The method is called automatically as a ** part of the application initialization code. ** This method is internal. It is used by Processor Expert only. ** =================================================================== */ void MotorD1_Init(void) { /* TPM3SC: TOF=0,TOIE=0,CPWMS=0,CLKSB=0,CLKSA=0,PS2=0,PS1=0,PS0=0 */ setReg8(TPM3SC, 0x00U); /* Disable device */ /* TPM3C0SC: CH0F=0,CH0IE=0,MS0B=1,MS0A=1,ELS0B=1,ELS0A=0,??=0,??=0 */ setReg8(TPM3C0SC, 0x38U); /* Set up PWM mode with output signal level high */ ActualRatio = 0x00U; /* Store initial value of the ratio */ EnUser = FALSE; /* Disable device */ /* TPM3MOD: BIT15=0,BIT14=1,BIT13=1,BIT12=0,BIT11=0,BIT10=0,BIT9=1,BIT8=0,BIT7=0,BIT6=1,BIT5=0,BIT4=0,BIT3=1,BIT2=1,BIT1=0,BIT0=1 */ setReg16(TPM3MOD, 0x624DU); /* Set modulo register */ /* TPM3C0SC: CH0F=0,CH0IE=0,MS0B=1,MS0A=0,ELS0B=0,ELS0A=0,??=0,??=0 */ setReg8(TPM3C0SC, 0x20U); /* Temporary set compare mode to enable modifications of compare register */ SetRatio(); /* Calculate and set up new values of the compare according to the selected speed CPU mode */ HWEnDi(); /* Enable/disable device according to status flags */ }
/* ** =================================================================== ** Method : HWEnDi (component PWM) ** ** Description : ** Enables or disables the peripheral(s) associated with the ** component. The method is called automatically as a part of the ** Enable and Disable methods and several internal methods. ** This method is internal. It is used by Processor Expert only. ** =================================================================== */ static void HWEnDi(void) { if (EnUser) { if (PTCD_PTCD0) { /* TPM3C0SC: CH0F=0,CH0IE=0,MS0B=1,MS0A=1,ELS0B=1,ELS0A=0,??=0,??=0 */ setReg8(TPM3C0SC, 0x38U); /* Set up PWM mode with output signal level high */ } else { /* TPM3C0SC: CH0F=0,CH0IE=0,MS0B=1,MS0A=1,ELS0B=1,ELS0A=1,??=0,??=0 */ setReg8(TPM3C0SC, 0x3CU); /* Set up PWM mode with output signal level low */ } } else { /* TPM3C0SC: CH0F=0,CH0IE=0,MS0B=0,MS0A=0,ELS0B=0,ELS0A=0,??=0,??=0 */ setReg8(TPM3C0SC, 0x00U); /* Disable output signal */ } }
/* ** =================================================================== ** Method : M3_ESC_Init (component PWM) ** ** Description : ** Initializes the associated peripheral(s) and the components ** internal variables. The method is called automatically as a ** part of the application initialization code. ** This method is internal. It is used by Processor Expert only. ** =================================================================== */ void M3_ESC_Init(void) { /* TPM1C2SC: CH2F=0,CH2IE=0,MS2B=1,MS2A=1,ELS2B=1,ELS2A=1,??=0,??=0 */ setReg8(TPM1C2SC, 0x3CU); /* Set up PWM mode with output signal level low */ ActualRatio = 0x00U; /* Store initial value of the ratio */ SetRatio(); /* Calculate and set up new values of the compare according to the selected speed CPU mode */ }
/* ** =================================================================== ** Method : M_1_Disable (component PWM) ** Description : ** This method disables the component - it stops the signal ** generation and events calling. When the timer is disabled, ** it is possible to call <ClrValue> and <SetValue> methods. ** Parameters : None ** Returns : ** --- - Error code, possible codes: ** ERR_OK - OK ** ERR_SPEED - This device does not work in ** the active speed mode ** =================================================================== */ byte M_1_Disable(void) { /* TPM1SC: TOIE=0 */ clrReg8Bits(TPM1SC, 0x40U); /* Disable Timer Overflow Interrupt */ /* TPM1C1SC: CH1F=0,CH1IE=0,MS1B=0,MS1A=0,ELS1B=0,ELS1A=0,??=0,??=0 */ setReg8(TPM1C1SC, 0x00U); /* Disable output signal */ return ERR_OK; /* OK */ }
/* ** =================================================================== ** Method : hwI2c_Init (bean InternalI2C) ** ** Description : ** Initializes the associated peripheral(s) and the bean internal ** variables. The method is called automatically as a part of the ** application initialization code. ** This method is internal. It is used by Processor Expert only. ** =================================================================== */ void hwI2c_Init(void) { hwI2c_SerFlag = 0x80; /* Reset all flags */ EnUser = TRUE; /* Enable device */ /* IIC2F: MULT1=0,MULT0=0,ICR5=0,ICR4=1,ICR3=0,ICR2=0,ICR1=1,ICR0=1 */ setReg8(IIC2F, 0x13); hwI2c_SetHigh(); /* Initial speed CPU mode is high */ }
/* ** =================================================================== ** Method : PE_low_level_init (component MC9S08SH8_20) ** ** Description : ** Initializes beans and provides common register initialization. ** The method is called automatically as a part of the ** application initialization code. ** This method is internal. It is used by Processor Expert only. ** =================================================================== */ void PE_low_level_init(void) { /* Common initialization of the CPU registers */ /* PTCD: PTCD0=0 */ clrReg8Bits(PTCD, 0x01); /* PTCPE: PTCPE0=0 */ clrReg8Bits(PTCPE, 0x01); /* PTCDD: PTCDD0=1 */ setReg8Bits(PTCDD, 0x01); /* PTAPE: PTAPE5=0,PTAPE0=0 */ clrReg8Bits(PTAPE, 0x21); /* PTADD: PTADD5=0,PTADD0=0 */ clrReg8Bits(PTADD, 0x21); /* PTBPE: PTBPE6=0 */ clrReg8Bits(PTBPE, 0x40); /* PTBDD: PTBDD6=0 */ clrReg8Bits(PTBDD, 0x40); /* PTASE: PTASE4=0,PTASE3=0,PTASE2=0,PTASE1=0,PTASE0=0 */ clrReg8Bits(PTASE, 0x1F); /* PTBSE: PTBSE7=0,PTBSE6=0,PTBSE5=0,PTBSE4=0,PTBSE3=0,PTBSE2=0,PTBSE1=0,PTBSE0=0 */ setReg8(PTBSE, 0x00); /* PTCSE: PTCSE3=0,PTCSE2=0,PTCSE1=0,PTCSE0=0 */ clrReg8Bits(PTCSE, 0x0F); /* PTADS: ??=0,??=0,??=0,PTADS4=1,PTADS3=1,PTADS2=1,PTADS1=1,PTADS0=1 */ setReg8(PTADS, 0x1F); /* PTBDS: PTBDS7=1,PTBDS6=1,PTBDS5=1,PTBDS4=1,PTBDS3=1,PTBDS2=1,PTBDS1=1,PTBDS0=1 */ setReg8(PTBDS, 0xFF); /* PTCDS: ??=0,??=0,??=0,??=0,PTCDS3=1,PTCDS2=1,PTCDS1=1,PTCDS0=1 */ setReg8(PTCDS, 0x0F); /* ### Shared modules init code ... */ /* ### BitIO "Bit1" init code ... */ /* ### Timer capture encapsulation "Cap1" init code ... */ Cap1_Init(); /* ### TimerInt "TI1" init code ... */ TI1_Init(); /* ### External interrupt "EInt1" init code ... */ /* IRQSC: ??=0,IRQPDD=1,IRQEDG=0,IRQPE=1,IRQF=0,IRQACK=0,IRQIE=0,IRQMOD=1 */ IRQSC = 0x51; IRQSC_IRQACK = 0x01; IRQSC_IRQIE = 0x01; /* ### BitIO "Bit2" init code ... */ /* ### Init_FLASH "FLASH1" init code ... */ FLASH1_Init(); __EI(); /* Enable interrupts */ }
void _EntryPoint(void) { /* ### MC9S08SH8_20 "Cpu" init code ... */ /* PE initialization code after reset */ /* Common initialization of the write once registers */ /* SOPT1: COPT=0,STOPE=0,??=0,??=0,IICPS=0,BKGDPE=1,RSTPE=0 */ setReg8(SOPT1, 0x02); /* SOPT2: COPCLKS=0,COPW=0,??=0,ACIC=0,??=0,??=0,T1CH1PS=0,T1CH0PS=0 */ setReg8(SOPT2, 0x00); /* SPMSC1: LVWF=0,LVWACK=0,LVWIE=0,LVDRE=1,LVDSE=1,LVDE=1,??=0,BGBE=0 */ setReg8(SPMSC1, 0x1C); /* SPMSC2: ??=0,??=0,LVDV=0,LVWV=0,PPDF=0,PPDACK=0,??=0,PPDC=0 */ setReg8(SPMSC2, 0x00); /* System clock initialization */ if (*(unsigned char*)0xFFAF != 0xFF) { /* Test if the device trim value is stored on the specified address */ ICSTRM = *(unsigned char*)0xFFAF; /* Initialize ICSTRM register from a non volatile memory */ ICSSC = *(unsigned char*)0xFFAE; /* Initialize ICSSC register from a non volatile memory */ } /* ICSC1: CLKS=0,RDIV=0,IREFS=1,IRCLKEN=1,IREFSTEN=0 */ setReg8(ICSC1, 0x06); /* Initialization of the ICS control register 1 */ /* ICSC2: BDIV=2,RANGE=0,HGO=0,LP=0,EREFS=0,ERCLKEN=0,EREFSTEN=0 */ setReg8(ICSC2, 0x80); /* Initialization of the ICS control register 2 */ while(!ICSSC_IREFST) { /* Wait until the source of reference clock is internal clock */ } /* GNGC: GNGPS7=0,GNGPS6=0,GNGPS5=0,GNGPS4=0,GNGPS3=0,GNGPS2=0,GNGPS1=0,GNGEN=0 */ setReg8(GNGC, 0x00); /*** End of PE initialization code after reset ***/ __asm jmp _Startup ; /* Jump to C startup code */ }
/* ** =================================================================== ** Method : statusLED_SetDir (component BitIO) ** Description : ** This method sets direction of the component. ** Parameters : ** NAME - DESCRIPTION ** Dir - Direction to set (FALSE or TRUE) ** FALSE = Input, TRUE = Output ** Returns : Nothing ** =================================================================== */ void statusLED_SetDir(bool Dir) { if (Dir) { setReg8(PTGD, (getReg8(PTGD) & (byte)(~(byte)0x01U)) | (Shadow_PTG & 0x01U)); /* PTGD0=Shadow_PTG[bit 0] */ setReg8Bits(PTGDD, 0x01U); /* PTGDD0=0x01U */ } else { /* !Dir */ clrReg8Bits(PTGDD, 0x01U); /* PTGDD0=0x00U */ } /* !Dir */ }
/* ** =================================================================== ** Method : TI1_Init (component TimerInt) ** ** Description : ** Initializes the associated peripheral(s) and the component ** internal variables. The method is called automatically as a ** part of the application initialization code. ** This method is internal. It is used by Processor Expert only. ** =================================================================== */ void TI1_Init(void) { /* RTCSC: RTIF=0,RTCLKS=0,RTIE=0,RTCPS=0 */ setReg8(RTCSC, 0x00U); /* Stop HW */ EnUser = TRUE; /* Enable device */ TI1_SetCV(0x0FU); /* Initialize appropriate value to the compare/modulo/reload register */ RTCMOD = RTCMOD; /* Reset HW counter */ HWEnDi(); }
/* ** =================================================================== ** Method : powerLED_SetDir (component BitIO) ** Description : ** This method sets direction of the component. ** Parameters : ** NAME - DESCRIPTION ** Dir - Direction to set (FALSE or TRUE) ** FALSE = Input, TRUE = Output ** Returns : Nothing ** =================================================================== */ void powerLED_SetDir(bool Dir) { if (Dir) { setReg8(PTGD, (getReg8(PTGD) & (byte)(~(byte)0x02U)) | (Shadow_PTG & 0x02U)); /* PTGD1=Shadow_PTG[bit 1] */ setReg8Bits(PTGDD, 0x02U); /* PTGDD1=0x01U */ } else { /* !Dir */ clrReg8Bits(PTGDD, 0x02U); /* PTGDD1=0x00U */ } /* !Dir */ }
/* ** =================================================================== ** Method : LedB_SetDir (component BitIO) ** ** Description : ** This method sets direction of the bean. ** Parameters : ** NAME - DESCRIPTION ** Dir - Direction to set (FALSE or TRUE) ** FALSE = Input, TRUE = Output ** Returns : Nothing ** =================================================================== */ void LedB_SetDir(bool Dir) { if (Dir) { setReg8(PTBD, (getReg8(PTBD) & (~0x08)) | (Shadow_PTB & 0x08)); /* PTBD3=Shadow_PTB[bit 3] */ setReg8Bits(PTBDD, 0x08); /* PTBDD3=0x01 */ } else { /* !Dir */ clrReg8Bits(PTBDD, 0x08); /* PTBDD3=0x00 */ } /* !Dir */ }
/* ** =================================================================== ** Method : M_1_Enable (component PWM) ** Description : ** This method enables the component - it starts the signal ** generation. Events may be generated (<DisableEvent> ** /<EnableEvent>). ** Parameters : None ** Returns : ** --- - Error code, possible codes: ** ERR_OK - OK ** ERR_SPEED - This device does not work in ** the active speed mode ** =================================================================== */ byte M_1_Enable(void) { (void)getReg8(TPM1SC); /* Dummy read of the TPM1SC register to reset flag */ /* TPM1SC: TOF=0,TOIE=1 */ clrSetReg8Bits(TPM1SC, 0x80U, 0x40U); /* Clear Overflow interrupt flag and enable Overflow interrupt */ /* TPM1C1SC: CH1F=0,CH1IE=0,MS1B=1,MS1A=1,ELS1B=1,ELS1A=1,??=0,??=0 */ setReg8(TPM1C1SC, 0x3CU); /* Set up PWM mode with output signal level low */ return ERR_OK; /* OK */ }
/* ** =================================================================== ** Method : HWEnDi (component TimerInt) ** ** Description : ** Enables or disables the peripheral(s) associated with the ** component. The method is called automatically as a part of the ** Enable and Disable methods and several internal methods. ** This method is internal. It is used by Processor Expert only. ** =================================================================== */ static void HWEnDi(void) { if (EnUser) { /* RTCSC: RTIF=1,RTCLKS=2,RTIE=1,RTCPS=8 */ setReg8(RTCSC, 0xD8U); /* Run RTC (select clock source; set frequency and enable interrupt) */ } else { /* RTCSC: RTCPS=0 */ clrReg8Bits(RTCSC, 0x0FU); /* Stop counter */ } }
/* ** =================================================================== ** Method : Serial_2_Init (component AsynchroSerial) ** ** Description : ** Initializes the associated peripheral(s) and the component's ** internal variables. The method is called automatically as a ** part of the application initialization code. ** This method is internal. It is used by Processor Expert only. ** =================================================================== */ void Serial_2_Init(void) { SerFlag = 0x00U; /* Reset flags */ Serial_2_InpLen = 0x00U; /* No char in the receive buffer */ InpIndxR = 0x00U; /* Reset read index to the receive buffer */ InpIndxW = 0x00U; /* Reset write index to the receive buffer */ /* SCI2C1: LOOPS=0,SCISWAI=0,RSRC=0,M=0,WAKE=0,ILT=0,PE=0,PT=0 */ setReg8(SCI2C1, 0x00U); /* Configure the SCI */ /* SCI2C3: R8=0,T8=0,TXDIR=0,TXINV=0,ORIE=0,NEIE=0,FEIE=0,PEIE=0 */ setReg8(SCI2C3, 0x00U); /* Disable error interrupts */ /* SCI2C2: TIE=0,TCIE=0,RIE=0,ILIE=0,TE=0,RE=0,RWU=0,SBK=0 */ setReg8(SCI2C2, 0x00U); /* Disable all interrupts */ /* SCI2S2: LBKDIF=0,RXEDGIF=0,??=0,RXINV=0,RWUID=0,BRK13=0,LBKDE=0,RAF=0 */ setReg8(SCI2S2, 0x00U); SCI2BDH = 0x05U; /* Set high divisor register (enable device) */ SCI2BDL = 0x1FU; /* Set low divisor register (enable device) */ /* SCI2C3: ORIE=1,NEIE=1,FEIE=1,PEIE=1 */ SCI2C3 |= 0x0FU; /* Enable error interrupts */ SCI2C2 |= (SCI2C2_TE_MASK | SCI2C2_RE_MASK | SCI2C2_RIE_MASK); /* Enable transmitter, Enable receiver, Enable receiver interrupt */ }
/* ** =================================================================== ** Method : Servo2_Init (bean PWM) ** ** Description : ** Initializes the associated peripheral(s) and the bean's ** internal variables. The method is called automatically as a ** part of the application initialization code. ** This method is internal. It is used by Processor Expert only. ** =================================================================== */ void Servo2_Init(void) { /* PWMCNT23: BIT15=0,BIT14=0,BIT13=0,BIT12=0,BIT11=0,BIT10=0,BIT9=0,BIT8=0,BIT7=0,BIT6=0,BIT5=0,BIT4=0,BIT3=0,BIT2=0,BIT1=0,BIT0=0 */ setReg16(PWMCNT23, 0); /* Reset Counter */ /* PWMSDN: PWMIF=1,PWMIE=0,PWMRSTRT=0,PWMLVL=0,??=0,PWM7IN=0,PWM7INL=0,PWM7ENA=0 */ setReg8(PWMSDN, 128); /* Emergency shutdown feature settings */ RatioStore = 4964; /* Store initial value of the ratio */ /* PWMDTY23: BIT15=0,BIT14=0,BIT13=0,BIT12=0,BIT11=0,BIT10=1,BIT9=0,BIT8=1,BIT7=1,BIT6=1,BIT5=1,BIT4=0,BIT3=1,BIT2=0,BIT1=1,BIT0=1 */ setReg16(PWMDTY23, 1515); /* Store initial value to the duty-compare register */ /* PWMPER23: BIT15=0,BIT14=1,BIT13=0,BIT12=0,BIT11=1,BIT10=1,BIT9=1,BIT8=0,BIT7=0,BIT6=0,BIT5=1,BIT4=0,BIT3=0,BIT2=0,BIT1=0,BIT0=0 */ setReg16(PWMPER23, 20000); /* and to the period register */ /* PWMPRCLK: ??=0,PCKB2=0,PCKB1=0,PCKB0=0,??=0,PCKA2=0,PCKA1=0,PCKA0=0 */ setReg8(PWMPRCLK, 0); /* Set prescaler register */ /* PWMSCLB: BIT7=0,BIT6=0,BIT5=0,BIT4=0,BIT3=0,BIT2=0,BIT1=0,BIT0=1 */ setReg8(PWMSCLB, 1); /* Set scale register */ /* PWMCLK: PCLK3=0 */ clrReg8Bits(PWMCLK, 8); /* Select clock source */ /* PWME: PWME3=1 */ setReg8Bits(PWME, 8); /* Run counter */ }
void _EntryPoint(void) { /* ### MC9S08PA16_32 "Cpu" init code ... */ /* PE initialization code after reset */ /* WDOG_CNT: CNT=0xC520 */ setReg16(WDOG_CNT, 0xC520U); /* First part of the WDG unlock sequence */ /* WDOG_CNT: CNT=0xD928 */ setReg16(WDOG_CNT, 0xD928U); /* Second part of the WDG unlock sequence */ /* Initialization of Init_WDOG */ /* WDOG_CS1: EN=1,INT=0,UPDATE=1,TST=0,DBG=0,WAIT=1,STOP=1 */ setReg8(WDOG_CS1, 0xA3U); /* WDOG_CS2: WIN=0,FLG=0,??=0,PRES=1,??=0,??=0,CLK=0 */ setReg8(WDOG_CS2, 0x10U); /* WDOG_TOVAL: TOVAL=0xF800 */ setReg16(WDOG_TOVAL, 0xF800U); /* Common initialization of the write once registers */ /* SYS_SOPT1: SCI0PS=0,BKGDPE=1,RSTPE=1,FWAKE=0,STOPE=0 */ clrSetReg8Bits(SYS_SOPT1, 0x83U, 0x0CU); /* PMC_SPMSC1: LVWIE=0,LVDRE=1,LVDSE=1,LVDE=1,BGBDS=0,BGBE=0 */ clrSetReg8Bits(PMC_SPMSC1, 0x23U, 0x1CU); /* PMC_SPMSC2: LVDV=0,LVWV=0 */ clrReg8Bits(PMC_SPMSC2, 0x70U); /* System clock initialization */ /*lint -save -e923 Disable MISRA rule (11.3) checking. */ if (*(uint8_t*)0xFF6FU != 0xFFU) { /* Test if the device trim value is stored on the specified address */ ICS_C3 = *(uint8_t*)0xFF6FU; /* Initialize ICS_C3 register from a non volatile memory */ ICS_C4 = (uint8_t)((*(uint8_t*)0xFF6EU) & (uint8_t)0x01U); /* Initialize ICS_C4 register from a non volatile memory */ } /*lint -restore Enable MISRA rule (11.3) checking. */ /* ICS_C1: CLKS=0,RDIV=0,IREFS=1,IRCLKEN=1,IREFSTEN=0 */ setReg8(ICS_C1, 0x06U); /* Initialization of the ICS control register 1 */ /* ICS_C2: BDIV=1,LP=0,??=0,??=0,??=0,??=0 */ setReg8(ICS_C2, 0x20U); /* Initialization of the ICS control register 2 */ /* ICS_C4: LOLIE=0,CME=0 */ clrReg8Bits(ICS_C4, 0xA0U); /*** End of PE initialization code after reset ***/ /*lint -save -e950 Disable MISRA rule (1.1) checking. */ __asm jmp _Startup ; /* Jump to C startup code */ /*lint -restore Enable MISRA rule (1.1) checking. */ }
/* ** =================================================================== ** Method : PE_low_level_init (bean MC9S12XS256_80) ** ** Description : ** Initializes beans and provides common register initialization. ** The method is called automatically as a part of the ** application initialization code. ** This method is internal. It is used by Processor Expert only. ** =================================================================== */ void PE_low_level_init(void) { /* Common initialization of the CPU registers */ /* PORTB: PB7=0,PB6=1,PB5=0,PB4=1,PB3=0,PB2=1,PB1=0,PB0=1 */ setReg8(PORTB, 85); /* PUCR: PUPBE=0 */ clrReg8Bits(PUCR, 2); /* DDRB: DDRB7=1,DDRB6=1,DDRB5=1,DDRB4=1,DDRB3=1,DDRB2=1,DDRB1=1,DDRB0=1 */ setReg8(DDRB, 255); /* CRGINT: LOCKIE=0,SCMIE=0 */ clrReg8Bits(CRGINT, 18); /* VREGCTRL: LVIE=0 */ clrReg8Bits(VREGCTRL, 2); /* COPCTL: WCOP=0,RSBCK=0,WRTMASK=0,??=0,??=0,CR2=0,CR1=0,CR0=0 */ setReg8(COPCTL, 0); /* DDR0AD0: DDR0AD07=1,DDR0AD06=1,DDR0AD05=1,DDR0AD04=1,DDR0AD03=1,DDR0AD02=1,DDR0AD01=1,DDR0AD00=1 */ setReg8(DDR0AD0, 255); /* DDRH: DDRH7=1,DDRH6=1,DDRH5=1,DDRH4=1,DDRH3=1,DDRH2=1,DDRH1=1,DDRH0=1 */ setReg8(DDRH, 255); /* DDRJ: DDRJ1=1,DDRJ0=1 */ setReg8Bits(DDRJ, 3); /* DDRK: DDRK7=1,DDRK5=1,DDRK4=1,DDRK3=1,DDRK2=1,DDRK1=1,DDRK0=1 */ setReg8Bits(DDRK, 191); /* DDRM: DDRM7=1,DDRM6=1 */ setReg8Bits(DDRM, 192); /* DDRP: DDRP6=1 */ setReg8Bits(DDRP, 64); /* DDRS: DDRS7=1,DDRS6=1,DDRS5=1,DDRS4=1 */ setReg8Bits(DDRS, 240); /* RDRIV: RDPE=0,RDPB=0,RDPA=0 */ clrReg8Bits(RDRIV, 19); /* RDRJ: RDRJ7=0,RDRJ6=0 */ clrReg8Bits(RDRJ, 192); /* RDRM: RDRM5=0,RDRM4=0,RDRM3=0,RDRM2=0,RDRM1=0,RDRM0=0 */ clrReg8Bits(RDRM, 63); /* RDRP: RDRP7=0,RDRP5=0,RDRP4=0,RDRP3=0,RDRP2=0,RDRP1=0,RDRP0=0 */ clrReg8Bits(RDRP, 191); /* RDRS: RDRS3=0,RDRS2=0,RDRS1=0,RDRS0=0 */ clrReg8Bits(RDRS, 15); /* RDRT: RDRT7=0,RDRT6=0,RDRT5=0,RDRT4=0,RDRT3=0,RDRT2=0,RDRT1=0,RDRT0=0 */ setReg8(RDRT, 0); /* RDR1AD0: RDR1AD07=0,RDR1AD06=0,RDR1AD05=0,RDR1AD04=0,RDR1AD03=0,RDR1AD02=0,RDR1AD01=0,RDR1AD00=0 */ setReg8(RDR1AD0, 0); /* IRQCR: IRQEN=0 */ clrReg8Bits(IRQCR, 64); /* ### MC9S12XS256_80 "Cpu" init code ... */ /* ### ByteIO "Byte1" init code ... */ Shadow_B = (byte)85; /* Initialize port "Byte1" shadow variable */ asm { PSHA LDAA #0 TFR A,CCRH PULA } __EI(); /* Enable interrupts */ }
void _EntryPoint(void) { /* ### MC9S08JM60_64 "Cpu" init code ... */ /* PE initialization code after reset */ /* Common initialization of the write once registers */ /* SOPT1: COPT=0,STOPE=0,??=1,??=0,??=0,??=1,??=1 */ setReg8(SOPT1, 0x13U); /* SPMSC1: LVWF=0,LVWACK=0,LVWIE=0,LVDRE=1,LVDSE=1,LVDE=1,??=0,BGBE=0 */ setReg8(SPMSC1, 0x1CU); /* SPMSC2: ??=0,??=0,LVDV=0,LVWV=0,PPDF=0,PPDACK=0,??=0,PPDC=0 */ setReg8(SPMSC2, 0x00U); /* System clock initialization */ /*lint -save -e923 Disable MISRA rule (11.3) checking. */ if (*(uint8_t*)0xFFAFU != 0xFFU) { /* Test if the device trim value is stored on the specified address */ MCGTRM = *(uint8_t*)0xFFAFU; /* Initialize MCGTRM register from a non volatile memory */ MCGSC = *(uint8_t*)0xFFAEU; /* Initialize MCGSC register from a non volatile memory */ } /*lint -restore Enable MISRA rule (11.3) checking. */ /* MCGC2: BDIV=1,RANGE=1,HGO=0,LP=0,EREFS=0,ERCLKEN=1,EREFSTEN=0 */ setReg8(MCGC2, 0x62U); /* Set MCGC2 register */ /* MCGC1: CLKS=0,RDIV=0,IREFS=1,IRCLKEN=1,IREFSTEN=0 */ setReg8(MCGC1, 0x06U); /* Set MCGC1 register */ /* MCGC3: LOLIE=0,PLLS=0,CME=0,??=0,VDIV=1 */ setReg8(MCGC3, 0x01U); /* Set MCGC3 register */ while(MCGSC_LOCK == 0U) { /* Wait until FLL is locked */ } /*** End of PE initialization code after reset ***/ /*lint -save -e950 Disable MISRA rule (1.1) checking. */ __asm jmp _Startup ; /* Jump to C startup code */ /*lint -restore Enable MISRA rule (1.1) checking. */ }
void _EntryPoint(void) { /* ### MC9S08SC4_16 "Cpu" init code ... */ /* PE initialization code after reset */ /* Common initialization of the write once registers */ /* SOPT1: COPT=1,STOPE=0,??=0,??=0,??=0,??=0,??=0 */ setReg8(SOPT1, 0x40U); /* SOPT2: COPCLKS=0,COPW=0,??=0,??=0,??=0,??=0,??=0,??=0 */ setReg8(SOPT2, 0x00U); /* SPMSC1: LVWF=0,LVWACK=0,LVWIE=0,LVDRE=1,LVDSE=1,LVDE=1,??=0,BGBE=0 */ setReg8(SPMSC1, 0x1CU); /* SPMSC2: ??=0,??=0,LVDV=0,LVWV=0,PPDF=0,PPDACK=0,??=0,PPDC=0 */ setReg8(SPMSC2, 0x00U); /* System clock initialization */ /* ICSC1: CLKS=0,RDIV=0,IREFS=1,IRCLKEN=1,IREFSTEN=0 */ setReg8(ICSC1, 0x06U); /* Initialization of the ICS control register 1 */ /* ICSC2: BDIV=0,RANGE=0,HGO=0,LP=0,EREFS=0,ERCLKEN=0,EREFSTEN=0 */ setReg8(ICSC2, 0x00U); /* Initialization of the ICS control register 2 */ while(ICSSC_IREFST == 0U) { /* Wait until the source of reference clock is internal clock */ SRS = 0x55U; /* Reset watchdog counter write 55, AA */ SRS = 0xAAU; } /* ICSSC: DRST_DRS=1,DMX32=0 */ clrSetReg8Bits(ICSSC, 0xA0U, 0x40U); /* Initialization of the ICS status and control */ while((ICSSC & 0xC0U) != 0x40U) { /* Wait until the FLL switches to Mid range DCO mode */ SRS = 0x55U; /* Reset watchdog counter write 55, AA */ SRS = 0xAAU; } /*** End of PE initialization code after reset ***/ /*lint -save -e950 Disable MISRA rule (1.1) checking. */ __asm jmp _Startup ; /* Jump to C startup code */ /*lint -restore Enable MISRA rule (1.1) checking. */ }
void _EntryPoint(void) { /* ### MC9S08JM16_48 "Cpu" init code ... */ /* PE initialization code after reset */ /* Common initialization of the write once registers */ /* SOPT1: COPT=0,STOPE=0,??=1,??=0,??=0,??=1,??=1 */ setReg8(SOPT1, 0x13); /* SPMSC1: LVWF=0,LVWACK=0,LVWIE=0,LVDRE=1,LVDSE=1,LVDE=1,??=0,BGBE=0 */ setReg8(SPMSC1, 0x1C); /* SPMSC2: ??=0,??=0,LVDV=0,LVWV=0,PPDF=0,PPDACK=0,??=0,PPDC=0 */ setReg8(SPMSC2, 0x00); /* System clock initialization */ if (*(unsigned char*)0xFFAF != 0xFF) { /* Test if the device trim value is stored on the specified address */ MCGTRM = *(unsigned char*)0xFFAF; /* Initialize MCGTRM register from a non volatile memory */ MCGSC = *(unsigned char*)0xFFAE; /* Initialize MCGSC register from a non volatile memory */ } /* MCGC2: BDIV=0,RANGE=0,HGO=0,LP=0,EREFS=0,ERCLKEN=0,EREFSTEN=0 */ setReg8(MCGC2, 0x00); /* Set MCGC2 register */ /* MCGC1: CLKS=0,RDIV=0,IREFS=1,IRCLKEN=1,IREFSTEN=0 */ setReg8(MCGC1, 0x06); /* Set MCGC1 register */ /* MCGC3: LOLIE=0,PLLS=0,CME=0,??=0,VDIV=1 */ setReg8(MCGC3, 0x01); /* Set MCGC3 register */ while(!MCGSC_LOCK) { /* Wait until FLL is locked */ } /*** End of PE initialization code after reset ***/ __asm jmp _Startup ; /* Jump to C startup code */ }