This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

conditional if statement

i want use if satement, to do something for the one time, example:

main(){
char k;
k=0;

while(1){

if(k==0){
printfLCD("please only one time\n");
k=1;
}//end if

printfLCD("test message\n");

}//end while
}//end main

but it isnt work, program enters the if statement infinite time. where is the error?, there is anyything about keilc51, which is i dont know? i use upsd3434 8051 microcontroler, sory for my nglish

Parents
  • Which memory model are you using (small/compact/large) ?

    If you are using the large model, be aware that the compiler might try to locate the variable k in xdata memory, which might need to be enabled first on your uC (consult the uCs datasheet for details on this).

    Try declaring your variable k as

    unsigned char data k;
    

    and check if the program behaves differently.

    Also, please read the hints on posting source code (they appear right above the the text window when you write a posting). Following them will make your source code much more legible.

Reply
  • Which memory model are you using (small/compact/large) ?

    If you are using the large model, be aware that the compiler might try to locate the variable k in xdata memory, which might need to be enabled first on your uC (consult the uCs datasheet for details on this).

    Try declaring your variable k as

    unsigned char data k;
    

    and check if the program behaves differently.

    Also, please read the hints on posting source code (they appear right above the the text window when you write a posting). Following them will make your source code much more legible.

Children
No data