Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Menu on LCD with pic how to?

Status
Not open for further replies.
This is should be very easy to do and create
But what do you know about pics and LCD
what language do you want to use picbasic ASM or c
 

Hi Wizpic,

I´m begining but i have a little knowledge on pic and lcd, i already made many projects with this microcontrollers family, i program in assembler and i´m also learning C , but I am geting hard to make this menu with some sub-menus inside.
It would be something like this.

Main menu

Function 1
config x
config y

Function 2
check y
check x

Function 3
...
...

Thank you again
Elson
 

About the LCD coding I can suggest to you to take a look at this post:



Bye
Pow
 

Hi
Creating a menu is fairly easy. Create an array of menu structs (record). The struct should look something like this:

typedef struct
{
char LcdString[20]; // what to display
char MenuIndex[2]; // Contains index of 'sub' menu - 0 if no sub menu
char Size[2]; // Indicates how many entries in this menu section - Only top of each menu has value - others = 0
.....other variables as required
}MenuRec_t;



If up or down arrow pressed move to next/previous record. If enter pressed jump to sub menu @ index. The other variables could be passed to a switch / case statement to determine what should happen if this menu entry is selected. Obviously there is quite a bit that I have not explained but this should give you an idea how to get started
 
You can try by implementing a FSM (Finite State Machine) trough the use of switch statement. In order to help the code writing draw the menu structure and identify each menu with a state.
To gain more info on the subject take a look at this link:

https://en.wikipedia.org/wiki/Finite_state_machine

There are also automatic tool able to generate the C code from a visual view of the FSM, to give you an example look at the attached menu structure, the generated code will be this one (from HFSM Editor a free FSM code generator
https://robertolanuza.tripod.com/fsm/fsm.htm).
Into the example below I've supposed to use arrow key to navigate trough the menu structure and ok to execute a selected menu option.

Code:
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//  Automatic generated C-code by the application:
//     HFSM Editor v1.4r3
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Methodology: Hierarchical Switch-case state. [v1.5r1]
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Exported function: void FSM_0001(void);
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Initialization proposed by the user (Start).
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  key == left

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Initialization proposed by the user (End).
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Entry flags (Start).
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Entry flags (End).
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Automatic initialization (Start).
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 // States index.
  #define  i_STATE_1   ((T_u8)0)
  #define  i_STATE_2   ((T_u8)1)
  #define  i_STATE_21  ((T_u8)2)
  #define  i_STATE_22  ((T_u8)3)
  #define  i_STATE_3   ((T_u8)4)
  #define  i_STATE_31  ((T_u8)5)
  #define  i_STATE_32  ((T_u8)6)

 // Index variable.
static T_u8 ind_FSM_0001 = i_STATE_1;

// Macros & functions.
// Force the FSM to the initial state.
#define FSM_0001_Init() { ind_FSM_0001 = i_STATE_1; }

// This is not a history FSM.
#define _FSM_0001_Init()  {FSM_0001_Init(); /* Children: */ }

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Automatic initialization (End).
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Local child functions  (Start).
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Local child functions  (End).
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// FSM dispatcher function to be called by the O.S.
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void FSM_0001(void)
{
    // Next state analyser.
    switch(ind_FSM_0001){
        case i_STATE_1:
            // State actions (Moore).
            WriteLCD("Welcome!");
            // Next state selection.
            if(key == down){
                // Pointing to the next state.
                ind_FSM_0001 = i_STATE_2;
            }
        break;
        case i_STATE_2:
            // State actions (Moore).
            WriteLCD("Menu1");
            // Next state selection.
            if(key == up){	// [1].
                // Pointing to the next state.
                ind_FSM_0001 = i_STATE_1;
            }else if(key == right){	// [2].
                // Pointing to the next state.
                ind_FSM_0001 = i_STATE_21;
            }else if(key == down){	// [3].
                // Pointing to the next state.
                ind_FSM_0001 = i_STATE_3;
            }
        break;
        case i_STATE_21:
            // State actions (Moore).
            WriteLCD("Submenu 1");
            // Next state selection.
            if(key == left){	// [1].
                // Pointing to the next state.
                ind_FSM_0001 = i_STATE_2;
            }else if(key == ok){	// [2].
                // Pointing to the next state.
                ind_FSM_0001 = i_STATE_22;
            }
        break;
        case i_STATE_22:
            // State actions (Moore).
            ExecuteSubMenu1();
            // Next state selection.
            {
                // Pointing to the next state.
                ind_FSM_0001 = i_STATE_1;
            }
        break;
        case i_STATE_3:
            // State actions (Moore).
            WriteLCD("Menu2");
            // Next state selection.
            if(key == up){	// [1].
                // Pointing to the next state.
                ind_FSM_0001 = i_STATE_2;
            }else if(key == down){	// [2].
                // Pointing to the next state.
                ind_FSM_0001 = i_STATE_1;
            }else if(key == right){	// [3].
                // Pointing to the next state.
                ind_FSM_0001 = i_STATE_31;
            }
        break;
        case i_STATE_31:
            // State actions (Moore).
            WriteLCD("Submenu 2");
            // Next state selection.
            if(key == left){	// [1].
                // Pointing to the next state.
                ind_FSM_0001 = i_STATE_3;
            }else if(key == ok){	// [2].
                // Pointing to the next state.
                ind_FSM_0001 = i_STATE_32;
            }
        break;
        case i_STATE_32:
            // State actions (Moore).
            ExecuteSubmenu2();
            // Next state selection.
            {
                // Pointing to the next state.
                ind_FSM_0001 = i_STATE_1;
            }
        break;
    }
}


//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Ending code proposed by the user (Start).
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Ending code proposed by the user (End).
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//  End of the automatic generated C-code.
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

With very little modification you can immediatly use the code inside your program in order to setup this simple menu.

Hope it help.

Bye
Pow
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top