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

LCD menu with keypad

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



Joined: 19 Nov 2019
Posts: 2

View user's profile Send private message

LCD menu with keypad
PostPosted: Tue Nov 19, 2019 12:48 am     Reply with quote

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:
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.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: LCD menu with keypad
PostPosted: Wed Nov 20, 2019 7:55 am     Reply with quote

bearzalk wrote:

it only goes to sub menu when I press one of these keys around 20 times.

This sounds like a problem with your usage of the kbd_getc() function.

The program in this post shows how to use a timer interrupt to call
the kbd_getc() function every 10 ms.
http://www.ccsinfo.com/forum/viewtopic.php?t=42707&start=4
bearzalk



Joined: 19 Nov 2019
Posts: 2

View user's profile Send private message

Re: LCD menu with keypad
PostPosted: Wed Nov 20, 2019 8:51 am     Reply with quote

PCM programmer wrote:
bearzalk wrote:

it only goes to sub menu when I press one of these keys around 20 times.

This sounds like a problem with your usage of the kbd_getc() function.

The program in this post shows how to use a timer interrupt to call
the kbd_getc() function every 10 ms.
http://www.ccsinfo.com/forum/viewtopic.php?t=42707&start=4


Thanks a lot for reply, I'll try this. Just a quick question, why does it work when there is only printf in case '*' and can you check this topic sometimes because I'll update the status after I try your solution, I'd like to get your help if this solution does not work.
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