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.

[参考译文] MSP430F5529:在 MSP430F5529LP 延迟功能不工作

Guru**** 2540720 points


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

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/570581/msp430f5529-in-msp430f5529lp-delay-function-not-working

器件型号:MSP430F5529

亲爱的朋友

我将 MSP430F5529LP 与4MHz XT2晶振和32.768kHz XT1晶振搭配使用。 我编写了一个类似这样的延迟函数

1)此延迟功能不起作用

空 DelayMs (无符号 int count)

unsigned int i;

for (i=100;i>0;i--);

计数--;  

2)此延迟功能正在工作

空 DelayMs (无符号 int count)

volatile unsigned int i;

for (i=100;i>0;i--);

计数--;  

我不确定 MSP430系列中是否存在 volatile 关键字的任何重要作用?

谢谢、此致

Beeresh

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

    [引述 USER="BEERESH GUDADAR "]我不确定 MSP430系列中是否存在易失性关键字的任何重要作用?[/QUERPLET]

    这与微控制器系列无关、而是与编译器优化有关。 禁用代码优化、您将看到两个"延迟函数"都起作用。 如果您研究 volatile 的含义、则可能会了解编译器为何无法优化 delay 函数#2的()周期的 empty。

    老实说- for () cycle 是执行延迟的错误方法。 最好使用__delay_cycles ()。