/* ** =================================================================== ** 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 */ }
/* ** =================================================================== ** Method : PE_low_level_init (bean MC9S12XDT384_112) ** ** 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) { /* Initialization of RAM Protection (MMC module) */ /* RAMXGU: ??=1,XGU6=1,XGU5=1,XGU4=1,XGU3=1,XGU2=1,XGU1=1,XGU0=1 */ setReg8(RAMXGU, 255); /* RAMSHL: ??=1,SHL6=1,SHL5=1,SHL4=1,SHL3=1,SHL2=1,SHL1=1,SHL0=1 */ setReg8(RAMSHL, 255); /* RAMSHU: ??=1,SHU6=1,SHU5=1,SHU4=1,SHU3=1,SHU2=1,SHU1=1,SHU0=1 */ setReg8(RAMSHU, 255); /* RAMWPC: RWPE=0,??=0,??=0,??=0,??=0,??=0,AVIE=0,AVIF=0 */ setReg8(RAMWPC, 0); /* Common initialization of the CPU registers */ /* PORTA: PA0=1 */ setReg8Bits(PORTA, 1); /* PUCR: PUPAE=0 */ clrReg8Bits(PUCR, 1); /* DDRA: DDRA0=1 */ setReg8Bits(DDRA, 1); /* 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); /* RDRIV: RDPK=0,RDPE=0,RDPB=0,RDPA=0 */ clrReg8Bits(RDRIV, 147); /* RDR1AD1: RDR1AD115=0,RDR1AD114=0,RDR1AD113=0,RDR1AD112=0,RDR1AD111=0,RDR1AD110=0,RDR1AD19=0,RDR1AD18=0 */ setReg8(RDR1AD1, 0); /* RDRH: RDRH7=0,RDRH6=0,RDRH5=0,RDRH4=0,RDRH3=0,RDRH2=0,RDRH1=0,RDRH0=0 */ setReg8(RDRH, 0); /* RDRJ: RDRJ7=0,RDRJ6=0,RDRJ1=0,RDRJ0=0 */ clrReg8Bits(RDRJ, 195); /* RDRM: RDRM7=0,RDRM6=0,RDRM5=0,RDRM4=0,RDRM3=0,RDRM2=0,RDRM1=0,RDRM0=0 */ setReg8(RDRM, 0); /* RDRP: RDRP7=0,RDRP6=0,RDRP5=0,RDRP4=0,RDRP3=0,RDRP2=0,RDRP1=0,RDRP0=0 */ setReg8(RDRP, 0); /* RDRS: RDRS7=0,RDRS6=0,RDRS5=0,RDRS4=0,RDRS3=0,RDRS2=0,RDRS1=0,RDRS0=0 */ setReg8(RDRS, 0); /* 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); /* ### MC9S12XDT384_112 "Cpu" init code ... */ /* ### BitIO "Bit1" init code ... */ asm { PSHA LDAA #0 TFR A,CCRH PULA } __EI(); /* Enable interrupts */ }
/* ** =================================================================== ** 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 */ }
void _EntryPoint(void) { /* ### MC9S12XS256_80 "Cpu" init code ... */ /* PE initialization code after reset */ /* MMCCTL1: MGRAMON=0,??=0,DFIFRON=0,PGMIFRON=0,??=0,??=0,??=0,??=0 */ setReg8(MMCCTL1, 0); /* DIRECT: DP15=0,DP14=0,DP13=0,DP12=0,DP11=0,DP10=0,DP9=0,DP8=0 */ setReg8(DIRECT, 0); /* IVBR: IVB_ADDR=255 */ setReg8(IVBR, 255); /* ECLKCTL: NECLK=0,NCLKX2=1,DIV16=0,EDIV4=0,EDIV3=0,EDIV2=0,EDIV1=0,EDIV0=0 */ setReg8(ECLKCTL, 64); /* System clock initialization */ /* CLKSEL: PLLSEL=0,PSTP=0,XCLKS=0,??=0,PLLWAI=0,??=0,RTIWAI=0,COPWAI=0 */ setReg8(CLKSEL, 0); /* Select clock source from XTAL and set bits in CLKSEL reg. */ /* PLLCTL: CME=1,PLLON=0,FM1=0,FM0=0,FSTWKP=0,PRE=0,PCE=0,SCME=1 */ setReg8(PLLCTL, 129); /* Disable the PLL */ /* SYNR: VCOFRQ1=0,VCOFRQ0=1,SYNDIV5=0,SYNDIV4=0,SYNDIV3=0,SYNDIV2=1,SYNDIV1=0,SYNDIV0=0 */ setReg8(SYNR, 68); /* Set the multiplier register */ /* REFDV: REFFRQ1=1,REFFRQ0=0,REFDIV5=0,REFDIV4=0,REFDIV3=0,REFDIV2=0,REFDIV1=0,REFDIV0=1 */ setReg8(REFDV, 129); /* Set the divider register */ /* POSTDIV: ??=0,??=0,??=0,POSTDIV4=0,POSTDIV3=0,POSTDIV2=0,POSTDIV1=0,POSTDIV0=0 */ setReg8(POSTDIV, 0); /* Set the post divider register */ /* PLLCTL: CME=1,PLLON=1,FM1=0,FM0=0,FSTWKP=0,PRE=0,PCE=0,SCME=1 */ setReg8(PLLCTL, 193); while(!CRGFLG_LOCK) { /* Wait until the PLL is within the desired tolerance of the target frequency */ } /* CLKSEL: PLLSEL=1 */ setReg8Bits(CLKSEL, 128); /* Select clock source from PLL */ /* VREGHTCL: ??=0,??=0,VSEL=0,VAE=1,HTEN=0,HTDS=0,HTIE=0,HTIF=0 */ setReg8(VREGHTCL, 16); /*** End of PE initialization code after reset ***/ __asm("jmp _Startup"); /* Jump to C startup code */ }
/* ** =================================================================== ** Method : LED_RUN_PutVal (component BitIO) ** Description : ** This method writes the new output value. ** Parameters : ** NAME - DESCRIPTION ** Val - Output value. Possible values: ** FALSE - logical "0" (Low level) ** TRUE - logical "1" (High level) ** Returns : Nothing ** =================================================================== */ void LED_RUN_PutVal(bool Val) { if (Val) { setReg8Bits(PORT_PTAD, 0x01U); /* */ } else { /* !Val */ clrReg8Bits(PORT_PTAD, 0x01U); /* */ } /* !Val */ }
/* ** =================================================================== ** Method : LedG_PutVal (component BitIO) ** ** Description : ** This method writes the new output value. ** Parameters : ** NAME - DESCRIPTION ** Val - Output value. Possible values: ** FALSE - logical "0" (Low level) ** TRUE - logical "1" (High level) ** Returns : Nothing ** =================================================================== */ void LedG_PutVal(bool Val) { if (Val) { setReg8Bits(PTBD, 0x04); /* PTBD2=0x01 */ } else { /* !Val */ clrReg8Bits(PTBD, 0x04); /* PTBD2=0x00 */ } /* !Val */ }
/* ** =================================================================== ** Method : ACKNOWLEDGE_LED_PutVal (component BitIO) ** Description : ** This method writes the new output value. ** Parameters : ** NAME - DESCRIPTION ** Val - Output value. Possible values: ** FALSE - logical "0" (Low level) ** TRUE - logical "1" (High level) ** Returns : Nothing ** =================================================================== */ void ACKNOWLEDGE_LED_PutVal(bool Val) { if (Val) { setReg8Bits(PTDD, 0x40U); /* PTDD6=0x01U */ } else { /* !Val */ clrReg8Bits(PTDD, 0x40U); /* PTDD6=0x00U */ } /* !Val */ }
/* ** =================================================================== ** Method : led_PutVal (component BitIO) ** ** Description : ** This method writes the new output value. ** Parameters : ** NAME - DESCRIPTION ** Val - Output value. Possible values: ** FALSE - logical "0" (Low level) ** TRUE - logical "1" (High level) ** Returns : Nothing ** =================================================================== */ void led_PutVal(bool Val) { if (Val) { setReg8Bits(PTBD, 0x20); /* PTBD5=0x01 */ } else { /* !Val */ clrReg8Bits(PTBD, 0x20); /* PTBD5=0x00 */ } /* !Val */ }
/* ** =================================================================== ** Method : Bit2_PutVal (bean BitIO) ** ** Description : ** This method writes the new output value. ** Parameters : ** NAME - DESCRIPTION ** Val - Output value. Possible values: ** FALSE - logical "0" (Low level) ** TRUE - logical "1" (High level) ** Returns : Nothing ** =================================================================== */ void Bit2_PutVal(bool Val) { if (Val) { setReg8Bits(PORTB, 1); /* PB0=1 */ } else { /* !Val */ clrReg8Bits(PORTB, 1); /* PB0=0 */ } /* !Val */ }
/* ** =================================================================== ** Method : SquareWave_PutVal (component BitIO) ** ** Description : ** This method writes the new output value. ** Parameters : ** NAME - DESCRIPTION ** Val - Output value. Possible values: ** FALSE - logical "0" (Low level) ** TRUE - logical "1" (High level) ** Returns : Nothing ** =================================================================== */ void SquareWave_PutVal(bool Val) { if (Val) { setReg8Bits(PTED, 0x40U); /* PTED6=0x01U */ } else { /* !Val */ clrReg8Bits(PTED, 0x40U); /* PTED6=0x00U */ } /* !Val */ }
/* ** =================================================================== ** Method : Bit1_PutVal (component BitIO) ** ** Description : ** This method writes the new output value. ** Parameters : ** NAME - DESCRIPTION ** Val - Output value. Possible values: ** FALSE - logical "0" (Low level) ** TRUE - logical "1" (High level) ** Returns : Nothing ** =================================================================== */ void Bit1_PutVal(bool Val) { if (Val) { setReg8Bits(PTCD, 0x01); /* PTCD0=0x01 */ } else { /* !Val */ clrReg8Bits(PTCD, 0x01); /* PTCD0=0x00 */ } /* !Val */ }
/* ** =================================================================== ** Method : O6_PutVal (bean BitIO) ** ** Description : ** This method writes the new output value. ** Parameters : ** NAME - DESCRIPTION ** Val - Output value. Possible values: ** FALSE - logical "0" (Low level) ** TRUE - logical "1" (High level) ** Returns : Nothing ** =================================================================== */ void O6_PutVal(bool Val) { if (Val) { setReg8Bits(PTP, 32); /* PTP5=1 */ } else { /* !Val */ clrReg8Bits(PTP, 32); /* PTP5=0 */ } /* !Val */ }
/* ** =================================================================== ** Method : O2_PutVal (bean BitIO) ** ** Description : ** This method writes the new output value. ** Parameters : ** NAME - DESCRIPTION ** Val - Output value. Possible values: ** FALSE - logical "0" (Low level) ** TRUE - logical "1" (High level) ** Returns : Nothing ** =================================================================== */ void O2_PutVal(bool Val) { if (Val) { setReg8Bits(PTP, 2); /* PTP1=1 */ } else { /* !Val */ clrReg8Bits(PTP, 2); /* PTP1=0 */ } /* !Val */ }
/* ** =================================================================== ** Method : Ref2_PutVal (component BitIO) ** Description : ** This method writes the new output value. ** Parameters : ** NAME - DESCRIPTION ** Val - Output value. Possible values: ** FALSE - logical "0" (Low level) ** TRUE - logical "1" (High level) ** Returns : Nothing ** =================================================================== */ void Ref2_PutVal(bool Val) { if (Val) { setReg8Bits(PTBD, 0x01U); /* PTBD0=0x01U */ } else { /* !Val */ clrReg8Bits(PTBD, 0x01U); /* PTBD0=0x00U */ } /* !Val */ }
/* ** =================================================================== ** Method : En4_PutVal (component BitIO) ** Description : ** This method writes the new output value. ** Parameters : ** NAME - DESCRIPTION ** Val - Output value. Possible values: ** FALSE - logical "0" (Low level) ** TRUE - logical "1" (High level) ** Returns : Nothing ** =================================================================== */ void En4_PutVal(bool Val) { if (Val) { setReg8Bits(PTFD, 0x80U); /* PTFD7=0x01U */ } else { /* !Val */ clrReg8Bits(PTFD, 0x80U); /* PTFD7=0x00U */ } /* !Val */ }
/* ** =================================================================== ** Method : Bit8_PutVal (bean BitIO) ** ** Description : ** This method writes the new output value. ** Parameters : ** NAME - DESCRIPTION ** Val - Output value. Possible values: ** FALSE - logical "0" (Low level) ** TRUE - logical "1" (High level) ** Returns : Nothing ** =================================================================== */ void Bit8_PutVal(bool Val) { if (Val) { setReg8Bits(PORTB, 8); /* PB3=1 */ } else { /* !Val */ clrReg8Bits(PORTB, 8); /* PB3=0 */ } /* !Val */ }
/* ** =================================================================== ** 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 : 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 : 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 : Byte1_PutBit (bean ByteIO) ** ** Description : ** This method writes the new value to the specified bit ** of the output value. ** Parameters : ** NAME - DESCRIPTION ** Bit - Number of the bit (0 to 7) ** Val - New value of the bit (FALSE or TRUE) ** FALSE = "0" or "Low", TRUE = "1" or "High" ** Returns : Nothing ** =================================================================== */ void Byte1_PutBit(byte Bit, bool Val) { byte const Mask = Byte1_GetMsk(Bit); /* Temporary variable - put bit mask */ if (Val) { setReg8Bits(PORTB, Mask); /* [bit Bit]=1 */ } else { /* !Val */ clrReg8Bits(PORTB, Mask); /* [bit Bit]=0 */ } /* !Val */ }
/* ** =================================================================== ** Method : LedB_PutVal (component BitIO) ** ** Description : ** This method writes the new output value. ** a) direction = Input : sets the new output value; ** this operation will be shown on ** output after the direction has ** been switched to output ** (SetDir(TRUE);) ** b) direction = Output : directly writes the value to the ** appropriate pin ** Parameters : ** NAME - DESCRIPTION ** Val - Output value. Possible values: ** FALSE - logical "0" (Low level) ** TRUE - logical "1" (High level) ** Returns : Nothing ** =================================================================== */ void LedB_PutVal(bool Val) { if (Val) { setReg8Bits(PTBD, 0x08); /* PTBD3=0x01 */ Shadow_PTB |= (byte)0x08; /* Set-up shadow variable */ } else { /* !Val */ clrReg8Bits(PTBD, 0x08); /* PTBD3=0x00 */ Shadow_PTB &= (byte)~0x08; /* Set-up shadow variable */ } /* !Val */ }
/* ** =================================================================== ** Method : statusLED_PutVal (component BitIO) ** Description : ** This method writes the new output value. ** a) direction = Input : sets the new output value; ** this operation will be shown on ** output after the direction has ** been switched to output ** (SetDir(TRUE);) ** b) direction = Output : directly writes the value to the ** appropriate pin ** Parameters : ** NAME - DESCRIPTION ** Val - Output value. Possible values: ** FALSE - logical "0" (Low level) ** TRUE - logical "1" (High level) ** Returns : Nothing ** =================================================================== */ void statusLED_PutVal(bool Val) { if (Val) { setReg8Bits(PTGD, 0x01U); /* PTGD0=0x01U */ Shadow_PTG |= 0x01U; /* Set-up shadow variable */ } else { /* !Val */ clrReg8Bits(PTGD, 0x01U); /* PTGD0=0x00U */ Shadow_PTG &= 0xFEU; /* Set-up shadow variable */ } /* !Val */ }
/* ** =================================================================== ** Method : powerLED_PutVal (component BitIO) ** Description : ** This method writes the new output value. ** a) direction = Input : sets the new output value; ** this operation will be shown on ** output after the direction has ** been switched to output ** (SetDir(TRUE);) ** b) direction = Output : directly writes the value to the ** appropriate pin ** Parameters : ** NAME - DESCRIPTION ** Val - Output value. Possible values: ** FALSE - logical "0" (Low level) ** TRUE - logical "1" (High level) ** Returns : Nothing ** =================================================================== */ void powerLED_PutVal(bool Val) { if (Val) { setReg8Bits(PTGD, 0x02U); /* PTGD1=0x01U */ Shadow_PTG |= 0x02U; /* Set-up shadow variable */ } else { /* !Val */ clrReg8Bits(PTGD, 0x02U); /* PTGD1=0x00U */ Shadow_PTG &= 0xFDU; /* Set-up shadow variable */ } /* !Val */ }
/* ** =================================================================== ** Method : Byte1_PutBit (bean ByteIO) ** ** Description : ** This method writes the new value to the specified bit ** of the output value. ** a) direction = Input : sets the value of the specified ** bit; this operation will be ** shown on output after the ** direction has been switched to ** output (SetDir(TRUE);) ** b) direction = Output : directly writes the value of the ** bit to the appropriate pin ** Parameters : ** NAME - DESCRIPTION ** Bit - Number of the bit (0 to 7) ** Val - New value of the bit (FALSE or TRUE) ** FALSE = "0" or "Low", TRUE = "1" or "High" ** Returns : Nothing ** =================================================================== */ void Byte1_PutBit(byte Bit, bool Val) { byte const Mask = Byte1_GetMsk(Bit); /* Temporary variable - put bit mask */ if (Val) { setReg8Bits(PORTB, Mask); /* [bit Bit]=1 */ Shadow_B |= Mask; /* Set appropriate bit in shadow variable */ } else { /* !Val */ clrReg8Bits(PORTB, Mask); /* [bit Bit]=0 */ Shadow_B &= (byte)~Mask; /* Clear appropriate bit in shadow variable */ } /* !Val */ }
/* ** =================================================================== ** Method : PE_low_level_init (component MC9S08JM60_64) ** ** Description : ** Initializes components 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 */ /* PTGD: PTGD1=0,PTGD0=1 */ clrSetReg8Bits(PTGD, 0x02U, 0x01U); /* PTGPE: PTGPE1=0,PTGPE0=0 */ clrReg8Bits(PTGPE, 0x03U); /* PTGDD: PTGDD1=1,PTGDD0=1 */ setReg8Bits(PTGDD, 0x03U); /* PTASE: PTASE5=0,PTASE4=0,PTASE3=0,PTASE2=0,PTASE1=0,PTASE0=0 */ clrReg8Bits(PTASE, 0x3FU); /* PTBSE: PTBSE7=0,PTBSE6=0,PTBSE5=0,PTBSE4=0,PTBSE3=0,PTBSE2=0,PTBSE1=0,PTBSE0=0 */ setReg8(PTBSE, 0x00U); /* PTCSE: PTCSE6=0,PTCSE5=0,PTCSE4=0,PTCSE3=0,PTCSE2=0,PTCSE1=0,PTCSE0=0 */ clrReg8Bits(PTCSE, 0x7FU); /* PTDSE: PTDSE7=0,PTDSE6=0,PTDSE5=0,PTDSE4=0,PTDSE3=0,PTDSE2=0,PTDSE1=0,PTDSE0=0 */ setReg8(PTDSE, 0x00U); /* PTESE: PTESE7=0,PTESE6=0,PTESE5=0,PTESE4=0,PTESE3=0,PTESE2=0,PTESE1=0,PTESE0=0 */ setReg8(PTESE, 0x00U); /* PTFSE: PTFSE7=0,PTFSE6=0,PTFSE5=0,PTFSE4=0,PTFSE3=0,PTFSE2=0,PTFSE1=0,PTFSE0=0 */ setReg8(PTFSE, 0x00U); /* PTGSE: PTGSE5=0,PTGSE4=0,PTGSE3=0,PTGSE2=0,PTGSE1=0,PTGSE0=0 */ clrReg8Bits(PTGSE, 0x3FU); /* PTADS: ??=0,??=0,PTADS5=1,PTADS4=1,PTADS3=1,PTADS2=1,PTADS1=1,PTADS0=1 */ setReg8(PTADS, 0x3FU); /* PTBDS: PTBDS7=1,PTBDS6=1,PTBDS5=1,PTBDS4=1,PTBDS3=1,PTBDS2=1,PTBDS1=1,PTBDS0=1 */ setReg8(PTBDS, 0xFFU); /* PTCDS: ??=0,PTCDS6=1,PTCDS5=1,PTCDS4=1,PTCDS3=1,PTCDS2=1,PTCDS1=1,PTCDS0=1 */ setReg8(PTCDS, 0x7FU); /* PTDDS: PTDDS7=1,PTDDS6=1,PTDDS5=1,PTDDS4=1,PTDDS3=1,PTDDS2=1,PTDDS1=1,PTDDS0=1 */ setReg8(PTDDS, 0xFFU); /* PTEDS: PTEDS7=1,PTEDS6=1,PTEDS5=1,PTEDS4=1,PTEDS3=1,PTEDS2=1,PTEDS1=1,PTEDS0=1 */ setReg8(PTEDS, 0xFFU); /* PTFDS: PTFDS7=1,PTFDS6=1,PTFDS5=1,PTFDS4=1,PTFDS3=1,PTFDS2=1,PTFDS1=1,PTFDS0=1 */ setReg8(PTFDS, 0xFFU); /* PTGDS: ??=0,??=0,PTGDS5=1,PTGDS4=1,PTGDS3=1,PTGDS2=1,PTGDS1=1,PTGDS0=1 */ setReg8(PTGDS, 0x3FU); /* ### Shared modules init code ... */ /* ### BitIO "powerLED" init code ... */ Shadow_PTG &= 0xFDU; /* Initialize pin shadow variable bit */ /* ### BitIO "statusLED" init code ... */ Shadow_PTG |= (byte)0x01U; /* Initialize pin shadow variable bit */ /* ### TimerInt "sampleTimer" init code ... */ sampleTimer_Init(); __EI(); /* Enable interrupts */ }
/* ** =================================================================== ** 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 */ }
extern "C" void _EntryPoint(void) { #ifdef debug clrSetReg8Bits(COPCTL, 131, 68); #else clrSetReg8Bits(COPCTL, 131, 4); #endif /* ### MC9S12GC16_80 "Cpu" init code ... */ /* PE initialization code after reset */ /* Initialization of the registers INITRG, INITRM, INITEE is done to protect them to be written accidentally later by the application */ *(byte*)INITRG_ADR = 0; /* Set the register map position */ asm("nop"); /* nop instruction */ /* INITRM: RAM15=0,RAM14=0,RAM13=0,RAM12=1,RAM11=0,??=0,??=0,RAMHAL=1 */ setReg8(INITRM, 17); /* Set the RAM map position */ /* MISC: ??=0,??=0,??=0,??=0,EXSTR1=1,EXSTR0=1,ROMHM=0,ROMON=1 */ setReg8(MISC, 13); /* PEAR: NOACCE=0,??=0,PIPOE=0,NECLK=1,LSTRE=0,RDWE=0,??=0,??=0 */ setReg8(PEAR, 16); /* System clock initialization */ /* CLKSEL: PLLSEL=0,PSTP=0,SYSWAI=0,ROAWAI=0,PLLWAI=0,CWAI=0,RTIWAI=0,COPWAI=0 */ setReg8(CLKSEL, 0); /* Select clock source from XTAL and set bits in CLKSEL reg. */ /* PLLCTL: CME=1,PLLON=0,AUTO=1,ACQ=1,??=0,PRE=0,PCE=0,SCME=0 */ setReg8(PLLCTL, 178);//setReg8(PLLCTL, 177); /* Disable the PLL */ /* SYNR: ??=0,??=0,SYN5=0,SYN4=0,SYN3=0,SYN2=0,SYN1=0,SYN0=1 */ setReg8(SYNR, 1); /* Set the multiplier register */ /* REFDV: ??=0,??=0,??=0,??=0,REFDV3=0,REFDV2=0,REFDV1=0,REFDV0=0 */ setReg8(REFDV, 0); /* Set the divider register */ /* PLLCTL: CME=1,PLLON=1,AUTO=1,ACQ=1,??=0,PRE=0,PCE=1,SCME=0 */ /*SCME=0 mejora la estabilidad*/ setReg8(PLLCTL, 242);//setReg8(PLLCTL, 243); //PERMITO CLOCK MON, HABILITO PLL, SINCRONIZO PLL AUTO, ?????, Y HABILITO SELF CLOCK; while(!CRGFLG_LOCK) { /* Wait until the PLL is within the desired tolerance of the target frequency */ } /* CLKSEL: PLLSEL=1 */ setReg8Bits(CLKSEL, 128); /* Select clock source from PLL */ /*** End of PE initialization code after reset ***/ __asm("jmp _Startup"); /* Jump to C startup code */ }
/* ** =================================================================== ** 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 */ }
/* ** =================================================================== ** Method : Byte1_SetBit (bean ByteIO) ** ** Description : ** This method sets (sets to one) the specified bit of the ** output value. ** [ It is the same as "PutBit(Bit,TRUE);" ] ** Parameters : ** NAME - DESCRIPTION ** Bit - Number of the bit to set (0 to 7) ** Returns : Nothing ** =================================================================== */ void Byte1_SetBit(byte Bit) { byte const Mask = Byte1_GetMsk(Bit); /* Temporary variable - set bit mask */ setReg8Bits(PORTB, Mask); /* [bit Bit]=1 */ }
/* ** =================================================================== ** Method : PE_low_level_init (component MCF51AC256A_80) ** ** Description : ** Initializes components 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) { /* SCGC1: TPM3=1,FTM2=1,FTM1=1,ADC=1,CAN=1,IIC=1,SCI2=1,SCI1=1 */ setReg8(SCGC1, 0xFFU); /* SCGC2: CRC=1,FLS=1,IRQ=1,KBI=1,ACMP=1,RTI=1,SPI2=1,SPI1=1 */ setReg8(SCGC2, 0xFFU); /* Common initialization of the CPU registers */ /* PTGPE: PTGPE4=0,PTGPE3=0,PTGPE2=0,PTGPE1=0,PTGPE0=0 */ clrReg8Bits(PTGPE, 0x1FU); /* PTDPE: PTDPE7=0,PTDPE3=0,PTDPE2=0 */ clrReg8Bits(PTDPE, 0x8CU); /* PTGDD: PTGDD4=0,PTGDD3=0,PTGDD2=0,PTGDD1=0,PTGDD0=0 */ clrReg8Bits(PTGDD, 0x1FU); /* PTDDD: PTDDD7=0,PTDDD3=0,PTDDD2=0 */ clrReg8Bits(PTDDD, 0x8CU); /* PTCDD: PTCDD5=0,PTCDD3=1 */ clrSetReg8Bits(PTCDD, 0x20U, 0x08U); /* PTCD: PTCD3=1 */ setReg8Bits(PTCD, 0x08U); /* PTHD: PTHD1=0 */ clrReg8Bits(PTHD, 0x02U); /* PTHPE: PTHPE1=0 */ clrReg8Bits(PTHPE, 0x02U); /* PTHDD: PTHDD1=1 */ setReg8Bits(PTHDD, 0x02U); /* PTASE: PTASE7=0,PTASE6=0,PTASE5=0,PTASE4=0,PTASE3=0,PTASE2=0,PTASE1=0,PTASE0=0 */ setReg8(PTASE, 0x00U); /* PTBSE: PTBSE7=0,PTBSE6=0,PTBSE5=0,PTBSE4=0,PTBSE3=0,PTBSE2=0,PTBSE1=0,PTBSE0=0 */ setReg8(PTBSE, 0x00U); /* PTCSE: PTCSE6=0,PTCSE5=0,PTCSE4=0,PTCSE3=0,PTCSE2=0,PTCSE1=0,PTCSE0=0 */ clrReg8Bits(PTCSE, 0x7FU); /* PTDSE: PTDSE7=0,PTDSE6=0,PTDSE5=0,PTDSE4=0,PTDSE3=0,PTDSE2=0,PTDSE1=0,PTDSE0=0 */ setReg8(PTDSE, 0x00U); /* PTESE: PTESE7=0,PTESE6=0,PTESE5=0,PTESE4=0,PTESE3=0,PTESE2=0,PTESE1=0,PTESE0=0 */ setReg8(PTESE, 0x00U); /* PTFSE: PTFSE7=0,PTFSE6=0,PTFSE5=0,PTFSE4=0,PTFSE3=0,PTFSE2=0,PTFSE1=0,PTFSE0=0 */ setReg8(PTFSE, 0x00U); /* PTGSE: PTGSE6=0,PTGSE5=0,PTGSE4=0,PTGSE3=0,PTGSE2=0,PTGSE1=0,PTGSE0=0 */ clrReg8Bits(PTGSE, 0x7FU); /* PTHSE: PTHSE6=0,PTHSE5=0,PTHSE4=0,PTHSE3=0,PTHSE2=0,PTHSE1=0,PTHSE0=0 */ clrReg8Bits(PTHSE, 0x7FU); /* PTJSE: PTJSE7=0,PTJSE6=0,PTJSE5=0,PTJSE4=0,PTJSE3=0,PTJSE2=0,PTJSE1=0,PTJSE0=0 */ setReg8(PTJSE, 0x00U); /* PTADS: PTADS7=1,PTADS6=1,PTADS5=1,PTADS4=1,PTADS3=1,PTADS2=1,PTADS1=1,PTADS0=1 */ setReg8(PTADS, 0xFFU); /* PTBDS: PTBDS7=1,PTBDS6=1,PTBDS5=1,PTBDS4=1,PTBDS3=1,PTBDS2=1,PTBDS1=1,PTBDS0=1 */ setReg8(PTBDS, 0xFFU); /* PTCDS: ??=0,PTCDS6=1,PTCDS5=1,PTCDS4=1,PTCDS3=1,PTCDS2=1,PTCDS1=1,PTCDS0=1 */ setReg8(PTCDS, 0x7FU); /* PTDDS: PTDDS7=1,PTDDS6=1,PTDDS5=1,PTDDS4=1,PTDDS3=1,PTDDS2=1,PTDDS1=1,PTDDS0=1 */ setReg8(PTDDS, 0xFFU); /* PTEDS: PTEDS7=1,PTEDS6=1,PTEDS5=1,PTEDS4=1,PTEDS3=1,PTEDS2=1,PTEDS1=1,PTEDS0=1 */ setReg8(PTEDS, 0xFFU); /* PTFDS: PTFDS7=1,PTFDS6=1,PTFDS5=1,PTFDS4=1,PTFDS3=1,PTFDS2=1,PTFDS1=1,PTFDS0=1 */ setReg8(PTFDS, 0xFFU); /* PTGDS: ??=0,PTGDS6=1,PTGDS5=1,PTGDS4=1,PTGDS3=1,PTGDS2=1,PTGDS1=1,PTGDS0=1 */ setReg8(PTGDS, 0x7FU); /* PTHDS: ??=0,PTHDS6=1,PTHDS5=1,PTHDS4=1,PTHDS3=1,PTHDS2=1,PTHDS1=1,PTHDS0=1 */ setReg8(PTHDS, 0x7FU); /* PTJDS: PTJDS7=1,PTJDS6=1,PTJDS5=1,PTJDS4=1,PTJDS3=1,PTJDS2=1,PTJDS1=1,PTJDS0=1 */ setReg8(PTJDS, 0xFFU); /* ### Shared modules init code ... */ KB1_Init(); /* ### Free running 8-bit counter "FC321" init code ... */ FC321_Init(); /* ### Asynchro serial "AS2" init code ... */ AS2_Init(); /* ### BitIO "Bit1" init code ... */ /* INTC_WCR: ENB=1,??=0,??=0,??=0,??=0,MASK=0 */ setReg8(INTC_WCR, 0x80U); SR_lock = 0x00; /* Set initial interrupt priority 0 */ asm { move.w SR,D0; andi.l #0xF8FF,D0; move.w D0,SR; } }