I have a problem with my menu integration. I am currently using keypad to switch menu sections like when I press 'A' on keypad go to a sub-menu or press 'B' to go another sub-menu, when I press '*' inside of these sub-menus then go back to main menu.
I don't have any problem about going to sub-menus when program started but after I press '*' to go to main menu, I can't go back to any of sub-menus.
The code is as following:
If there is only printf inside case '*' then program works as I want, but when I comment out the printf and put MainMenu(); in there then it doesn't go to anywhere after I press '*', it keeps displaying main menu.
In program's first execution, when I press 'D' then it goes to sub menu, when I press * it goes back to main menu but while in main menu it doesn't go to sub menu when I press A,B,C or D, it only goes to sub menu when I press one of these keys around 20 times.
I don't have any problem about going to sub-menus when program started but after I press '*' to go to main menu, I can't go back to any of sub-menus.
The code is as following:
Code: |
char K; char T; void MainMenu() { do { K = kbd_getc(); T = K - 48; lcd_gotoxy(1,1); printf(lcd_putc,"A)MOD B)SET HOUR"); delay_ms(5); if((K=='A') || (K=='B') ||(K=='C') || (K=='D')) { printf(lcd_putc,"\f U is zero now"); U=0; } }while(U==1); } void AltMod() { lcd_gotoxy(21,1); printf(lcd_putc, "\fPRESS * FOR MAIN MENU\n"); delay_ms(5); lcd_gotoxy(1,2); printf(lcd_putc,"ENTER NUM=>\n"); } void AltModRun() { do { K = kbd_getc(); T = K - 48; if((K!=0) && (K!='A') && (K!='B') && (K!='C') && (K!='D')&& (K != '*') && (K != '#')) { A = (A*10) + T; //Don't add Y=20 here, it resets it to 20 in every cycle Y++; lcd_gotoxy(Y,1); printf(lcd_putc,"PRESS # FOR SUBMIT %d",T); delay_ms(5); } if(K=='#') { num= A; lcd_gotoxy(21,2); printf(lcd_putc,"%d NUM IS CHOSEN", num); delay_ms(5); } if(K == '*') { printf(lcd_putc,"\fINSIDE MOD STAR"); Y=20; Z=0; A=0; } }while(Z==1); void main() { kbd_init(); port_b_pullups(true); set_tris_b(0xF0); rtc_init(); lcd_init(); MainMenu();//To display Main menu when program starts while(true) { K = kbd_getc(); T = K - 48; switch(K) { case 'D': Z=1; AltMod(); AltModRun(); break; case '*': U=1; printf(lcd_putc, "\fINSIDE CASE STAR"); //MainMenu(); break; } } } |
If there is only printf inside case '*' then program works as I want, but when I comment out the printf and put MainMenu(); in there then it doesn't go to anywhere after I press '*', it keeps displaying main menu.
In program's first execution, when I press 'D' then it goes to sub menu, when I press * it goes back to main menu but while in main menu it doesn't go to sub menu when I press A,B,C or D, it only goes to sub menu when I press one of these keys around 20 times.