K60 学习05修改时钟

流程如下:

/* SIM->CLKDIV1: OUTDIV1=0,OUTDIV2=2,OUTDIV3=4,OUTDIV4=4*/
  SIM->CLKDIV1 = (uint32_t)0x01330000u;
 /* Update system prescalers */
  /* Switch to FBE Mode */
  /* OSC->CR: ERCLKEN=1,,EREFSTEN=0,,SC2P=0,SC4P=0,SC8P=0,SC16P=0 */
  OSC->CR = (uint8_t)0x80u;
  /*SIM->SOPT2: MCGCLKSEL=0*/
  SIM->SOPT2 &= (uint8_t)~(uint8_t)0x01u;
  /* MCG->C2: RANGE0=2,HGO=0,EREFS=0,LP=0,IRCS=0 */
  MCG->C2 = (uint8_t)0x20u;
  /* MCG->C1: CLKS=2,FRDIV=5,IREFS=0,IRCLKEN=1,IREFSTEN=0 */
  MCG->C1 = (uint8_t)0xAAu;
  /* MCG->C4: DMX32=0,DRST_DRS=0 */
  MCG->C4 &= (uint8_t)~(uint8_t)0xE0u;
  /* MCG->C5: PLLCLKEN=0,PLLSTEN=0,PRDIV0=16 */
  MCG->C5 = (uint8_t)0x0Fu;
  /* MCG->C6: LOLIE=0,PLLS=0,CME=0,VDIV0=0 */
  MCG->C6 = (uint8_t)0x00u;
  while((MCG->S & MCG_S_OSCINIT0_MASK) == 0u) {
 /* Check that the oscillator is running */
  }
  while((MCG->S & MCG_S_IREFST_MASK) != 0u) {
 /* Check that the source of the FLL reference clock is the external reference clock. */
  }
  while((MCG->S & 0x0Cu) != 0x08u) {    
/* Wait until external reference clock is selected as MCG output */
  }
  /* Switch to PBE Mode */
  /* MCG_C5: PLLCLKEN=0,PLLSTEN=0,PRDIV0=1 */
  MCG->C1 = (uint8_t)0xAAu;
  /* MCG->C6: LOLIE=0,PLLS=1,CME=0,VDIV0=32 */
  MCG->C6 = (uint8_t)0x48u;
  while((MCG->S & MCG_S_PLLST_MASK) == 0u) { 
/* Wait until the source of the PLLS clock has switched to the PLL */
  }
  while((MCG->S & MCG_S_LOCK0_MASK) == 0u) {
 /* Wait until locked */
  }
  /* Switch to PEE Mode */
  /* MCG->C1: CLKS=0,FRDIV=3,IREFS=0,IRCLKEN=1,IREFSTEN=0 */
  MCG->C1 = (uint8_t)0x2Au;
  while((MCG->S & 0x0Cu) != 0x0Cu) {    
/* Wait until output of the PLL is selected */
  }
  while((MCG->S & MCG_S_LOCK0_MASK) == 0u) {
 /* Wait until locked */
  }

里面还是有许多不懂的地方,这里只是 抄下来,知道哪个寄存器在什么地方,要想真正搞清楚里面究竟是怎么回事,还差得远!没有下载器,也无法验证。只是慢慢来,不急!

你可能感兴趣的:(K60 学习05修改时钟)