If...Else Statement not working properly

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

If...Else Statement not working properly

2,765 Views
krude
Contributor I
Hi,
Krude here. I am experiencing problem with the If...Else statement. I know it's very simple but I not sure why that after the condition match, the program would not go into the code but jump out of the If....Else statement. Attached below is my code*no modification done*. The statement works on my main code body but not after I place it on another file, so I can use it as an object. Thanks for helping me out. Arigatou!
---------------------------------------------------------------------

#include "derivative.h"
#include "M68DEMO908GB60" /*customized header file for GB60DEMO board*/
#include "timer.h" //customized header file for timer
#include "leds.h" //customized header file for LED
#include "sine.h" //customized header file for sine wave
#include "dac.h"
#include "swtiches.h"

int ichoice;
int iTimActPerioddef;

int swit::check (void){

int iwaitmain=0, iSW2flag, iSW3flag,FFreqFlag=0;

timer2 Timer1;

if(SW4 == DOWN){ //SW1 start the data transfer process

if(ichoice=31){
iTimActPerioddef = 96;
TPM1C0SC_CH0IE = 1;
FFreqFlag = 0;
}else if (ichoice>31){
FFreqFlag = 1;
TPM1C0SC_CH0IE = 0;
}

} else if (SW2 == DOWN){ //SW2 increase the frequency

iSW2flag = 1;//the flag will be set when SW2 is pressed down. Flag is to prevent multi-increment of the ichoice

} else if(iSW2flag == 1 && SW2 == UP){

if(ichoice 36){
ichoice ++;
}
iSW2flag = 0;
Timer1.timdelay(1000);

} else if(SW3 == DOWN){ //SW3 decrease the frequency

iSW3flag = 1;//the flag will be set when SW2 is pressed down. Flag is to prevent multi-decrement of the ichoice

} else if(iSW3flag == 1 && SW3 == UP) {

if(ichoice > 0){
ichoice --;
}
iSW3flag = 0;
Timer1.timdelay(1000);
} else{

}
return FFreqFlag;
}
Labels (1)
Tags (1)
0 Kudos
Reply
3 Replies

768 Views
krude
Contributor I
Hi, I don't know how to edit my text, so I double post. And apparently, I pasted my code but forget to do some checking. Hehe. The code was pasted incorrectly. And sorry again for not specifying which If...Else. I was refering to the If...Else statement which contains my SW4, SW2, SW3 as parameters. If you can see, my higher priority If...Else statement is the statement which contains my SW4 and etc...
P.S please ignore the If..Else which uses parameter, ichoice because that is not the problem If...Else. I am facing. Thanks. >.
---------------------------------------------------------------------

#include "M68DEMO908GB60.h" /*customized header file for GB60DEMO board*/
#include "timer.h" //customized header file for timer
#include "leds.h" //customized header file for LED
#include "sine.h" //customized header file for sine wave
#include "dac.h"
#include "swtiches.h"

int ichoice;
int iTimActPerioddef;

int swit::check (void){

int iwaitmain=0, iSW2flag, iSW3flag,FFreqFlag=0;

timer2 Timer1;

if(SW4 == DOWN){ //SW1 start the data transfer process

if(ichoice==31){
iTimActPerioddef = 96;
TPM1C0SC_CH0IE = 1;
FFreqFlag = 0;
}else if (ichoice>31){
FFreqFlag = 1;
TPM1C0SC_CH0IE = 0;
}

} else if (SW2 == DOWN){ //SW2 increase the frequency

iSW2flag = 1;

} else if(iSW2flag == 1 && SW2 == UP){

if(ichoice> 36){
ichoice ++;
}
iSW2flag = 0;
Timer1.timdelay(1000);

} else if(SW3 == DOWN){ //SW3 decrease the frequency

iSW3flag = 1;

} else if(iSW3flag == 1 && SW3 == UP) {

if(ichoice > 0){
ichoice --;
}
iSW3flag = 0;
Timer1.timdelay(1000);

}
return FFreqFlag;
}
0 Kudos
Reply

768 Views
admin
Specialist II


 


if(SW4 == DOWN){ //SW1 start the data transfer process

if(ichoice==31){


Does it have anything to do with the fact that the if() tests SW4, but your comment references SW1?

Just a thought,

Tomahawk

0 Kudos
Reply

768 Views
MH
Contributor I

Hi Krude,

I don't know which If..Else statement you are referring to but some of the code will not be reached because of the single = in 

if(ichoice=31)

instead of

if(ichoice==31)

However, since you also have if(ichoice 36) maybe that is also just a typo in creating your post and nothing to do with the problem?

Regards,

Malcolm

Message Edited by MH on 06-06-2006 07:32 AM

0 Kudos
Reply