循环条件不会停止程序 [英] Loop condition does not stop the program

查看:88
本文介绍了循环条件不会停止程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

void initTimer (void);
void delay (unsigned long milli);

unsigned int counter;
unsigned int zero =  0b0000000000000000;
unsigned int one =   0b0000000001000000;   

int main (void)
{
    initTimer();

    TRISB = 0;

    LATB = 0;

   for (counter = 0; counter < 10; counter++) {
       LATB = zero;
       delay (SHORT_DELAY);
     
       LATB = one;
       delay (SHORT_DELAY);
      
   }
       while (1);
}

即使计数器超过10,循环中的代码也会执行.LED继续闪烁.所有变量都已声明,所有数字变量均为二进制,不确定是否有意义.

The code in the loop executes even after the counter crosses 10.The LEDS continue to flash. All variables are declared and all the number variables are binary, not sure if that means much.

推荐答案

您必须在配置中关闭看门狗定时器,类似:

You had to switch off the watchdogtimer in your configuration, Something like:

__CONFIG _WDT_OFF

否则,程序将始终重新启动,并通过您的 for 循环再次运行

Otherwise the program will always be restartet and runs again thru your for loop

这篇关于循环条件不会停止程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