HI!
I'm using the PIC18F452 20MHZ
I have a problem with the switch statement because when I add more "case" in the switch statement appears many meaningless characters on my display.
NOTE: I've tried on the compiler 4.10 and 4.15 and i have the same problem.
Thank you
fernandomarques
#define UP 26
#define LF 9
#define RH 11
#define DW 12
//TO RECEIVE CHARACTERS FROM MY KEYBOARD
unsigned char MGetc(void)
{
while(!PIR1.RCIF);
return RCREG;
}
void main()
{
unsigned short key;
UART1_Init(9600);
while(1)
{
key=MGetc(); //THIS IS MY FUNCTION TO RECEIVE CHARACTERS FROM MY KEYBOARD
switch(key)
{
case UP: UART1_Write_Text("UP");
break;
case LF: UART1_Write_Text("LF");
break;
case RH: UART1_Write_Text("RH");
break;
case DW: UART1_Write_Text("DW");
break;
case 10: UART1_Write_Text("JK"); //UNTILL THIS LINE WOKS WELL
break;
/* FROM THIS LINE UNTILL THE END DOES NOT WORK
APPEARS (TO MANY CHARACTERS ON THE DISPLAY */
case 13: UART1_Write_Text("LM");
break;
case 14: UART1_Write_Text("MN");
break;
case 15: UART1_Write_Text("OP");
break;
case 16: UART1_Write_Text("HJ");
break;
default: UART1_Write_Text("UI");
break;
}
}
}
PROBLEM WITH SWITCH INSTRUCTION
- slavisa.zlatanovic
- mikroElektronika team
- Posts: 1321
- Joined: 07 Apr 2009 09:39
Re: PROBLEM WITH SWITCH INSTRUCTION
Hi!
The Switch statement is working fine.
I have made some changes to your code and now it is working properly:
P.S.
We strongly encourage users to switch to PRO version because non-PRO version is an ancestor of PRO compiler
and is no longer being developed.
Every new feature, improvement and bug fix will only affect new versions of PRO compilers.
If you're a registered user you'll receive PRO license key free of charge.
See the migration document for more details:
The Switch statement is working fine.
I have made some changes to your code and now it is working properly:
Code: Select all
#define UP 26
#define LF 9
#define RH 11
#define DW 12
//TO RECEIVE CHARACTERS FROM MY KEYBOARD
unsigned char MGetc(void)
{
while(!PIR1.RCIF);
return RCREG;
}
void main()
{
unsigned short key;
UART1_Init(9600);
Delay_ms(100);
UART1_Write_Text("START");
while(1){
//key=MGetc(); //THIS IS MY FUNCTION TO RECEIVE CHARACTERS FROM MY KEYBOARD
if (UART1_Data_Ready()) { // ! use Library routines
key = UART1_Read(); // ! see the Help file for more details
switch(key)
{
case UP: UART1_Write_Text("UP");
break;
case LF: UART1_Write_Text("LF");
break;
case RH: UART1_Write_Text("RH");
break;
case DW: UART1_Write_Text("DW");
break;
case 10: UART1_Write_Text("JK"); //UNTILL THIS LINE WOKS WELL
break;
/* FROM THIS LINE UNTILL THE END DOES NOT WORK
APPEARS (TO MANY CHARACTERS ON THE DISPLAY */
case 13: UART1_Write_Text("LM");
break;
case 14: UART1_Write_Text("MN");
break;
case 15: UART1_Write_Text("OP");
break;
case 16: UART1_Write_Text("HJ");
break;
default: UART1_Write_Text("UI");
//break;} // !
}
}
}
}
We strongly encourage users to switch to PRO version because non-PRO version is an ancestor of PRO compiler
and is no longer being developed.
Every new feature, improvement and bug fix will only affect new versions of PRO compilers.
If you're a registered user you'll receive PRO license key free of charge.
See the migration document for more details:
Best regards
Slavisa
Slavisa
-
- Posts: 26
- Joined: 24 May 2010 10:15
Re: PROBLEM WITH SWITCH INSTRUCTION
Dear Slavisa
I apologize because it was my mistake. I have one problem with my bootloader, because it do not put the null terminator at the end of the string, so it cause senseless strings
Once again my apologies
thank you
fernandomarques
I apologize because it was my mistake. I have one problem with my bootloader, because it do not put the null terminator at the end of the string, so it cause senseless strings
Once again my apologies
thank you
fernandomarques