为什么进入不了中断程序????

2019-07-31 14:21发布

  1. #include<msp430g2553.h>

  2. /*
  3. *  the OSC is not work, run this function
  4. */
  5. void FaultRoutine()
  6. {
  7.    P1OUT = 0x01;                        // P1.0 on (red LED)
  8.    while(1);                                         // TRAP
  9. }
  10. /*
  11. * initialize Clock Module
  12. * use DCO clock as MCLK and SMCLK
  13. * the frequency of DCO is 1MHZ; MCLK and SMCLK is 1MHZ
  14. */
  15. void init_CLOCK()
  16. {
  17.         if(CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
  18.         {
  19.                 FaultRoutine();                            // If calibration data is erased then run FaultRoutine
  20.         }
  21.         BCSCTL1=CALBC1_1MHZ;                                 //Set range
  22.         DCOCTL=CALDCO_1MHZ;                                        //Set DCO step + modulation
  23.         BCSCTL3 |= LFXT1S_0;                // LFXT1 =Normal operation
  24.         IFG1 &= ~OFIFG;                     // Clear OSCFault flag
  25.         BCSCTL2|=SELM_0+DIVM_0+DIVS_0;                //MCLK and SMCLK(use DCO) Divider:1 [internal resistor]
  26. }
  27. /*
  28. * initialize digital IO port
  29. */
  30. void init_IO()
  31. {
  32.         P1DIR&=~BIT3;                                                //set P1DIR is input(Reset with PUC)[P1.3 is input]
  33.         P1DIR|=BIT6+BIT0;                                        //set P1.0 and P1.6 are output
  34.         P1OUT=0;
  35. }

  36. /*
  37. * initialize Timer A
  38. * SMCLK is 1MHZ
  39. */
  40. void init_TA()
  41. {
  42.         TACTL|=TASSEL_2+ID_0+MC_1+TAIE;                //use SMCLK[1M]/up mode/interrupt enable/No interrupt pending
  43.         TAR=0;
  44.         TACCR0=500;                                                //0.05s
  45.         TACCTL0|=CAP+CCIE;                                                //use Compare mode
  46.         TACCTL0&=~CCIFG;
  47. }
  48. /*
  49. * main function
  50. */
  51. void main()
  52. {
  53.         WDTCTL=WDTHOLD+WDTPW;                        //watch dog timer is stopped
  54.         init_CLOCK();                                        //initialize basic clock
  55.         init_IO();                                                //initialize digtal IO port
  56.         init_TA();
  57.         _EINT();
  58.         while(1)
  59.         {
  60. //                P1OUT|=BIT6;
  61. //                _delay_cycles(100000);
  62. //                P1OUT&=~BIT6;
  63. //                _delay_cycles(100000);
  64.         }
  65. }

  66. #pragma vector=TIMER0_A0_VECTOR
  67. __interrupt void Timer_A (void)
  68. {
  69.         //P1OUT=0;                                                //close green led
  70.         P1OUT|=BIT6;                                        //open red led
  71.         _delay_cycles(100000);
  72.         //TACCTL0&=~CCIFG;                                        //clear interrupt flag
  73. }
复制代码调试程序时中断的flag位显示为1了,但就是进入不了中断程序啊……
硬件为msp430g2553launchpad
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
2条回答
涛声依旧00
2019-07-31 23:03
dirtwillfly 发表于 2015-1-6 23:12
注意检查定时器的初始化配置

找到原因了,定时器初试化有问题,把TACTL的中断使能关掉,只流TACCTL开着中断使能就可以,但是不知道为什么……

一周热门 更多>