|
程序运行后,P2.1开中断,并进入低功耗,中断后退出低功耗,初始化定时器,每隔125 US进入定时器中断服务程序,我要判断进入定时器中断的次数(page_length),满足条件后,退出定时器中断,我在主程序中判断 if(k>page_length)break; ,但怎么关不了中断,而且执行不到while后面的语句.
#include <MSP430x14x.h>
#define CLE BIT3
#define ALE BIT3
#define WE BIT6
#define CE BIT4
#define RE BIT5
#define page_length 2142 //85E=2142,总共85F页,即0-85E
#define RD BIT0
#define RB BIT7
void InitSys(); //系统初始化
unsigned int j,k=0,j1,j2=0,j3=0,j4=0;
unsigned char ISR_Symbol;
unsigned int i;
int main (void)
{
WDTCTL = WDTPW + WDTHOLD;
P2DIR &= ~BIT1;
P2SEL &= ~BIT1; //P2.1口允许中断;
P2IES |= BIT1;
P2IE |= BIT1;
P2IFG = 0;
P4DIR |= 0x00;
P5DIR |= 0x00;
P6DIR |= 0xFF;
ISR_Symbol = 0;
_EINT();
while(1)
{
LPM4;
if(ISR_Symbol)break;
}
ISR_Symbol = 0;
InitSys();
_NOP();
_NOP();
while(1)
{
if(k>page_length)break; //判断次数
}
TACTL |= 0x00;
while(1)
{
_NOP();
}
}
void InitSys() //系统初始化
{
unsigned int iq0;
BCSCTL1 &= ~XT2OFF;
do
{
IFG1 &= ~OFIFG;
for(iq0=0xFF; iq0>0; iq0--);
}
while ((IFG1 & OFIFG)!= 0);
BCSCTL2 = SELM_2 + SELS + DIVS_1; //启动XT2晶振;
TACTL = TASSEL1 + TACLR + MC0;
CCTL0 = CCIE; //初始化TA定时器
CCR0 = 500;
_EINT();
}
#pragma vector = PORT2_VECTOR
__interrupt void Port2()
{
LPM4_EXIT;
_NOP();
_NOP();
P2DIR &= ~BIT1;
if((P2IN&BIT1)==0)return;
for(j=0;j<100;j++);
if((P2IN&BIT1)==0)return;
P3DIR |= BIT1 + BIT4;
P3OUT |= BIT4; //为1
P3OUT &= ~BIT1; //为0 //P2口中断,给AD上电
_NOP();
_NOP();
_NOP();
P1DIR |= BIT0 + BIT7 + BIT6 + BIT5;
P1OUT |= BIT7 + BIT6; //A1、A2为1
P1OUT &= ~BIT5; //A0为0
P2IFG &= ~BIT1;
_DINT();
P2IFG = 0;
P2IE = 0;
ISR_Symbol = 0xff;
return;
}
#pragma vector=TIMERA0_VECTOR
__interrupt void TimerA0()
{
P1OUT ^= BIT0;
P1OUT ^= BIT0; //产生HOLD
for(j1=0xFF; j1>0; j1--); //延时
k++; //HOLD个数i加1
return;
}
另外小弟还问一个问题,我用MSP430F149的P6口与FLASH存储器I/O口相联,但一执行P6DIR|=0XFF,定义输出时,仿真器就出错,不知为什么.
|
|