【发布时间】:2016-08-20 10:39:32
【问题描述】:
我在 Keil 上使用 STM32F 微控制器。我在while 或for 循环上有问题。共享代码是我的错误部分。我的 for 或 while 循环不起作用。我停留在“step = 2”和“counter = 0”。我尝试了发布和调试模式。调试模式我看到了这个结果监视屏幕;
step = 1 (WaitData = 1) after systemtick 在那个 systemtick = 5000 after that step = 2 (systemtick = 0 waitdata = 0) 之后增加,但代码堆栈在 for 循环上。
#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)
{
}
}
【问题讨论】:
-
waitdata和WaitData应该是同一个变量吗?随机格式的代码真的很难阅读,但看起来它甚至无法按原样编译。 -
是的,这些都是一样的。
标签: while-loop arm keil