LCD Menu Sample 1: Unterschied zwischen den Versionen

Aus ProjectWiki
Wechseln zu:Navigation, Suche
(Created page with "This sample shows all functions of the menu. It also uses the software timer library, but that's not necessary for the menu. === Menu stru...")
(kein Unterschied)

Version vom 3. Juli 2011, 07:13 Uhr

This sample shows all functions of the menu. It also uses the software timer library, but that's not necessary for the menu.

Menu structure

Menu structure full.jpg

Main file

$regfile = "m32def.dat"
$crystal = 16000000
$baud = 57600

$hwstack = 64
$swstack = 48
$framesize = 64

Const False = 0 : Const True = 1


'###############################################################################
'##      R O T A R Y   E N C O D E R                                          ##
'###############################################################################
Encoder_a Alias Pinb.1
Encoder_switch Alias Pind.6
Portb.1 = True                                              ' pullup encoder a,
Portb.2 = True                                              ' encoder b,
Portd.6 = True                                              ' and encoder switch
Config Int2 = Falling                                       ' encoder b is the interrupt source
On Int2 Encoder_isr
Enable Int2
Dim Encoder_switch_old As Bit
Dim Encoder_turn_left As Byte , Encoder_turn_right As Byte


'###############################################################################
'##      T I M E R                                                            ##
'###############################################################################
Const Ticker_hwtimer = 0                                    ' Choose which hardware timer to use
Const Ticker_frequency = 1000                               ' set the timer resolution
Const Tickers = 2                                           ' # of software timers to use
$include "inc\tickers.bas"
Const Timer_readswitches = 1
Const Timer_valueupdate = 2


'###############################################################################
'##      L C D                                                                ##
'###############################################################################
Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Portc.4 , Db5 = Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 , E = Portc.2 , Rs = Portc.3


'###############################################################################
'##      L C D   M E N U                                                      ##
'###############################################################################
Macro Menu_include_data
   ' include the data file created with the menu designer
   $include "inc\menu_data_all.bas"
End Macro
$include "inc\menu.bas"


'###############################################################################
'##      V A R I A B L E S                                                    ##
'###############################################################################
' Declare the variables associated with the menu values
Dim Test_bit As Byte                                        ' bit values have to be declared as byte
Dim Test_byte As Byte
Dim Test_byte_counting 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         ' max string length is stored in a constant

Dim Tempbyte As Byte


'###############################################################################
'##      I N I T                                                              ##
'###############################################################################
Encoder_switch_old = Encoder_switch

Ticker_time(timer_readswitches) = 20
Ticker_enabled(timer_readswitches) = True
Ticker_time(timer_valueupdate) = 500
Ticker_enabled(timer_valueupdate) = True

Menu_init

Enable Interrupts
Gosub Draw_homescreen


'###############################################################################
'##      M A I N   L O O P                                                    ##
'###############################################################################
Do
   ' one function to rule them all
   Menu

   Select Case Ticker_get_interrupt()
   Case Timer_readswitches:
      ' encoder switch pressed?
      If Encoder_switch = True And Encoder_switch_old = False Then
         Tempbyte = Menu_enter()
         Select Case Tempbyte
         Case Menu_exit:                                    ' menu closed
            Gosub Draw_homescreen

         Case 2:
            ' function 2 execute
            Cls                                             ' show something on the LCD
            Locate 1 , 2
            Lcd "Function call"
            Locate 2 , 2
            Lcd "demonstration"
            Wait 2
            Test_string = "Executed"                        ' assign the byte variable with a value
            Menu_show 24                                    ' and display it throuth the read-only byte menu entry
         End Select
      End If

      ' encoder turns left
      If 0 < Encoder_turn_left Then
         Decr Encoder_turn_left
         Menu_backward
      End If

      ' encoder turns right
      If 0 < Encoder_turn_right Then
         Decr Encoder_turn_right
         Menu_forward
      End If
      Encoder_switch_old = Encoder_switch

   Case Timer_valueupdate
      ' force the read-only value currently displayed to update
      Menu_check_update

      Incr Test_byte_counting                               ' changing value to demonstrate read-only values
      If Test_byte_counting = 101 Then Test_byte_counting = 0

   End Select
Loop


'###############################################################################
'##      S U B R O U T I N E S                                                ##
'###############################################################################
Draw_homescreen:
   Cls
   Cursor Off
   Locate 1 , 1
   Lcd "  LCD MENU 1.1"
   Locate 2 , 1
   Lcd "    Sample 2"
Return

Encoder_isr:
   ' to use with a rotary encoder
   If Encoder_a = False Then
      Incr Encoder_turn_right
   Else
      Incr Encoder_turn_left
   End If
Return

Menu data include file

$nocompile

Const Lcd_width = 16
Const Lcd_bar_style = 1
Const Lcd_bit_display_off = "Off"
Const Lcd_bit_display_on = "On"

Const Menu_entries_count = 25
Const Menu_default_entry = 1

