0
我在Keil上使用STM32F微控制器。我在while
或for
循環上遇到問題。共享代碼是我的錯誤部分。我for或while循環不起作用。我留下了「step = 2」和「counter = 0」。我嘗試了發佈和調試模式。調試模式我看到了這個結果手錶屏幕; stept = 1(WaitData = 1)在systemtick增加之後,在systemtick = 5000之後,step = 2(systemtick = 0 waitdata = 0),但for循環上的代碼堆棧。Keil - 我的while循環不起作用
#include "stm32f4xx_hal.h"
#include <stdio.h>
#include <stdlib.h>
int step = 0;
int waitdata = 0;
int systemtick1 = 0;
int counter = 0;
void HAL_SYSTICK_Callback(void)
{
if (WaitData == 1)
{
systemtick1++;
if (systemtick1 == 5000)
{
step = 2;
systemtick1 = 0;
WaitData = 0;
}
}
}
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
HAL_Delay(2000);
step = 1;
WaitData = 1;
for (; WaitData==1 ;) // Or while (WaitData == 1);
{
asc++;
}
step = 3;
while (1)
{
}
}
http://stackoverflow.com/questions/246127/why-is-volatile-needed-in-c – Notlikethat
http://stackoverflow.com/questions/38257618/is-volatile-modifier-really-needed-if -global-variables-are-modified-by-an-interr – Notlikethat
「waitdata」和「WaitData」應該是同一個變量嗎?隨機格式化的代碼很難閱讀,但看起來它甚至不會按原樣編譯。 – Notlikethat