Quantcast
Viewing all articles
Browse latest Browse all 20613

Share your working BASCOM-AVR code here : LCD menu with UI designer : REPLY

I've got an odd problem. I'd ordinarily post it in the general area but after stripping everything else away the only thing left is the menu. I'm guessing my ERAM variables are conflicting with how you handle ERAM. Below is code that shows the problem. It displays 2 variables from ERAM, then sets them. After rebooting, the variables should always be what they are set to, but they get corrupted. Any idea what I'm doing wrong? Thanks! [code:1:42e7fcc6c7] $programmer = 22 'ARDUINO (using stk500v1 protocol) $regfile = "m328pdef.dat" 'Set the AVR to use - ATMega328. $crystal = 16000000 'Set the AVR clock. ' $hwstack = 90 'Set the capacity of the hardware stack. $swstack = 90 'Set the capacity of the software stack. $framesize = 128 'Set the capacity of the frame area. '############################################################################### '## V A R I A B L E S T O S A V E T O E E P R O M ## '############################################################################### Dim SkipZeroE as Eram Byte ' This occupies Address zero. ' Dim AutoStart as Byte Dim Treatment_time as Byte Dim Vib_Intensity as Byte Dim JitterSetting as Word Dim HandMirror as Byte Dim ERM_LRA_Setting as String * 3 Dim OL_CL_Setting as String * 6 Dim Drive_Voltage as Single ' Even with the menu system, we need to save some variables to ERAM Dim ERM_LRA_SettingE as ERAM String * 3 Dim OL_CL_SettingE as ERAM String * 6 '############################################################################### '## D I M E N S I O N V A R I A B L E S ## '############################################################################### Dim MinuteTimer as Byte Dim SWVer as String * 5 Dim TreatmentActive as Bit ' If this is a 1, then we are actively doing treatment, or should be Dim LRA_Frequency as Word '############################################################################### '## S E T V A R I O U S V A R I A B L E S ## '############################################################################### SkipZeroE = 128 ' This isn't used, just to occupy a flaky part of EEPROM '############################################################################### '## C O N F I G U R E R O T A R Y E N C O D E R ## '############################################################################### Encoder_switch Alias PinC.2 Dim B As Byte Dim Encoder_switch_old As Bit Dim Encoder_turn_left As Byte , Encoder_turn_right As Byte PortC.0 = 1 ' pullup encoder a, PortC.1 = 1 ' pullup encoder b, PortC.2 = 1 ' pullup encoder switch Dim skip_flagL as byte ' This is used for this specific encoder. Otherwise, one notch registers as two! Dim skip_flagR as byte ' This is used for this specific encoder. Otherwise, one notch registers as two! '############################################################################### '## C O N F I G U R E M E N U T I M E R ## '############################################################################### Const Ticker_hwtimer = 2 ' Choose which hardware timer to use Const Ticker_frequency = 1000 ' set the timer resolution Const Tickers = 2 ' # of software timers to use $include "tickers.inc" Const Timer_readswitches = 1 Const Timer_valueupdate = 2 '############################################################################### '## C O N F I G U R E L C D ## '############################################################################### $lib "i2c_twi.lib" 'Incorporate the hardware I2C/TWI library. Config Twi = 100000 'I2C bus clock = 100KHz Config Scl = Portc.5 'You must specify the SCL pin name. Config Sda = Portc.4 'You must specify the SDA pin name. I2cinit 'Initialize the SCL and SDA lines of the I2C bus. Reset Watchdog Dim Pcf8574_lcd As Byte : Pcf8574_lcd = &H4E 'PCF8574 slave address. (&H40,&H42,&H44,&H46,&H48,&H4A,&H4C,&H4E) Dim Backlight As Byte : Backlight = 1 'LCD backlight control. (0: off, 1: on) $lib "lcd_i2c_PCF8574.LIB" 'Incorporate the library of I2C LCD PCF8574 Adapter. Config Lcd = 16x2 'Set the LCD to 16 characters and 2 lines. Initlcd 'Initialize the LCD. ' Temp Testing '-------------------------------------------------------------------------------- ' THIS is the section that highlights the problem ERM_LRA_Setting = ERM_LRA_SettingE OL_CL_Setting = OL_CL_SettingE CLS LCD "ERM/LRA:" ; ERM_LRA_Setting Lowerline LCD "OL/CL:"; OL_CL_Setting Waitms 800 ' Here we set these variables for testing. These should always be the same in ERAM but get corrupted OL_CL_Setting = "CLOSED" OL_CL_SettingE = OL_CL_Setting ERM_LRA_Setting = "LRA" ERM_LRA_SettingE = ERM_LRA_Setting '--------------------------------------------------------------------- '############################################################################### '## L C D M E N U ## '############################################################################### Macro Menu_include_data ' include the data file created with the menu designer $Include "C:UsersCharlesDesktopParkinsonsBASCOM CodeMenu Testmenu_srcPARKINSONS_menu_data3.inc" End Macro 'Include just the Menu.inc $include "C:UsersCharlesDesktopParkinsonsBASCOM CodeMenu Testmenu_srcmenu.inc" Dim Tempbyte As Byte '############################################################################### '## M E N U I N I T ## '############################################################################### Encoder_switch_old = Encoder_switch Ticker_time(timer_readswitches) = 20 ' 20 ms debounce Ticker_enabled(timer_readswitches) = True Ticker_time(timer_valueupdate) = 500 ' 500 ms read-only value update Ticker_enabled(timer_valueupdate) = True Menu_init ' We need to set our variables AFTER this ?????? '######################################################################################################## '## M A I N L O O P ## '######################################################################################################## MainLoop: Menu 'Reset Watchdog ' Here we handle the encoder B = Encoder(pinC.0 , PinC.1 , Left , Right , 0) WaitMS 1 ' Helps to debounce ' Here we select what to do with each menu choice 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_switch_old = Encoder_switch ' 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 ' ----------- Case Timer_valueupdate ' force the read-only value currently displayed to update Menu_check_update End Select Goto mainloop '*************************************************** '############################################################################### '## S U B R O U T I N E S ## '############################################################################### Draw_homescreen: ' Makesw the main screen. Varies depending on if treatment is going on 'If TreatmentActive = 1 Then ' If therapy is going on make a menu that shows minutes left ' CLS ' Cursor Off ' Locate 1 , 1 ' LCD "Minutes: " ; MinuteTimer ' If MinuteTimer > Treatment_time Then ' Here we check to see if treatment time is up. ' ' Gosub StopTreatment ' EndIf 'Else ' Cls ' Cursor Off ' Locate 1 , 1 ' Lcd " FreedomWavePD" ' Locate 2 , 1 ' LCD " Version " ; SWVer 'End If 'Return 'DrawOperationScreen: ' 'CLS 'LCD "17 Minutes to go" 'Lowerline 'LCD " FreedomWavePD" Return '-------------------------------------------------------- ' Handle the Rotary Encoder '-------------------------------------------------------- Left: If skip_flagL = 1 then skip_flagL = 0 Else Incr Encoder_turn_left skip_flagL = 1 End if Return Right: If skip_flagR = 1 then skip_flagR = 0 Else Incr Encoder_turn_right skip_flagR = 1 End if Return [/code:1:42e7fcc6c7]

Viewing all articles
Browse latest Browse all 20613

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>