Const Menu_values_use = True
Const Menu_values_edit_use = True
Const Menu_values_count = 18
Const Menu_value_bit_count = 2
Const Menu_value_byte_count = 2
Const Menu_value_word_count = 2
Const Menu_value_integer_count = 2
Const Menu_value_dword_count = 2
Const Menu_value_long_count = 2
Const Menu_value_single_count = 2
Const Menu_value_double_count = 2
Const Menu_value_string_count = 2

Goto Menu_data_jumpover

Menu_entries:
   ' Type, Text ID, Before, Next, Child
   Data Menu_link , 0 , 5 , 2 , 24                          ' 1, Link
   Data Menu_link , 1 , 1 , 3 , 6                           ' 2, Editable
   Data Menu_link , 12 , 2 , 4 , 16                         ' 3, Read Only
   Data Menu_function , 13 , 3 , 5 , 2                      ' 4, Function
   Data Menu_exit , 14 , 4 , 1 , 0                          ' 5, {127} Exit
   Data Menu_value , 2 , 15 , 7 , 1                         ' 6, Bit
   Data Menu_value , 3 , 6 , 8 , 2                          ' 7, Byte
   Data Menu_value , 4 , 7 , 9 , 3                          ' 8, Word
   Data Menu_value , 5 , 8 , 10 , 4                         ' 9, Integer
   Data Menu_value , 6 , 9 , 11 , 5                         ' 10, DWord
   Data Menu_value , 7 , 10 , 12 , 6                        ' 11, Long
   Data Menu_value , 8 , 11 , 13 , 7                        ' 12, Single
   Data Menu_value , 9 , 12 , 14 , 8                        ' 13, Double
   Data Menu_value , 10 , 13 , 15 , 9                       ' 14, String
   Data Menu_link , 11 , 14 , 6 , 2                         ' 15, {127} Back
   Data Menu_value , 2 , 25 , 17 , 10                       ' 16, Bit, read only
   Data Menu_value , 3 , 16 , 18 , 11                       ' 17, Byte, read only
   Data Menu_value , 4 , 17 , 19 , 12                       ' 18, Word, read only
   Data Menu_value , 5 , 18 , 20 , 13                       ' 19, Integer, read only
   Data Menu_value , 6 , 19 , 21 , 14                       ' 20, DWord, read only
   Data Menu_value , 7 , 20 , 22 , 15                       ' 21, Long, read only
   Data Menu_value , 8 , 21 , 23 , 16                       ' 22, Single, read only
   Data Menu_value , 9 , 22 , 24 , 17                       ' 23, Double, read only
   Data Menu_value , 10 , 23 , 25 , 18                      ' 24, String, read only
   Data Menu_link , 11 , 24 , 16 , 3                        ' 25, {127} Back

Menu_string_constants:
   Data "Link"                                              ' 0
   Data "Editable"                                          ' 1
   Data "Bit"                                               ' 2
   Data "Byte"                                              ' 3
   Data "Word"                                              ' 4
   Data "Integer"                                           ' 5
   Data "DWord"                                             ' 6
   Data "Long"                                              ' 7
   Data "Single"                                            ' 8
   Data "Double"                                            ' 9
   Data "String"                                            ' 10
   Data "{127} Back"                                        ' 11
   Data "Read Only"                                         ' 12
   Data "Function"                                          ' 13
   Data "{127} Exit"                                        ' 14

Menu_values:
   ' Type, Value Child, Step/ReadOnly (if 0), Min, Max, [Init value]
   Data Menu_value_bit , 1 , 1 , False                      ' 1, Bit
   Data Menu_value_byte , 1 , 2 , 0 , 100 , 50              ' 2, Byte
   Data Menu_value_word , 1 , 64% , 0% , 1024% , 0%         ' 3, Word
   Data Menu_value_integer , 1 , 1% , -5% , 5% , 0%         ' 4, Integer
   Data Menu_value_dword , 1 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0       ' 5, DWord
   Data Menu_value_long , 1 , 1& , 0& , 10& , 0&            ' 6, Long
   Data Menu_value_single , 1 , 0.25! , -2.5! , 2.5! , 0!   ' 7, Single
   Data Menu_value_double , 1 , 3.14159# , -31.4159# , 31.4159# , 0#       ' 8, Double
   Data Menu_value_string , 1 , 1 , "Hello World"           ' 9, String
   Data Menu_value_bit , 2 , 0                              ' 10, Bit, read only
   Data Menu_value_byte , 2 , 0 , 0 , 100                   ' 11, Byte, read only
   Data Menu_value_word , 2 , 0% , 0% , 1024%               ' 12, Word, read only
   Data Menu_value_integer , 2 , 0% , -5% , 5%              ' 13, Integer, read only
   Data Menu_value_dword , 2 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 10 , 0 , 0 , 0       ' 14, DWord, read only
   Data Menu_value_long , 2 , 0& , 0& , 10&                 ' 15, Long, read only
   Data Menu_value_single , 2 , 0! , -2.5! , 2.5!           ' 16, Single, read only
   Data Menu_value_double , 2 , 0# , -31.4159# , 31.4159#   ' 17, Double, read only
   Data Menu_value_string , 2 , 0                           ' 18, String, read only

