LCD Menu Sample 1: Unterschied zwischen den Versionen
Aus ProjectWiki
| Mat (Diskussion | Beiträge) | Mat (Diskussion | Beiträge)  | ||
| Zeile 4: | Zeile 4: | ||
| == Menu structure == | == Menu structure == | ||
| [[File:Menu_structure_simple.jpg]] | [[File:Menu_structure_simple.jpg]] | ||
| + | |||
| + | == Main file == | ||
| + | <pre>$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 = 1                                           ' # of software timers to use | ||
| + | $include "inc\tickers.bas" | ||
| + | Const Timer_readswitches = 1 | ||
| + | |||
| + | |||
| + | '############################################################################### | ||
| + | '##      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_simple.bas" | ||
| + | End Macro | ||
| + | $include "inc\menu.bas" | ||
| + | |||
| + | |||
| + | '############################################################################### | ||
| + | '##      V A R I A B L E S                                                    ## | ||
| + | '############################################################################### | ||
| + | Dim Tempbyte As Byte | ||
| + | |||
| + | |||
| + | '############################################################################### | ||
| + | '##      I N I T                                                              ## | ||
| + | '############################################################################### | ||
| + | Encoder_switch_old = Encoder_switch | ||
| + | |||
| + | Ticker_time(timer_readswitches) = 20 | ||
| + | Ticker_enabled(timer_readswitches) = 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 | ||
| + | |||
| + |          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 | ||
| + | |||
| + |    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 1" | ||
| + | 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</pre> | ||
| == Menu data include file == | == Menu data include file == | ||
| Zeile 87: | Zeile 218: | ||
| ###DESIGNER_END### | ###DESIGNER_END### | ||
| ')</pre> | ')</pre> | ||
| − | |||
| − | |||
Version vom 3. Juli 2011, 07:38 Uhr
This sample demonstrates the basic functions of the menu. It also uses the software timer library, but that's not necessary for the menu.
Menu structure
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 = 1                                           ' # of software timers to use
$include "inc\tickers.bas"
Const Timer_readswitches = 1
'###############################################################################
'##      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_simple.bas"
End Macro
$include "inc\menu.bas"
'###############################################################################
'##      V A R I A B L E S                                                    ##
'###############################################################################
Dim Tempbyte As Byte
'###############################################################################
'##      I N I T                                                              ##
'###############################################################################
Encoder_switch_old = Encoder_switch
Ticker_time(timer_readswitches) = 20
Ticker_enabled(timer_readswitches) = 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
         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
   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 1"
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 = 9
Const Menu_default_entry = 1
Const Menu_values_use = True
Const Menu_values_edit_use = False
Const Menu_values_count = 1
Const Menu_value_bit_count = 0
Const Menu_value_byte_count = 0
Const Menu_value_word_count = 0
Const Menu_value_integer_count = 0
Const Menu_value_dword_count = 0
Const Menu_value_long_count = 0
Const Menu_value_single_count = 0
Const Menu_value_double_count = 0
Const Menu_value_string_count = 1
Goto Menu_data_jumpover
Menu_entries:
   ' Type, Text ID, Before, Next, Child
   Data Menu_link , 0 , 7 , 2 , 4                           ' 1, Submenu
   Data Menu_value , 5 , 1 , 3 , 1                          ' 2, Another Entry
   Data Menu_link , 6 , 2 , 7 , 3                           ' 3, 3rd Entry
   Data Menu_link , 1 , 6 , 5 , 2                           ' 4, Sub-Entry 1
   Data Menu_link , 2 , 4 , 6 , 8                           ' 5, Submenu 2
   Data Menu_link , 4 , 5 , 4 , 1                           ' 6, {127} Back
   Data Menu_exit , 7 , 3 , 1 , 0                           ' 7, {127} Exit
   Data Menu_link , 3 , 9 , 9 , 4                           ' 8, Entry
   Data Menu_link , 4 , 8 , 8 , 5                           ' 9, {127} Back
Menu_string_constants:
   Data "Submenu"                                           ' 0
   Data "Sub-Entry 1"                                       ' 1
   Data "Submenu 2"                                         ' 2
   Data "Entry"                                             ' 3
   Data "{127} Back"                                        ' 4
   Data "Another Entry"                                     ' 5
   Data "3rd Entry"                                         ' 6
   Data "{127} Exit"                                        ' 7
Menu_values:
   ' Type, Value Child, Step/ReadOnly (if 0), Min, Max, [Init value]
   Data Menu_value_string , 1 , 0                           ' 1, Another Entry
Macro Menu_varpointers
   Menu_value_varpointer(1) = Varptr(test_string)           ' Another Entry, entry: 2, value: 1
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
b77fffd307070f7fe3e4cb25fdfffc9c5fd9e17fbfc897ebe7c5f2ed6f9cbc5e4f16f4c76f9cecf3
17fb9defb64f976d7d9dd2377bfcfdfdc8bb297d75c05f1df8dff29b0c91be7928df3cc9a6f4cd2f
dedd7bf04b52f9fd3e83fd74e86bc1784fbefec9ac5ce734ea65d5cef33ad50ef8d3d76d5d2c2fb8
f19bbc697fff46ff7e53e30d8172cfc7ee5e3d3300eef1b70fe4dbd377456b5090dfe9bb1ffff11f
3ffdf219fdfb1b27
###DESIGNER_END###
')

