各位高手,初学430单片机,想做充电器,在书上看到程序,时钟模块程序咋看不得其解,望赐教。
void init_Clk (void)
{
unsigned int Compare, Oldcapture = 0;
// ACLK= LFXT1CLK/8
BCSCTL1 |= DIVA_3;
CCTL2 = CM_1 + CCIS_1 + CAP;
// SMCLK
TACTL = TASSEL_2 + MC_2 + TACLR;//子系统时钟,连续计数模式,定时器A清零
while (1)
{
//等待捕获发生
while (!(CCIFG & CCTL2)) ;
//清除标志
CCTL2 &= ~CCIFG;
//得到当前的SMCLK
Compare = CCR2;
//SMCLK的差
Compare = Compare - Oldcapture;
//保存
Oldcapture = CCR2;
if (DELTA == Compare) break;
else if (DELTA < Compare)
{
DCOCTL--;
if (DCOCTL == 0xFF)
{
if (!(BCSCTL1 == (XT2OFF + DIVA_3)))
{
BCSCTL1--;
}
}
}
else
{
DCOCTL++;
if (DCOCTL == 0x00)
{
if (!(BCSCTL1 == (XT2OFF + DIVA_3 + 0x07)))
{
BCSCTL1++;
}
}
}
}
//停止CCR2
CCTL2 = 0;
//停止定时器A
TACTL = 0;
} |