This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

同一个程序,用CCS和IAR分别下载到单片机中,现象不同。

Other Parts Discussed in Thread: MSP430G2452

硬件设备:MSP430 Launch——MSP430G2452单片机

软件程序:

#include<msp430g2452.h>

void delay();


void main()
{
WDTCTL = WDTPW + WDTHOLD;
P1DIR=0XFF;

P1OUT |=BIT0;
while(1)
{
delay();
P1OUT<<=1;
}
}

void delay(void)
{
unsigned int i;
i = 50000; // Delay
do (i--);
while (i != 0);
}

用IAR编译下载,LED从左到右依次点亮,实验现象正常

用CCS编译下载,LED没有任何反应。

但CCS使用如下程序,实验现象正常。

#include<msp430g2452.h>

void delay();


void main()
{
WDTCTL = WDTPW + WDTHOLD;
P1DIR=0XFF;

P1OUT |=BIT0;
while(1)
{
delay();
P1OUT<<=1;
}
}

void delay(void)
{
volatile unsigned int i;
i = 50000; // Delay
do (i--);
while (i != 0);
}

为什么要使用volatile?