Macro Menu_varpointers
   Menu_value_varpointer(1) = Varptr(test_bit)              ' Bit, entry: 6, value: 1
   Menu_value_varpointer(2) = Varptr(test_byte)             ' Byte, entry: 7, value: 1
   Menu_value_varpointer(3) = Varptr(test_word)             ' Word, entry: 8, value: 1
   Menu_value_varpointer(4) = Varptr(test_integer)          ' Integer, entry: 9, value: 1
   Menu_value_varpointer(5) = Varptr(test_dword)            ' DWord, entry: 10, value: 1
   Menu_value_varpointer(6) = Varptr(test_long)             ' Long, entry: 11, value: 1
   Menu_value_varpointer(7) = Varptr(test_single)           ' Single, entry: 12, value: 1
   Menu_value_varpointer(8) = Varptr(test_double)           ' Double, entry: 13, value: 1
   Menu_value_varpointer(9) = Varptr(test_string)           ' String, entry: 14, value: 1
   Menu_value_varpointer(10) = Varptr(test_bit)             ' Bit, entry: 16, value: 2
   Menu_value_varpointer(11) = Varptr(test_byte)            ' Byte, entry: 17, value: 2
   Menu_value_varpointer(12) = Varptr(test_word)            ' Word, entry: 18, value: 2
   Menu_value_varpointer(13) = Varptr(test_integer)         ' Integer, entry: 19, value: 2
   Menu_value_varpointer(14) = Varptr(test_dword)           ' DWord, entry: 20, value: 2
   Menu_value_varpointer(15) = Varptr(test_long)            ' Long, entry: 21, value: 2
   Menu_value_varpointer(16) = Varptr(test_single)          ' Single, entry: 22, value: 2
   Menu_value_varpointer(17) = Varptr(test_double)          ' Double, entry: 23, value: 2
   Menu_value_varpointer(18) = Varptr(test_string)          ' String, entry: 24, value: 2
End Macro

Menu_string_characters:
   ' Table of characters used in string editing
   Data 254                                                 ' start of table, needed

   Data "ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789"

   ' special characters with function, these are needed
   Data Menu_character_backspace                            ' backspace
   Data Menu_character_finish                               ' finish string editing
   Data 254                                                 ' end of table

Menu_data_jumpover:

'(
###DESIGNER###
1f8b0800000000000400ecbd07601c499625262f6dca7b7f4af54ad7e074a10880601324d8904010
ecc188cde692ec1d69472329ab2a81ca6556655d661640cced9dbcf7de7befbdf7de7befbdf7ba3b
9d4e27f7dfff3f5c6664016cf6ce4adac99e2180aac81f3f7e7c1f3f22fec7bff71fdcfdf4374e76
7fe3e4f8c9c9d3d3679f7ffbec3bbfd7f32f5e7cf9f2275ebd7ef3d54f7ef7f7fe7d7e2addd9ddbb
b77fffd307070f7fe3e4cb25fdfffc9c5fd9e17fbfc897ebe7c5f2ed6f9cc8bf7bfbfccd9effcde9
ac68b34999ffc6c9a7fccda7f2e54f66e59a3e7b52b4bf71c2bff36fcfb2b2a14fdfe44dfbfb4fbc
0f76f9d507e1abd76d6edee55fefef9837f94f7d1598ee0852f2bf8300ca77ab7aa650e45703e48a
fff28160749fd2ffef3198870198b3659b5fe4b542b27f196085f940e16ddf27747958fb0c6c7727
80f6d4c34a7f3790667dbc18ce7d81a393a2709e57cb0b0523bf1a2825ffd5032233b4abf3a7405e
17cb0b4c1fff69fe30801afddb8c6b6f0c44f0cfce78ef3e4f1920de0b8757ad2716a2f9c30e50ff
3610efed8ef777ef13b5dd2fe35df9e54080ef87e8b67561476dfef8765e96554a942c670671fd46
bb7928a0ee0ba827d99438f717efee3df825a9fcbec708ea3084b15fe5d92cfd72595ed37b9ff277
bbefc7db6f6ab4da15b8bb373077c8dbf2aa616dfcdc1528efc5dc6f1c14955c4c3dc07c3de616ac
94b701ed9e08cbfb32b7373af9a142f75eccdd03725f80dc86b9c75df6d69179dc6d277def36bc6d
011aee56807de606e00702f8167cedf394e16865ab0301727f88a3ef715fdac7b3f572da16152978
f79bb0bcbe7ffa0e1c2befcbeff4dd8ffff88f9f7ef98cfefd8d
###DESIGNER_END###
')