新聞中心

MSP430F149 定時(shí)器

作者: 時(shí)間:2016-12-02 來(lái)源:網(wǎng)絡(luò) 收藏


對(duì)定時(shí)時(shí)間的說(shuō)明:

當(dāng)TASSEL_1時(shí),選ACLK = 32.768KHZ,此時(shí)根據(jù)選取不同的TACCR0來(lái)實(shí)現(xiàn)不同的延時(shí),

當(dāng)TASSEL_2時(shí),選SMCLK = DCO 時(shí),~~~~~~~~~~~~~~~~~~~~~

選SMCLK = XT2時(shí),~~~~~~~~~~~~~~~~

關(guān)鍵語(yǔ)句:

TACTL = TASSEL_X + MC_1;

TACCR0 = ~~~~~~~;

TACCTL0 = CCIE;

(3)、利用定時(shí)器A的比較模式,及輸出模式4和連續(xù)計(jì)數(shù)模式可實(shí)現(xiàn)同時(shí)實(shí)現(xiàn)4個(gè)獨(dú)立的定時(shí)間隔,或4種不同的頻率輸出。

在實(shí)驗(yàn)的過(guò)程中,同時(shí)驅(qū)動(dòng)數(shù)碼管的4個(gè)段。

在比較模式下主要區(qū)分TACCR0 TACCR1 TACCR2 及TAIFG,的中斷向量及入口地址,及輸出模式(共8種)



其程序如下:

#include

typedef unsigned char uchar;
typedef unsigned int uint;
uchar flag=0;
uchar table[] = {0x18,0x7e,0x51,0x52,0x36,0x92,0x90,0x5E,0x10,0x12}; //對(duì)應(yīng)0---9的共陽(yáng)極碼
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
//BCSCTL1 |= XT2OFF;
//BCSCTL2 |= SELS + DIVS_3;
TACCTL0 = OUTMOD_4 +CCIE ; //Enable interrupt
TACCTL1 = OUTMOD_4 +CCIE ;
TACCTL2 = OUTMOD_4 +CCIE ;

TACCR1 = 0X8000;
TACCR2 = 0X2000;
TACCR0 = 0XF000;
P3DIR |= BIT6 + BIT7; // P3.4 output
P3OUT |= BIT6 + BIT7;
P4DIR = 0XFF;
P4OUT = 0XFF;
TACTL = TASSEL_2 + MC_2 + TAIE; // SMCLK, contmode, interrupt
_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: P4OUT ^= BIT5; TACCR1 += 0X8000;break; // CCR1 not used
case 4: P4OUT ^= BIT3;TACCR2 += 0X2000;break; // CCR2 not used
case 10: flag++;
if(flag==12){P4OUT ^= BIT2; flag = 0; } // overflow
break;//flag++;
}
}

/**/
// Timer A0 interrupt service routine
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer0_A (void)
{
P4OUT ^= BIT4; // Toggle P3.4
TACCR0 += 0XF000;
}

上一頁(yè) 1 2 下一頁(yè)

關(guān)鍵詞: MSP430F149定時(shí)

評(píng)論


技術(shù)專區(qū)

關(guān)閉