rockt 发表于 2012-10-8 20:46:58

关于MSP430单片机的时钟设置

MSP430单片机的时钟设置感觉很麻烦,我碰到一个问题,使用DCO时钟6M,不知道怎么弄大家看看:

#include <msp430x12x2.h>

#define DELTA1024                         // target DCO = DELTA*(4096) = 6M
//#define DELTA256                           // target DCO = DELTA*(4096) = 1M

void Set_DCO (void);

void main(void)
{
WDTCTL = WDTPW + WDTHOLD;               // Stop WDT
Set_DCO();                              // Set DCO

while (1);
}

//------------------------------------------------------------------------------
void Set_DCO (void)                         // Set DCO to selected frequency
//------------------------------------------------------------------------------
{
unsigned int Compare, Oldcapture = 0;

BCSCTL1 |= DIVA_3;                        // ACLK= LFXT1CLK/8
CCTL2 = CM_1 + CCIS_1 + CAP;            // CAP, ACLK
TACTL = TASSEL_2 + MC_2 + TACLR;          // SMCLK, cont-mode, clear

while (1)
{
    while (!(CCIFG & CCTL2));               // Wait until capture occured
    CCTL2 &= ~CCIFG;                        // Capture occured, clear flag
    Compare = CCR2;                         // Get current captured SMCLK
    Compare = Compare - Oldcapture;         // SMCLK difference
    Oldcapture = CCR2;                      // Save current captured SMCLK

    if (DELTA == Compare) break;            // If equal, leave "while(1)"
    else if (DELTA < Compare)               // DCO is too fast, slow it down
    {
      DCOCTL--;
      if (DCOCTL == 0xFF)
      {
      if (!(BCSCTL1 == (XT2OFF + DIVA_3)))
      BCSCTL1--;                        // Did DCO roll under?, Sel lower RSEL
      }
    }
    else
    {
      DCOCTL++;
      if (DCOCTL == 0x00)
      {
          if (!(BCSCTL1 == (XT2OFF + DIVA_3 + 0x07)))
          BCSCTL1++;                        // Did DCO roll over? Sel higher RSEL
      }
    }
}
CCTL2 = 0;                              // Stop CCR2
TACTL = 0;                              // Stop Timer_A
}


就是无法初始化成功,求助。。。。。。。给个例子参考也好
页: [1]
查看完整版本: 关于MSP430单片机的时钟设置