9S12G48 时钟初始化

9S12G48 时钟初始化


生成24M bus clock
外部8m晶振初始化

void CPMU_Init(void)
{
    /* ocs= 8  fbus =24*/
    /* 1: External oscillator is enabled */

    CPMUOSC_OSCE = 0x01u;
    /* 10: 6MHz<=fREF<=12MHz, 8M */
    CPMUREFDIV_REFFRQ = 0x10u;
    CPMUREFDIV_REFDIV = 0x00u;
    /* ICS Trim Register */
    CPMUIRCTRIM_IRCTRIM += 2u;
    /* 010111: fVCO=2*fREF*(SYNDIV+1) */
    CPMUSYNR_SYNDIV = 0x02u;
    /* 00: 32MHz<=fVCO<=48MHz */
    CPMUSYNR_VCOFRQ = 0x00u;
    /* 01: Enable PLL Frequency Modulation fVCO Variation = ±1% */
    CPMUPLL_FM = 0x01u;
    /* 00000: fPLL=fVCO/(POSTDIV+1) */
    CPMUPOSTDIV_POSTDIV = 0x00u; 
    /* 1: System clocks are derived from PLLCLK,fbus=fPLL/2 */
    CPMUCLKS_PLLSEL = 0x01u;
    while(!CPMUFLG_LOCK){}/* Wait for the PLL stabilization */
}

内部1m rc振荡器 初始化

void MCUex_init(void)
{

  /* ### MC9S12G64_64 "Cpu" init code ... */
  /*  PE initialization code after reset */
  /*  System clock initialization */
  /* CPMUPROT: PROT=0 */
  CPMUPROT = 0x26U;                    /* Disable protection of clock configuration registers */
  /* CPMUCLKS: PSTP=0 */
  CPMUCLKS &= (unsigned char)~(unsigned char)0x40U;                     
  /* CPMUCLKS: PLLSEL=1 */
  CPMUCLKS |= (unsigned char)0x80U;    /* Enable the PLL to allow write to divider registers */
  /* CPMUSYNR: VCOFRQ1=0,VCOFRQ0=1,SYNDIV5=0,SYNDIV4=1,SYNDIV3=1,SYNDIV2=1,SYNDIV1=1,SYNDIV0=1 */
  CPMUSYNR = 0x5FU;                    /* Set the multiplier register */
  /* CPMUPOSTDIV: POSTDIV4=0,POSTDIV3=0,POSTDIV2=0,POSTDIV1=1,POSTDIV0=1 */
  CPMUPOSTDIV = 0x03U;                 /* Set the post divider register */
  /* CPMUPLL: FM1=0,FM0=0 */
  CPMUPLL = 0x00U;                     /* Set the PLL frequency modulation */
  while(CPMUFLG_LOCK == 0U) {          /* Wait until the PLL is within the desired tolerance of the target frequency */
  }
  /* CPMUPROT: PROT=0 */
  CPMUPROT = 0x00U;                    /* Enable protection of clock configuration registers */
  /* CPMUCOP: RSBCK=0,WRTMASK=0 */
  CPMUCOP &= (unsigned char)~(unsigned char)0x60U;                     
  /* Common initialization of the CPU registers */
  /* CPMUINT: LOCKIE=0,OSCIE=0 */
  CPMUINT &= (unsigned char)~(unsigned char)0x12U;                     
  /* CPMULVCTL: LVIE=0 */
  CPMULVCTL &= (unsigned char)~(unsigned char)0x02U;                     
  /* IRQCR: IRQEN=0 */
  IRQCR &= (unsigned char)~(unsigned char)0x40U;                     
  /* ### */
  /* Initial interrupt priority */
  /*lint -save  -e950 Disable MISRA rule (1.1) checking. */
  //asm CLI;                             /* Enable interrupts */
  /*lint -restore Enable MISRA rule (1.1) checking. */
} /*MCU_init*/
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值