1. 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.
    Dismiss Notice

LCD Display

Discussion in 'Microcontrollers' started by TucsonDon, Sep 23, 2017.

  1. TucsonDon

    TucsonDon Member

    Joined:
    Sep 4, 2016
    Messages:
    45
    Likes:
    0
    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
    Code (c):

    typedef enum
    {
        UIModesSetting,
                Time,
                Pump,
                Solar,
                Waterfall,
                Clean
    }MainModes;
     
    On my source file
    Code (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: Sep 24, 2017
  2. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
    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..
     
  3. TucsonDon

    TucsonDon Member

    Joined:
    Sep 4, 2016
    Messages:
    45
    Likes:
    0
    Ian Rogers how do I get enum display and scroll?
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK

    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..
     
  6. TucsonDon

    TucsonDon Member

    Joined:
    Sep 4, 2016
    Messages:
    45
    Likes:
    0
    This is what I came up with

    Code (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?
     
  7. TucsonDon

    TucsonDon Member

    Joined:
    Sep 4, 2016
    Messages:
    45
    Likes:
    0
    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
    Code (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
     
  8. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
    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]);
     
    • Like Like x 1
  9. TucsonDon

    TucsonDon Member

    Joined:
    Sep 4, 2016
    Messages:
    45
    Likes:
    0
    Ian Rogers what is the propose of the "[5][10]"? I know that they are for array length, but why the 5 & 10?
    It did compile with no errors now I just need to work on the up-down scroll.
     
  10. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
    5 strings at 10 chars long..

    I normally use pointers ( the top one...) .. You have to know where one string starts and the other ends
     
  11. TucsonDon

    TucsonDon Member

    Joined:
    Sep 4, 2016
    Messages:
    45
    Likes:
    0
    Code (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: Sep 28, 2017
  12. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
    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.
     
  13. TucsonDon

    TucsonDon Member

    Joined:
    Sep 4, 2016
    Messages:
    45
    Likes:
    0
    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?

    Code (c):


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


    typedef enum
    {
        UITimerSetting,
                Timer1,
                Timer2,
                Timer3,
                Timer4,
                Timer5,
                Timer6,
                Timer7,
                Timer8,
    }TimerModes;
     
     
    Last edited: Oct 2, 2017
  14. TucsonDon

    TucsonDon Member

    Joined:
    Sep 4, 2016
    Messages:
    45
    Likes:
    0
    With what I posted above how do I go from the main menu to a sub-menu?
     
  15. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
    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..
     

Share This Page