Simple LCD Menu Main Page
Inhaltsverzeichnis
Overview
This is a menu system for standard alphanumerical LC-displays.
To navigate through the menu, only 3 buttons are needed: Forward, Backward and Menu/Enter (or a rotary encoder with push button).
You can make multiple nested sub-menus, hidden menus (not supported by the designer yet), function calls and display or edit different value types (Bit, Byte, Word, Integer, Single, String).
The menu structure and associated data is stored in arrays at runtime, the structure is made by connecting the right entries together (with their array indexes).
Numerical values are displayed both as value and as a bargraph showing the current position in the specified range.
Bit values can be set to On/Off (or another custom text), numerical values will be increased/decreased by the specified step size and string values can be edited using a custom set of characters (and two special characters for backspace/enter). Read-Only values just show the content of a variable.
To save program space, just the pieces of code you use are compiled. You get the smallest size if you just use Links and Function Calls, it will increase if you use values (read-only, editable or both) and for each data type used.
How to use it
Setup
Include the menu structure created with the designer and the menu functions:
Macro Menu_include_data $include "inc\menu_data.bas" End Macro $include "inc\menu.bas"
Dimension used Variables
Between the function include and the initialisation you have to dimension the variables used to display or edit in the menu:
Dim Test_bit As Byte Dim Test_byte As Byte Dim Test_word As Word Dim Test_integer As Integer Dim Test_dword As Dword Dim Test_long As Long Dim Test_single As Single Dim Test_double As Double Dim Test_string As String * Menu_value_string_width
Bit data types have to be defined as a byte. Note that a constant was created containing the maximum string size.
Initialisation
Menu_init
Main Loop
Do If Switch_minus = 1 Then Menu_backward() ' back button pressed If Switch_plus = 1 Then Menu_forward() ' forward button pressed If Switch_enter = 1 Then ' enter button pressed Select Case Menu_enter() Case Menu_exit: ' Exit entry selected ... Case 2-255: ' Function call ... End Select End If Menu ' Main function ... Loop
Interface description
Const Menu_default_entry
ID of the default entry
Const Menu_value_string_width
size for strings used to display
Macro Menu_init
loads the menu data
Declare Sub Menu()
Main function, called in Main Loop
Declare Sub Menu_forward()
Goes one step forward in the menu or while in edit mode, bit values are set to true, numerical values are increased by the step size and for strings, the following character in the table will be selected.
Declare Sub Menu_backward()
Goes one step backward in the menu or while in edit mode, bit values are set to false, numerical values are decreased by the step size and for strings, the preceeding character in the table will be selected.
Declare Function Menu_enter() As Byte
Shows the menu if inactive, follows a link, enters/exits the edit mode, adds a character in string edit mode or selects a function
Declare Sub Menu_show(byval Entry_id As Byte)
Displays the menu with the provided entry id, if 0, the default entry is selected
Declare Sub Menu_hide()
hides the menu