- #include<msp430g2553.h>
- /*
- * the OSC is not work, run this function
- */
- void FaultRoutine()
- {
- P1OUT = 0x01; // P1.0 on (red LED)
- while(1); // TRAP
- }
- /*
- * initialize Clock Module
- * use DCO clock as MCLK and SMCLK
- * the frequency of DCO is 1MHZ; MCLK and SMCLK is 1MHZ
- */
- void init_CLOCK()
- {
- if(CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
- {
- FaultRoutine(); // If calibration data is erased then run FaultRoutine
- }
- BCSCTL1=CALBC1_1MHZ; //Set range
- DCOCTL=CALDCO_1MHZ; //Set DCO step + modulation
- BCSCTL3 |= LFXT1S_0; // LFXT1 =Normal operation
- IFG1 &= ~OFIFG; // Clear OSCFault flag
- BCSCTL2|=SELM_0+DIVM_0+DIVS_0; //MCLK and SMCLK(use DCO) Divider:1 [internal resistor]
- }
- /*
- * initialize digital IO port
- */
- void init_IO()
- {
- P1DIR&=~BIT3; //set P1DIR is input(Reset with PUC)[P1.3 is input]
- P1DIR|=BIT6+BIT0; //set P1.0 and P1.6 are output
- P1OUT=0;
- }
- /*
- * initialize Timer A
- * SMCLK is 1MHZ
- */
- void init_TA()
- {
- TACTL|=TASSEL_2+ID_0+MC_1+TAIE; //use SMCLK[1M]/up mode/interrupt enable/No interrupt pending
- TAR=0;
- TACCR0=500; //0.05s
- TACCTL0|=CAP+CCIE; //use Compare mode
- TACCTL0&=~CCIFG;
- }
- /*
- * main function
- */
- void main()
- {
- WDTCTL=WDTHOLD+WDTPW; //watch dog timer is stopped
- init_CLOCK(); //initialize basic clock
- init_IO(); //initialize digtal IO port
- init_TA();
- _EINT();
- while(1)
- {
- // P1OUT|=BIT6;
- // _delay_cycles(100000);
- // P1OUT&=~BIT6;
- // _delay_cycles(100000);
- }
- }
- #pragma vector=TIMER0_A0_VECTOR
- __interrupt void Timer_A (void)
- {
- //P1OUT=0; //close green led
- P1OUT|=BIT6; //open red led
- _delay_cycles(100000);
- //TACCTL0&=~CCIFG; //clear interrupt flag
- }
复制代码调试程序时中断的flag位显示为1了,但就是进入不了中断程序啊……
硬件为msp430g2553launchpad
找到原因了,定时器初试化有问题,把TACTL的中断使能关掉,只流TACCTL开着中断使能就可以,但是不知道为什么……
一周热门 更多>