Simple LCD Menu Main Page

Aus ProjectWiki
Wechseln zu:Navigation, Suche

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, DWord, Long, Single, Double, 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.

Watch this video to see it in action.

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

LCD Menu Designer

Global Settings

Global menu settings

When the first entry in the menu tree is selected, the global settings are visible. Here you can select the LCD character width, the visual style for the bargraph, edit the character table used in string edit mode and choose the texts to display for bit values (Default is On/Off, you can set it for example to Yes/No or High/Low etc.).

Link

Entry is a link, select the target

With links you can jump to another entry in the menu, just select it in the right menu tree. Submenu- and Back entries are also links, but the target is created automatically.

Value

Value settings

Select the variable type (all Bascom types are supported) and choose if the value should be editable or read-only. In the "Associated variable" field enter the Variable name you declared in your code. Then set the range of the value (lowest and highest possible value). If the value is editable, you further have to set its initial value (will be set in Menu_init) and, if its a numerical value, the step size (positive, > 0).

Function

Function ID select

Select a function ID between 2 and 255. When this entry is selected, the menu hides and the Menu()-function returns the ID.

Tool: Character Table

Tool: interactive LCD character table

With this little tool it is easy to get the corresponding code for characters supported by alphanumerical LCDs. Click on the desired character, the calculated code, formatted ready to use in Bascom strings, appears in the text field below.

Samples

Sample 1: Small menu

LCD Menu Sample 1

Sample 2: All functions

LCD Menu Sample 2

Download