郭天祥MSP430教程源码-SoftwreFLL.zip
时间:10-27 14:41
查看:1494次
下载:162次
简介:
有关郭天祥MSP430教程源码-SoftwreFLL实验程序设计。
#include <msp430x14x.h>
#include "BoardConfig.h"
//#define DELTA 977 // target DCO= DELTA*(4096) = 4Mhz
//#define DELTA 900 // target DCO= DELTA*(4096) = 3686400
#define DELTA 250 // target DCO= DELTA*(4096) = 1048576
//#define DELTA 70 // target DCO= DELTA*(4096) = 286720
unsigned int Compare, Oldcapture;
void main(void)
{
BoardConfig(0xb8);
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 |= DIVA_3; // ACLK= LFXT1CLK/8
CCTL2 = CM_1 + CCIS_1 + CAP + CCIE; // CAP, ACLK, interrupt
TACTL = TASSEL_2 + MC_2 + TACLR; // SMCLK, cont-mode, clear
P5DIR |= 0x60; // P5.5,6 output
P5SEL |= 0x60; // P5.5,6 SMCLK, ACLK output
_BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt
}
// Timer_A3 Interrupt Vector (TAIV) handler
#pragma vector=TIMERA1_VECTOR
__interrupt void Timer_A(void)
{
switch( TAIV )
{
case 2: break; // CCR1 not used
case 4:
{
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)"
if (DELTA < Compare)
{
DCOCTL--;
if (DCOCTL == 0xFF) // DCO is too fast, slow it down
{
if (!(BCSCTL1 == (XT2OFF + DIVA_3)))
BCSCTL1--; // Did DCO roll under?, Sel lower RSEL
}
}
else
{
DCOCTL++; // DCO is too slow, speed it down
if (DCOCTL == 0x00)
{
if (!(BCSCTL1 == (XT2OFF + DIVA_3 + 0x07)))
BCSCTL1++; // Did DCO roll over? Sel higher RSEL
}
}
}
case 10: break; // not used
}
}