CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

IF statement and push buttons

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
matt1eg



Joined: 05 Feb 2009
Posts: 14

View user's profile Send private message

IF statement and push buttons
PostPosted: Wed Mar 18, 2009 7:01 pm     Reply with quote

Hi

I think I'm just being stupid but I can't get a sub-routine to work as I need it. It is meant to detect what button is pushed and then do something accordingly. All works except one statement. This is the last else if
Code:
else if(!input(CANCEL)){
         printf(lcd_putc,"\f\n   ARE YOU SURE?");
         printf(lcd_putc,"\n\nYES = SEL   NO = CAN");
         delay_ms(200);
         if(!input(SELECT)){
            printf(lcd_putc,"\f\n     CANCELLED");
            delay_ms(1600);
            break;
         }
         else if(!input(CANCEL)){
            continue;
            delay_ms(250);
         }
      }      


When either button is pressed it doesnt do the action in the sub if and else but the action of the button in the while loop. The code is below which should help me make sense more
Code:
void Set_Tariff()
{
   delay_ms(100);

   Tariff = 0;
   printf(lcd_putc,"\f    ENTER TARIFF\n",);
   printf(lcd_putc,"%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,
                                 0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06);
   printf(lcd_putc,"    %2.1fp PER UNIT\n",tariff);   
   printf(lcd_putc,"\nMORE = +   LESS = -");
   
   while(Tariff_Set==FALSE){

      if(!input(INCREMENT)){    //This Works fine
         Tariff += 0.5;
         delay_ms(200);
         printf(lcd_putc,"\f    ENTER TARIFF\n");
         printf(lcd_putc,"%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,
                                          0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06);
         printf(lcd_putc,"    %2.1fp PER UNIT",tariff);
         printf(lcd_putc,"\n\nYES = SEL   NO = CAN");
      }
      else if(!input(DECREMENT)){       //This Works fine   
         Tariff -= 0.5;
         delay_ms(200);
         printf(lcd_putc,"\f    ENTER TARIFF\n");
         printf(lcd_putc,"%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,
                                         0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06);
         printf(lcd_putc,"    %2.1fp PER UNIT",tariff);
         printf(lcd_putc,"\n\nYES = SEL   NO = CAN");
      }
      else if(!input(SELECT)){     //This Works fine
         Tariff_Set = TRUE;
         delay_ms(200);
      }
      else if(!input(CANCEL)){    // This is the Problem
         printf(lcd_putc,"\f\n   ARE YOU SURE?");
         printf(lcd_putc,"\n\nYES = SEL   NO = CAN");
         delay_ms(200);
         if(!input(SELECT)){
            printf(lcd_putc,"\f\n     CANCELLED");      //If I press 'select' it does the previous statement
            delay_ms(1600);
            break;
         }
         else if(!input(CANCEL)){      //Same kind of issue here
            continue;
            delay_ms(250);
         }
      }      
   }   
}


I'm sure its just my fairley basic knowledge of C but I don't know a way around it or to sort it.

Any suggestions welcome

Cheers
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Thu Mar 19, 2009 3:33 am     Reply with quote

First problem, it will always do the previous condition if SELECT is pressed, you need to change it so that it only does this if CANCEL is NOT pressed!

Code:

      else if(input(CANCEL) && !input(SELECT)){     //This Works fine
         Tariff_Set = TRUE;
         delay_ms(200);
      }
      else if(!input(CANCEL)){    // This is the Problem
         printf(lcd_putc,"\f\n   ARE YOU SURE?");
         printf(lcd_putc,"\n\nYES = SEL   NO = CAN");
         delay_ms(200);
         if(!input(SELECT)){
            printf(lcd_putc,"\f\n     CANCELLED");      //If I press 'select' it does the previous statement
            delay_ms(1600);
            break;
         }
         else {      //Don't need to do a check here as we already know CANCEL is false!
            continue;
            delay_ms(250);
         }
      }     
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group