Gary Chio

a weird problem of "FOR loop"

Discussion created by Gary Chio on May 15, 2006
Latest reply on May 15, 2006 by David Payne
got a weird problem when i use the dual FOR loop in my program.
this program will turn off the LED2 when it finished.
but i found if the variable i and j greater than some value,the FOR loop couldn't quit.
the entire program will loop forever..~___~"
i had checked the C reference book,think the syntax should be correct.
the attached file is my test project.
could anyone please try it if it happened as well?
 
 
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
#define LED2 PTBD_PTBD7
 
void MCU_init(void); /* Device initialization function declaration */
 
void test(void){
 short int i,j;
 for(i=0;i<=600;i++){
  for(j=0;j<=600;j++){
   
   LED2 = 0;
   
  }  //j end
 }  //i end
 
} //test end
 
void main(void) {
 
 /* Uncomment this function call after using Device Initialization
    to use the generated code */
 /* MCU_init(); */
 
 //EnableInterrupts; /* enable interrupts */
 
 /* include your code here */
 PTBDD_PTBDD7 = 1; //Set PTB7 as an output
 
 LED2 = 1;  //turn off LED2
 test();      //turn on LED2
  LED2 = 1; //turn off LED2
 

 for(;:smileywink: {
   __RESET_WATCHDOG(); /* feeds the dog */
 } /* loop forever */
 /* please make sure that you never leave this function */
}

Outcomes