Menus on LCD for embedded systems

Hi

I want to have menus (with sub menus and so on) on a LCD (graphics LCD and I can have about

4 lines on it) of an embedded system. I am programming in C (MPLAB C18 does not support C++). The system has three keys, UP, DOWN and ENTER. I have searched a lot on the internet for data structures and methods for such applications. I have found that lot of people say pointer to functions can make life really simple in such menu driven systems.

Can any one share an small example (in C) from which I can take over. I would like to have following things in the menu code:

  1. Menus can be easily added or removed without having to change lot of code.

Thanking you an advance. M

Reply to
murphy001
Loading thread data ...

An ordinary state machine is often all that's needed. The arrow keys move an indicator up or down among the selections. When ENTER is pressed, change the state variable and set a flag that a new state has been entered. When you loop back to re-enter the state machine at the new state, draw the new screen and reset the flag, then handle the key presses.

--
Rich Webb     Norfolk, VA
Reply to
Rich Webb

You'll need a menu/esc key too. Without one, you can't navigate.

Look into using arrays to pointers of functions. Its easy to associate a menu selection with an index to function you want to execute.

Reply to
Moon Shine

formatting link
and something i found, i can't remember where from I stuck here
formatting link
could be from avrfreaks

martin

Reply to
Martin Griffith

Sure you can; you just need to make "Exit" or "Done" a choice in each menu...

--Gene

Reply to
Gene S. Berkowitz

And "Back".

Reply to
Mike Silva

A menu interface can be very simple. But with only four lines on your screeen (you don't say how wide) your menus will be rather short and as a result they may have to be deep. Deep menus are confusing for a user. I wrote a program for a Luminary Micro eval board which had a graphic display with only two lines max. I wrote my code to treat the OLED display as a window over a larger menu or other display. It also had a thumbwheel for scrolling, which you will have to use buttons for. A wheel was great for this as it gave quick response in a way that would become very comfortable. I have never seen a menu system with up/down push buttons that was nice to use. Regardless, my point is that you might want to consider using menus with more than four entries if you application is at all complex. This is much preferred to having four or more levels of menus which will tend to confuse an operator.

Reply to
rickman

I wrote an article on this very topic. Although it was based around th Rabbit micro, it is coded in C and the concepts should not prove ever difficult to port. It appeared in the Nov 2003 issue of Circuit Cella (issue 160)

formatting link

entitled "Hierarchical Menus in Embedded Systems". CC's model is to charge nominal amount for the article, however the code is available for free a the ftp site ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2003/160/

-Aubrey Kagan

Reply to
antedeluvian51

Depends a bit on whether the OP's display is a 4x16 or a 4x20 (or larger, but the 4x20 is pretty common) but he could use two columns for the menus, giving him items 1-7 plus a Back or Quit entry.

Yeah, they'll be terse but we've gotten pretty well trained for that with the legends on things like consumer remote controls.

Err, controls for consumer electronics, not controls for consumers.

--
Rich Webb     Norfolk, VA
Reply to
Rich Webb

Many years ago (back when I was a young dinosaur) we did a menu with a 2 x

40 LCD. Top line was status/data, bottom line was commands. Left, right and enter keys only. When a highlighted command was "entered", the line changed to the relevant subcommands. This can go on as deep as you want. Each line had a "back" or "done", possibly both.

Orginal idea was borrowed from an HP development box in the early 80's. They had a full CRT, but the menu was on the bottom line, and there was a keyboard key directly under each of the menu items. Press a key, the menu line changed.

Scott

Reply to
Not Really Me

at

You can find some of the preliminary discussion that led to the articl here

formatting link
and here
formatting link

-Aubrey

Reply to
antedeluvian51

Scrolling down the screen isn't really a problem in a well designed menu. Sure it means that you don't have the same level of visual cues available instantly but you can soon fix that tby scrolling up and down a bit. Most embedded apps are far simpler than hosted apps so there shouldn't be that much of a problem at any rate. However, one addition that your users will really appreciate in this circumstance is an 'up' or 'back' button to move up the menu hierarchy - selecting menu options to do this is annoyingly clumbersome and the sheer effort of getting out may result in a user not bothering to go into that menu in the first instance.

One example that comes to mind to me from a user persepctive is the Meade Autostar telescope controller. You can find a full description of this, including the menu layout at

formatting link
if you are interested. That only has a two line display and a relatively complex menu structure but it is very simple to use in practice, and this is one area where the user is possibly justified in not wanting to refer to the manual (to avoid loss of night vision). I think the key there is having buttons available - arrow keys laid out in an intuitive cross, a dedicated "mode" key that goes back to the previous menu, and a numeric keypad for, well, numeric entry instead of attempting to force that into a menu layout.

To return to the OP's original question, which was more about code, I don't have any to hand but it doesn't need to be difficult. Begin with something along the lines of:

typedef struct { char *menuLabel; void (*action)(void); } MenuItem;

For each menu, create a null temrinated MenuItem array. Move back and forth about the array (and menu) with a simple index. When selected, execute menu[i].action(), or whatever you have called your menu and index. I would flesh this out a little more but am in a hurry to get off, post back if you need further hints.

--
Andrew Smallshaw
andrews@sdf.lonestar.org
Reply to
Andrew Smallshaw

The book "Front Panel" by Niall Murphy is useful. A bit dated, but the concepts are solid.

It covers a bit more than simple data-driven menus, however.

Regards,

-=Dave

Reply to
Dave Hansen

Hi Thanks a million for the very useful hints.

Let us consider a practical example: Main Menu:

1.Setup 2.Options 3.Exit

Setup Sub Menu:

1.Setup_1 2.Setup_2 3.Exit

Functions to be called for first two options: fnSetup_1(), fnSetup_1()

Options Sub Menu:

1.Option_1 2.Option_2 3.Exit

Function to be called for options menau: fnOptions_1(), fcOptions_2()

  1. First we have to define data structures for menus. They should have a string to be displayed and information about how many items are there in that menu(this will be used by the Display function that displayes the menu items on LCD when ever there is change). Next comes the function to be called.

We must have a variable to show which item is currently selected.

Any other thing?

The data structures should be such that if we want to remove a particular menu item, it should be accomplished with little code change.

  1. Initalise the Menu structure variables with strings, data etc.

  1. Make a function (DisplayMenu) to display menu items when ever the LCD is to be updated, say after a option is selected. It should be able to print the Current menu item in Inverse video/or some indication of "current selection".

  2. A switch statement to process the key events (UP, DOWN and ENTER). It will change the current selection depending upton the key pressed. Then the LCD should be updated.

Suggestions for code for above things are welcome. Thanking you in advance With Best regards M

Reply to
murphy001

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.