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.

[参考译文] 编译器/TMS320F2.8335万:当指令导致死循环时

Guru**** 2556800 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/tools/code-composer-studio-group/ccs/f/code-composer-studio-forum/588655/compiler-tms320f28335-while-instruction-cause-dead-loop

部件号:TMS320F2.8335万

工具/软件:TI C/C++编译器

我使用的是CCS 7.0 0/0和 TI 6.2 .1709编译器。在以下代码中,语句“while (ReceivedChar ==0);”使程序始终 保持在此处,即使ReceivedChar从串行端口中断获得非零值,也无法继续,当我在表达式监视窗口中暂停程序时, 我可以看到变量“Receivedchar”有一个非零值,它与 从串行端口接收的字符的值相匹配,但程序不能跳过这一while循环。如果我将此while语句更改为“if (Receivedchar !=0)",程序工作正常。 我不知道为什么,感谢您的帮助

对于(;;)

//等待inc字符


while (ReceivedChar ==0);


//获取字符
//ReceivedChar = SciaRegs.SCIRXBUF.ALL;

//回显字符
MSG ="您已发送:\0";
scia_msg (msg);
scia_xmit (ReceivedChar);
ReceivedChar =0;
MSG ="\r\n输入一个字符:\0";
scia_msg (msg);
}
LoopCount++;
}

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    可以在执行的主线程范围之外更改的任何变量(如ReceivedChar)都必须使用关键字volatile限定。  有点像……

    volatile char ReceivedChar; 

    请阅读 有关 volatile的这篇Wiki文章。

    谢谢,此致,

    -George