定义全局变量FrequencyCounter用于Timer0_A3中断程序中计数,很简单的一个,但是出现了问题! unsigned int FrequencyCounter; main(){ ... ...} #pragma vector=TIMER0_A1_VECTOR__interrupt void Timer0_A1(void){ switch(TAIV)
{
default : break;
case 2: break;
case 4: break;
case 10:
{
FrequencyCounter ++;
break;
}
}} 奇怪的是,每次执行完FrequencyCounter ++;FrequencyCounter的值都是1,调试后发现每次进入中断的时候FrequencyCounter被清零了,这是为什么呢?FrequencyCounter我定义的是全局变量啊。
此帖出自
小平头技术问答
unsigned int FrequencyCounter;
void main(void)
{
Task_InitSystem();
for(;;)
{
_NOP();
}
}
void Task_InitSystem(void)
{
unsigned int i;
_BIS_SR(OSCOFF);
WDTCTL = WDTPW + WDTHOLD;
DCOCTL = DCO2 + DCO1 + DCO0;
BCSCTL1 = RSEL3 + RSEL1 + XTS + XT2OFF;
BCSCTL3 &=~ LFXT1OF;
IFG1 &=~ OFIFG;
while((OFIFG & IFG1) != 0) /* Wait for OFIFG = 0 */
{
IFG1 &=~ OFIFG;
for(i = 0xff;i > 0u;i--);
}
TACTL = TASSEL_2 + MC_1 + TACLR + TAIE;
TACCR0 = 4000;
TACCR1 = 2500;
TACCR2 = 2500;
TACCTL1 |= OUTMOD_7;
TACCTL2 |= OUTMOD_7;
P1SEL |= 0x0c;
P1DIR |= 0x0c;
TA1CTL = TASSEL_2 + MC_1 + TACLR + TAIE;
TA1CCR0 = 4000;
TA1CCR1 = 2500;
TA1CCTL1 |= OUTMOD_7;
P3SEL |= 0x80;
P3DIR |= 0x80;
_BIS_SR(GIE);
}
#pragma vector=TIMER0_A1_VECTOR
__interrupt void Timer0_A1(void)
{
switch(TAIV)
{
default : break;
case 2: break;
case 4: break;
case 10:
{
FrequencyCounter ++;
break;
}
}
}
一周热门 更多>