# Need C code to display/Manage Menu on LCD by Keyboard

Status
Not open for further replies.

#### niket_304

##### Member level 4
rashby054

Hello,
I have 89c51/89c668 based hardware in which I have interfaced a PC AT Keyboard and 16X2 LCD. I have LCD driver as well as Keyboard software in C. But I need a C code to display Menu Structure on LCD and I can manage menu by keyboard.So please give me the C code for menu structure for LCD and Keyboard. I will be vey greatful to you.

#### coshkun

##### Full Member level 2
lcd menu state machine

I asked the same question but nobody answered yet...

#### Code Warrior

##### Full Member level 4

niket can you give us info about which C compiler you are using and which development board you are using. Where are you from.

#### silvio

##### Advanced Member level 3
Don't you think Robert is a smart guy ?

Quote from World of Robert Ashby
You can tell someone's a geek if they first describe a menu using the words file, edit, and view instead of breakfast, lunch, and dinner. One of the great things about the World of Robert is that I get to dip my fingers in lots of different projects that give me enough variety to make me somewhat of a Jack-of-all-trades and master-of-none. I've learned, almost invariably, that I need to listen to everyone (they probably know something you can learn), and there's probably a better way (if you spend enough time). Unfortunately, you usually need to complete designs without a complete knowledge or adequate research, and you can usually get a design 80% of the way to perfect in 20% of the time, and spend the rest of forever fine-tuning those last undesirables out of the design.

You can save yourself a lot of heartache when your design is based around concepts and structures that already exist in other products, even if those products don't directly relate to what you are doing

https://archive.chipcenter.com/eexpert/rashby/rashby054.html
and responses to above article
https://archive.chipcenter.com/eexpert/rashby/rashby056.html
especially responses from Aubrey Kagan, Kenneth W. Reighard and Bill Burton .

According to Robert's thoughts, the "C" chalenge :

https://www.bytecraft.com/cop8flash.html

Try deciphering meanings and purpose of:
const char far * menu_strings[]
void handle_menu_request(char far * table_ptr)

As you can see it's not right on the shelf.

Or you can wait until samples codes will be posted at the bottom of page : www.eagleairaust.com.au/sampcode.htm

#### sn_burki

##### Full Member level 5
Its a very good Question even I also want to study Keyboard working so I can interface with ATmel controller with my projects even I want to know how Usb port work and how i can interface my projects to this port? If any one has any idea plz do upload details.
regards

#### coshkun

##### Full Member level 2
I tried something for my project.My menu have 4 submenus and a associated parameter.It works fine in ISIS simulation but it doesn't on the board.After a few fast pushes it gets stuck.What can be the problem? I put some delays after button pushes but still it doesnt work properly.

#### maxer

##### Member level 5
all precedent are not the right way to do what you want!

i reccomend you to study carefully a simple state machine with as many states as submenues you have to switch to.

this machine can be coded in c easily as you construct a diagram for what you want to do.
Start imaginating how would you code this machine in paper with states: A,B,C,D etc. and then how should the current state change under external condition (button pressing etc...) from A to B or from A to C, D etc.

Code in C and run it in a loop making attention to include a delay in it so you can control the speed at which the State machine runs. Each state has to perform operations as your project in detail requests.

regards

maXer

Added after 5 minutes:

oh i forgot

proteus runs the project at a certain frequency and assumes some real errors not as theorytical errors so for the simulator your project is OK.

These problems may be tied to : bad clock selection in reality, wrong delay routines etc.

the best thing to do in all your cases is to lower the crystal frequency and to modificate the code for such a clock so critical problems due to delays can be eliminated.Start at clk= 1Mhz. That would be standard and not create problems.

maXer

Added after 2 minutes:

and ciao a silvio !

#### coshkun

##### Full Member level 2
Actually i used the similar state machine logic.That's what i came up with:
Code:
void main(void)
{

//Forever loop
while(1){

{
while(RD4==0);
DelayMs(sometime);
}
}//end of while loop

}

lcd_clear();
lcd_puts(m1);
lcd_goto(71);
lcd_puts(m2);

while(1)	{ //submenu forever loop

if(RD0==0){ //increment
while(RD0==0);
DelayMs(sometime);
// do something

}

if(RD1==0){ //artır
while(RD1==0);
DelayMs(sometime);
//do something

}

while(RD4==0);
DelayMs(sometime);
break;
}
}
//end while
return;
}//end menu1

am i doing something wrong? Can't we use forever loops in our functions?

#### maxer

##### Member level 5
no i would reccomend to you using case instruction instead of IF == etc etc...

use a while (forever loop ) and then use the case instruction for each menu0,1...

maXer

Added after 2 minutes:

and avoid delay routines internal to each IF...

try replacing IFs with Case and instead of using too many DELAY routines which may have an unpredictable total delay use only one at the end of the main While statement.

maxer

Added after 2 minutes:

and use only one WHILE forever loop from which you execute the function that manages the states,as i see you have 2 of them,i don't think this is very good...

hope to have been of help to you

maxer

Status
Not open for further replies.