MSP LaunchPad V1.5 定时器A操作
[复制链接]
#include
//led
#define LED1 BIT0
#define LED2 BIT6
#define LED_OUT P1OUT
#define LED_DIR P1DIR
void sys_init(void);
void led_init(void);
void timer_init(void);
int main(void)
{
sys_init();
while(1);
}
void sys_init(void){
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
led_init();
timer_init();
}
void led_init(void){
LED_DIR |= LED1|LED2;
LED_OUT |= LED1|LED2;
}
void timer_init(void){
//TACCTL0 = CCIE;
TACCTL0 = CCIE;
TACTL = TASSEL_2 | MC_1 ;//选择SMCLK,增计数方式,
TACCR0 = 50000;//设置最大计数值为50000,可修改
//TAR = 0;//将计数值清零,实际无必要
_EINT();//开总中断
}
#pragma vector = TIMER0_A0_VECTOR
//注意此处,中断向量 还有一个TIMER0_A1_VECTOR,最开始的时候这两个地方混了,导致始终无法观察到灯的闪烁
__interrupt void timer0_a(void){
TACCR0 = 50000;
LED_OUT ^= LED1|LED2;
}
|