While Loop Always True Ccs

While Loop Always True Ccs

I'm using CCS compiler and for this piece of code getting a warning that condition is always true. This is a code for PIC16F877, so when the input is 1 , it should break out of loop. Am I missing something here?

int read_keypad()
{
   int value=0;
   while(1)
   {
     UpButton=0;                  // In case of bad Input
     DownButton=0;
     RightButton=0;
     LeftButton=0;
     EnterButton=0;

     output_high(sat1); 
     if (input(sut1)) 
     {    
       value=1;
       while(input(sut1));
       break;
     }
}

1 Answer

The loop condition is always true. That warning does not mean that your loop could not possibly exit, just not through its test condition.

When input(sut1) returns true you are entering a loop that does nothing until input returns false, then you are breaking out of your outer loop and exiting read_keypad()

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

James H. Sterling
Author

James H. Sterling

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.