遇到这样一个问题,不知道MSP430是如何对循环进行优化的。开发环境ccs5.4,launchpadG2553.
代码1:官方例程去掉volatile,循环结果i为0;变量I以及循环全部被优化掉了,灯不闪烁。
for (;;)
{
unsigned int i=50000;
P1OUT ^= 0x01; // Toggle P1.0 using exclusive-OR
do (i--);
while (i!=0);
}
代码2:只要循环最后i不为0,就不会被被优化,灯正常闪烁。
for (;;)
{
unsigned int i=50000;
P1OUT ^= 0x01; // Toggle P1.0 using exclusive-OR
do (i--);
while (i!=1);
_nop();
}
这是为什么呢?