[cpp] view plaincopy
<pre class="cpp" name="code">/******************************************************************************************
| FUNCTION NAME : MCU_SetBusClock
| CALLED BY : xxxx
| PRECONDITIONS : xxxx
| INPUT PARAMETERS : xxxx
| OUTPUT PARAMETERS: xxxx
| RETURN VALUE : xxxx
| DESCRIPTION : set MCGOUT and bus frequency,BDIV = 1, VDIV = 16, RDIV = 4, OSC = 4.332MHz
| MCGOUT = [(OSC / RDIV) * VDIV] / BDIV;
| MCGOUT = [(4.332MHz / 4) * 16] / 1 = 17.328MHz;
| Bus frequency = MCGOUT / 2 = 8.664MHz
| NOTE : xxxx
|*******************************************************************************************/
void MCU_SetBusClock(void) /* XOSC 4.332MHZ,BUS clock 8.664MHZ */
{
//SOPT1 = 0; /* STOP WATCH DOG */
SOPT1_COPT =3; /* enable watchdog 1s timeout*/
/*After RESET start in FEI Mode
FEI > FBE ***************************************
Set MCGC2:
BDIV[6:7] | RANGE | HGO | LP | EFERS | ERCLKEN | EREFSTEN | */
MCGC2 = 0X36;
while(!MCGSC_OSCINIT); /* Wait till OSCINIT in MCGSC is one */
_asm SEI; /* MUST BLOCK INTERRUPTS */
MCGC1 = 0XB8; /* Set MCGC1:| CLKS[6:7] | RDIV[3:5] | IREFS | IRCLKEN | IREFSTEN | */
while(MCGSC_IREFST); /* Wait till IRFEST in MCGSC is zero */
while((MCGSC_CLKST)^(0x02));/* Wait till external clock source is selected */
/* FBE > BLPE **************************************** */
MCGC2_LP = 1;
MCGC1 = 0X90; /* Set the range of frequency divider 4.332m/4 (1mhz~2mhz) */
MCGC3 = 0X44;
while(!MCGSC_PLLST); /* Wait till Source of PLLS clock is set to PLL clock */
/* BLPE > PBE **************************************** */
/* Clear LP to switch to PBE Mode*/
MCGC2_LP = 0;
while(!MCGSC_LOCK); /* Wait for PLL to lock */
/* PBE > PEE ***************************************** */
/* Select clock source */
MCGC1 = 0X10;
while((MCGSC_CLKST)^(0x03));/* Check if output of the PLL is selected as current clock mode */
_asm CLI; /* CAN ENEBLE INTERRUPTS */
}</pre><br>
<pre></pre>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<pre> </pre>
<pre> </pre>
<pre></pre>
<pre></pre>
<pre></pre>
|