|
#include "msp430G2553.h"
//************主函数***************************
void main()
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 = CALBC1_1MHZ; //时钟为1M,课设8M、12M和16M
DCOCTL = CALDCO_1MHZ; //同上(并同时设置)
BCSCTL2 |=SELM_1+DIVM_3;//SELM_1时钟源选择,0、1为DCOCLK,
//2为XT2CLK/LFXTCLK,3为LFXTCLK
//DIVM_1,为所选的时钟分频,0不分频,1为2分频,2为4分频,3为8分频
////////////
P1DIR|=0x41; //P1.6和P1.0为输出,控制LED
P1OUT |=0x01;
P1OUT &=~0x40;
//////////////////
TACTL |= TASSEL_2+ID_3+MC_1;
//TASSEL_x计数器时钟源选择,x=0,外时钟TACLK,1选ACLK,2选SMCLK,3选外部时钟
// ID_x是分频选择,x=0不分频,1是2分频,2是4分频,3是8分频后(125K)
// MC_x是计数模式,x=0,停止,1是up到CCR0的值,2是连续到满0xffff,
//3增减计数,先增到CCR0的值,再减到0
TACCR0 =25000; //计到2500,约20ms
TACCTL0 |= CCIE; // CCR0 interrupt enabled
_BIS_SR(GIE); //开总中断
while(1);
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A(void)
{
//TACCTL0&=~ CCIE; //关中断
static int cc=0;
cc+=1;
if(cc==20) //1s=1000ms=20*50 定时
{
P1OUT^=0x41; //P1.6 LED取反
cc=0;
}
}
|
|