Sticking Loop Mystery
coryco2
Posts: 107
I am greatly perplexed after writing what I thought was a simple bit of code to cycle through a series of items on an LCD display when a button is pushed. For some reason, the code will function for a while (depending on the delay length in the loop), then freeze randomly while running one of the display methods. The crash seems to occur after a set time, not necessarily at any point in the code. Also, sometimes (if the delay is commented out, for example), the LCD backlight will go out as well or it will display garbage characters, and/or the Prop will spontaneously restart. The Prop seems to work just fine if I load other code into it, though, so there's got to be bug somewhere in here:
I would very much appreciate if anyone could shed some light on this for me.
CON _clkmode = xtal1 + pll16x ' System clock settings _xinfreq = 5_000_000 LCDBasePin = 17 OBJ LCD: "BenkyLCDdriver" 'Declare LCD display driver VAR BYTE MenuLevel LONG maxT ' Variable used by LCD driver PUB Start LCD_DisplayInit PUB LCD_DisplayInit LCD.start( LCDBasePin,0 ) ' Start LCD Display DIRA[16]~~ ' Set pin 16 "high" to turn on backlight OUTA[16]~~ maxT:=LCD.getMax waitcnt(clkfreq + cnt) ' Wait 1 s before starting MenuLevel:=1 'Resets to top of Main Menu MenuLoop PUB MenuLoop repeat waitcnt(((clkfreq/1000)*10) + cnt) 'Pause for specified number of millliseconds between loops if MenuLevel>2 or MenuLevel<1 'Stay in range of menu MenuLevel:=1 case MenuLevel 1: DisplayMenuItem1 2: DisplayMenuItem2 PUB DisplayMenuItem1 LCD.exec( LCD#CMD_INSTR, 000000 + $00) 'sets cursor position - see chart in BenkyLCDdriver LCD.exec( LCD#CMD_PRINT, string(" Menu Item: ") ) LCD.exec( LCD#CMD_INSTR, 000000 + $40) 'sets cursor position - see chart in BenkyLCDdriver LCD.exec( LCD#CMD_PRINT, string(" Number 1 ") ) repeat if ina[15]==1 ' Check button ++MenuLevel ' Add one to MenuLevel MenuLoop PUB DisplayMenuItem2 LCD.exec( LCD#CMD_INSTR, 000000 + $00) 'sets cursor position - see chart in BenkyLCDdriver LCD.exec( LCD#CMD_PRINT, string(" Menu Item: ") ) LCD.exec( LCD#CMD_INSTR, 000000 + $40) 'sets cursor position - see chart in BenkyLCDdriver LCD.exec( LCD#CMD_PRINT, string(" Number 2 ") ) repeat if ina[15]==1 ' Check button ++MenuLevel ' Add one to MenuLevel MenuLoop
I would very much appreciate if anyone could shed some light on this for me.
Comments
-Phil
Thanks for the help!