Sarim Khan
Sarim Khan

Reputation: 11

Loop condition does not stop the program

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);
}

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.

Upvotes: 0

Views: 126

Answers (1)

Mike
Mike

Reputation: 4288

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

__CONFIG _WDT_OFF

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

Upvotes: 1

Related Questions