程序如下
void UCS_Init()
{
P5SEL |= BIT4+BIT5; // Port select XT1
UCSCTL6 &= ~XT1OFF; // XT1 On
UCSCTL6 |= XCAP_3; // Internal load cap
P5SEL |= BIT2+BIT3;
UCSCTL6 &= ~XT2OFF; //打开XT2
UCSCTL0 = 0x0000;
UCSCTL3 = SELREF_0 + FLLREFDIV_0; //n=1,FLLREFCLK时钟源为XT1CLK
//DCOCLK=D*(N+1)*(FLLREFCLK/n);
//DCOCLKDIV=(N+1)*(FLLREFCLK/n);
UCSCTL4 = UCSCTL4 & (~(SELA_7|SELS_7|SELM_7)) | SELA_4 | SELS_3 | SELM_3;
/*********************寄存器配置部分******************************/
_bis_SR_register(SCG0);
UCSCTL1 = DCORSEL_5; //DCO频率范围在10~20MHZ
UCSCTL2 = FLLD_4 | 1; //D=16,N=1
//UCSCTL4 = SELA_4 + SELS_3 +SELM_3; //ACLK的时钟源为DCOCLKDIV,MCLK\SMCLK的时钟源为DCOCLK
UCSCTL5 = DIVA_1 + DIVS_1; //ACLK由DCOCLKDIV的2分频得到,SMCLK由DCOCLK的2分频得到
//最终MCLK:10MHZ,SMCLK:5MHZ,ACLK:32KHZ
_bic_SR_register(SCG0); //Enable the FLL control loop
__delay_cycles(8192);
while (SFRIFG1 & OFIFG)
{
UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + DCOFFG);
SFRIFG1 &= ~OFIFG;
}
运行的时候,一直在while里面循环,查寄存器发现DCOFFG始终是置1状态不能清除,我想知道是对DCO的哪里配置存在问题 |