他使用KE的驱动库,开发环境Keil,写了这么一段代码:
unsigned int count;
void main()
{
  count=5;
  while(count>0);   
  ......
}
void PIT_ISR(void) 
{   
  ......
  if(count>0)
      count--;
}
本意是想做一个延时,在PIT中断里count每次减1,当减到0时,main函数继续向下执行。
结果发现当count减到0时,并没有跳出while循环。
后来找到了解决办法:
1) KE驱动库中Keil设置的优化等级如下:

这个default等级是Level 2

当改为Level 0 等级之后程序就可以正常运行了。
1)将unsigned int count; 定义前加上 volatile 也可以
关于这个问题的讨论可以参考帖子:http://www.eeskill.com/group/topic/id/1905
另外关于编译器优化问题,可参考同事Jicheng的两篇博客:
http://www.eeskill.com/article/id/48622
http://www.eeskill.com/article/id/48623
P.S
1) IAR 优化指令

2) 关于Keil-MDK 优化的文档
(下载地址:http://www.eeskill.com/file/id/39639)
 Getting the Best Optimized Code for your Embedded Application.pdf
Getting the Best Optimized Code for your Embedded Application.pdf
 ARM® Compiler Software Development Guide.pdf
ARM® Compiler Software Development Guide.pdf