Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

LCD Display

Status
Not open for further replies.

TucsonDon

Member
I have a 4x20 LCD that I am trying to get a menu to display.
This is what I have so far
On my header file
C:
typedef enum
{
    UIModesSetting,
            Time,
            Pump,
            Solar,
            Waterfall,
            Clean
}MainModes;

On my source file
C:
void UIModeSet(void)
{
  

    switch(UIModesSetting)
    {
        case Time:
        {
            UITimerSet();
        }

        case Pump:
        {
            //UIPumpSet();
        }

        case Solar:
        {
            //UISolarSet();
        }

        case Waterfall:
        {

        }

        case Clean:
        {

        }
    } /*end of shift()*/

}

I have four buttons as inputs : Mode, Up, Down, Enter. What I am trying to do is when I push the mode button the main menu will be displayed then scroll up or down with the corresponding button push then display the sub-menu when enter button is pushed .

P.S How do I get code to display as code and not text when posting?
 
Last edited:
P.S How do I get code to display as code and not text when posting?
I just type in the HTML tags...
upload_2017-9-23_21-23-57.png

Change to "code=asm " if you are using asm..

Menu control is quite easy.. What I do is cycle through a menu and once the correct item has been selected then enter the function. I only use two lines and scroll through the menuitems one by one..
 
Enum is just a way of making code readable....

enum{
Time;
Pump;
Solar;
Waterfall;
Clean;
}MainModes;

This just makes Time = 0 Pump = 1 etc..
For display purposes you need a string array.

unsigned char modeText[][] = { "Time:","Pump:","Solar:","Waterfall","Clean"};

Then display... LCD_print(modetext[time]);

This is totally untested, so try it out..
 
This is what I came up with

C:
void ModeDisplay(void)
{
    char buff[17];
    unsigned char DisplayText[2] = {"Time","Pump","Solar","Waterfall","Clean"};
    sprintf(buff, "%c", DisplayText[1][1]);
    while (BusyXLCD());
    LCDMove (2,10);
    putsXLCD(buff);
}
I get errors when I compile.
also not sure how to scroll up or down, I'm displaying on col-2 row-10 so the line below would 3,10?
 
I have tried but still getting the following error and not sure how to fix

error: (316) "}" expected
error: (240) too many initializers
error: (241) initialization syntax
error: (981) pointer required

these errors are in the second and third lies
C:
unsigned char DisplayText[2] = {"Time","Pump","Solar","Waterfall","Clean"};
    sprintf(buff, "%c", DisplayText[1][1]);

I also changed void ModeDisplay(MainModes) for the enum list
 
unsigned char * DisplayText[] = {"Time","Pump","Solar","Waterfall","Clean"};
sprintf(buff, "%s", DisplayText[1]);
or
unsigned char DisplayText[5][10] = {"Time","Pump","Solar","Waterfall","Clean"};
sprintf(buff, "%s", DisplayText[1]);
 
C:
 do
    {
        scroll2 = scroll + 1;
        sprintf(buff, "%s", DisplayText[scroll]);
        LineOne;                            //goto display address
        putsXLCD(buff);
        sprintf(buff, "%s", DisplayText[scroll2]);
        LineTwo;                            //goto display address
        while(BusyXLCD());
        putsXLCD(buff);
        if (ButtonStatus.Up == On && ButtonStatus.Pushed == Off)
        {
            ButtonStatus.Pushed = On;
            scroll++;
            if (scroll >= 5) scroll = 0;
            else if (scroll2 >= 5) scroll2 = 0;
        }
        else if (ButtonStatus.Down == On && ButtonStatus.Pushed == Off)
        {
            ButtonStatus.Pushed = On;
            scroll--;
            if (scroll < 0)scroll = 4;
            else if (scroll2 < 0)scroll2 = 4;
        }
        else if (ButtonStatus.Enter == On && ButtonStatus.Pushed == Off)
        {
            MainModes(UIModesSetting) = DisplayText[scroll];
            ButtonStatus.Pushed = On;
            UIModeSet();
        }
    }
while(ButtonStatus.Mode != On && ButtonStatus.Pushed == Off);

Using the enum list that I posted in #1 as the main menu, how do I point to sub-menus for instance from "Timer" I have a menu that has "Timer1 - 8" to set and use 8 different timers?
 
Last edited:
When I set up my menu... Like I said I scroll though one at a time... When the user presses the "MENU" key the menu is invoked.

The top line displays the menulevel and the bottom the menuitem.. I have five main menu items, the fifth is the "exit" menuitem, the fourth is a sub menuitem that takes me to a calibration menu..

When I press "MENU" I cycle though each menuitem.. If I press "ENTER" then that menuitem is selected, and a new menulevel may be started. Sometimes there is only one setting per menuitem and other times, many!

The neatest way is to coincide the menuitems with data structures so each menuitem is enumerated to the data structure. This way when you work on a menuitem, the data is automatically selected and each menuitem is like a similar object. I group menu's together that hold very similar functions.

Once you have the basic menu system working as an individual object, it's easier to change viewing device..

I am porting my menusystem to a graphical display and keeping the same "menu feel" which should help my customers when using the new interface.
 
The neatest way is to coincide the menuitems with data structures so each menuitem is enumerated to the data structure. This way when you work on a menuitem, the data is automatically selected and each menuitem is like a similar object. I group menu's together that hold very similar functions.
In post #7 you showed me how to display the menu using an enumerated list. I have an enum list and a switch statment for all the sub-menu list item, I am just unsure how to move to display the list items from the selection on the main menu. For instance if I select "Time" I want to move to the timer menu. Ian Rogers can you help me with this?

C:
typedef enum
{
    UIModesSetting,
            Time,
            Pump,
            Solar,
            Waterfall,
            Clean,
}MainModes;


typedef enum
{
    UITimerSetting,
            Timer1,
            Timer2,
            Timer3,
            Timer4,
            Timer5,
            Timer6,
            Timer7,
            Timer8,
}TimerModes;
 
Last edited:
With what I posted above how do I go from the main menu to a sub-menu?
 
In post #7 you showed me how to display the menu using an enumerated list
No! That was just an Enumerated string array...

My menu is structured like this:
menu()
display menu text
setup menu variables
while( forever)
get a key
if key = x do this
if key = y do this
if key = z do this
if key = enter
if menuitem = a do this
if menuitem = b do this
if menuitem = c do this
if menuitem = d call menu2​
display text[menuitem]​


All my text is kept in an external flash chip and I read the entire screen and the display.
I have written text fetching routines... a,b and c will have associate cal data structures so storage is simple

To raise a sub menu it will be a menu item which will call... say "menu2" and then once done it will return here..
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top