|
发表于 2011-3-11 16:54:33
|
显示全部楼层
看了技术手册,UCAxCLK是需要外部输入的,UCA0CLK是第1脚,UCA0CLK是第14脚.
DCO可以设置的(1M-20M),而且设置比较准的,网站上有例程可以看看.
这个程序可以参考一下
/*
设置DCO函数
in:无
out:无
*/
void Set_DCO (void) // Set DCO to selected frequency
{
#define DELTA 977 // target DCO= DELTA*(4096) = 4Mhz
//#define DELTA 900 // target DCO = DELTA*(4096) = 3686400
//#define DELTA 256 // target DCO = DELTA*(4096) = 1048576
//#define DELTA 70 // target DCO = DELTA*(4096) = 286720
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
} |
|