标签:
代码一:
/************************** 功能:LED每隔1秒闪烁一次 ****************************/ #include <msp430x14x.h> void main() { P6DIR = 0XFF; P6OUT = 0X00; TACCR0 = 4095; TACCTL0 = CCIE; TACTL = TASSEL_1 + ID_3 + MC_1; _EINT(); LPM3; } #pragma vector=TIMERA0_VECTOR __interrupt void Timer_A(void) { P6OUT ^= 0XFF; }
代码二:
1 /********************************* 2 程序流程: 3 关看门狗-->定时中断10ms-->开总中断-->中断是否置位 4 *********************************/ 5 #include <msp430x14x.h> 6 7 int flag=0,time=0; 8 void int_clk(); //初始化时钟 9 void int_timer(); //设置定时器A 10 void main() 11 { 12 WDTCTL = WDTPW +WDTHOLD; 13 P6DIR = 0XFF; 14 P6OUT = 0XFF; 15 int_clk(); 16 int_timer(); 17 _EINT(); 18 19 for(;;) 20 { 21 while(flag) 22 { 23 flag=0; 24 time++; 25 if(time==100) 26 { 27 P6OUT ^= 0XfF; 28 time = 0; 29 } 30 } 31 } 32 } 33 34 void int_clk() 35 { 36 BCSCTL1 &= ~XT2OFF; 37 BCSCTL2 |= SELM_1 + SELS; 38 do 39 { 40 IFG1 &= ~OFIFG; 41 for(int i=100;i>0;i--) 42 _NOP(); 43 }while((IFG1 & OFIFG)!=0); 44 IFG1 &= ~OFIFG; 45 } 46 47 void int_timer() 48 { 49 TACTL |= TACLR + TASSEL_2 + ID_3 + MC_1; 50 TACTL |= TAIE; 51 TACCR0 = 9999; //10ms 52 } 53 #pragma vector = TIMERA0_VECTOR 54 __interrupt void Timer_A(void) 55 { 56 P6OUT = 0X00; 57 switch(TAIV) 58 { 59 case 2:break; 60 case 4:break; 61 case 10:flag =1;break; 62 } 63 }
标签:
原文地址:http://www.cnblogs.com/boyiliushui/p/4630752.html