我用LaunchPad做仿真器,连接到目标板,写了一个TIMERA中断,系统老是复位,查看寄存器IFG1,里面OFIFG和PORIFG都置1。代码如下:
#include "io430.h"
void SysInit(void)
{
P1DIR = 0xea; // 1110 1010
P1OUT = 0x3a; // p14 上拉
P1REN = 0x10;
P1SEL2 = 0;
P1SEL2 |= 0x05;
P1SEL = 0;
P1SEL |= 0x05;
P2DIR = 0xff;
P2OUT = 0x00;
P2SEL = 0x00;
TACCTL0 = CCIE;
TACCR0 = 0x1234;
TACTL = TASSEL_2 + MC_2 + TAIE; // 时钟源 SMCLK + 连续模式 +中断使能
}
int main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
BCSCTL1 = CALBC1_1MHZ; // Set DCO to 1MHz
DCOCTL = CALDCO_1MHZ;
BCSCTL3 |= LFXT1S_2; // LFXT1 = VLO
IFG1 &= ~OFIFG;
SysInit();
__bis_SR_register(GIE);
while(1);
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
{
P1OUT ^= 0x80;
TACCR0 += 0x1234;
} |