I am experimenting an strange problem with C30 and MPLAB X, I have this piece of code:
unsigned char mode;
switch(mode){ // Eligo el modo que se envio a traves del UART
case FRECUENCIMETER:
vFrecuencimetro();
break;
case LC_METER:
vLC_Meter();
break;
case VOLTMETER:
break;
case 'L':
vLogicAnalizer();
break;
}
if(mode == 'L'){
vLogicAnalizer();
}
When mode is equal to 'L' character the switch doesn't enter in "case 'L'" as it should but it enters in the if sentece. But when I change my code on this way:
unsigned char mode;
switch(mode){
case 'L':
vLogicAnalizer();
break;
}
if(mode == 'L'){
vLogicAnalizer();
}
It enters perfectly on the switch statement. The other cases are defines like this:
#define FRECUENCIMETER 0
#define LC_METER 1
#define VOLTMETER 3
I am using C30 compiler v3.31 and MPLAB X v1.41. Hope you can help me.
Thank you
EDIT:
Ok according to the answer and comments I have changed my code on this way:
char mode;
#define FRECUENCIMETER 0
#define LC_METER 1
#define LOGIC_ANALIZER 76 // 'L'
#define VOLTMETER 3
#define NO_MODE 4
switch(mode){ // Eligo el modo que se envio a traves del UART
case FRECUENCIMETER:
vFrecuencimetro();
break;
case LC_METER:
vLC_Meter();
break;
case VOLTMETER:
break;
case LOGIC_ANALIZER:
vLogicAnalizer();
break;
}
If before the switch statement I write:
mode = 'L';
The switch statement works perfectly, but when I get an 'L' from UART with the function ReadUART1() which returns and unsigned int:
unsigned int ReadUART1(void);
And it returns 'L' according to my debugger which correspond to number 76 in unsigned int the switch statement doesn't work but mode is still 'L'. Even if I change mode to unsigned int to be the same as the function it doesn't work. I think I will have to use if() statements.