在ADS1.2下编译的程序,硬件是LPC2101,开始只是想测试一下Timer0,后来在主程序里加了一条while语句,程序运行的while语句就停下了,无法继续运行下去,希望各位大侠给予指点,万分感谢,程序如下:
#define LED_RUN (1<<6)
#define LED_T (1<<16)
#define LED_R (1<<17)
uint16 OverTimeCounter;
uint8 OverTimeFlag;
/****************************************************/
void __irq Timer0_IRQ(void) //25ms
{
if(OverTimeCounter > 0)
{
OverTimeCounter--;
if(OverTimeCounter == 0)
{
OverTimeFlag = 1;
IO0CLR = LED_RUN; //turn on
}
}
T0IR = 0x01;
VICVectAddr = 0x00;
}
/******************************************************/
void Timer0Init(uint16 rate)
{
T0TCR = 0x02;
T0PR = 0;
T0PC = 0;
T0MCR = 0x03; //match interrupt and TC reset
T0MR0 = Fpclk / rate;
T0TC = 0;
T0IR = 0xffffffff;
T0EMR = 0;
IRQEnable();
VICIntSelect = VICIntSelect & (~(1<<4));
VICVectCntl2 = 0x20 | 4;
VICVectAddr2 = (uint32)Timer0_IRQ;
VICIntEnable = 1 << 4;
T0TCR = 0x01; //start
}
/****************************************************************/
int main(void)
{
OverTimeCounter = 0;
OverTimeFlag = 0;
Timer0Init(40); //25ms
IO0DIR = LED_RUN | LED_T | LED_R;
IO0SET = LED_RUN | LED_T | LED_R; //turn off all led
OverTimeCounter = 20; //500ms
/* while(OverTimeFlag==0); */
for(;;)
{
while(OverTimeFlag==0);
IO0CLR = LED_R; //turn on
if(OverTimeFlag)
{
OverTimeFlag = 0;
IO0CLR = LED_T; //turn on
}
}
return 0;
}
运行结果是只有在Timer0中断程序里的LED_RUN灯亮了,其他两个灯都不亮,程序停止在while语句处,无论while语句放在主程序还是被注释处运行结果都一样。如果把while语句去掉,三个灯都亮了。困惑中,期待解决。。。。。。
|