Selection menu

orjanjan

New Member
Hi

I have made a selection menu for my logging system. It works, but I think its a very long and ineffective program.
I'm pleased if anyone has comments on it on improvements.

Thanks

Code:
#slot 0


'This program is only the menu of my logging station. There are 5 menu items with Yes/No choice, and one with minute 0 -255.
'The menu states are written in bit 101 to 107. 
'After choices are made, it runs Slot1-3. Here i reed the bits, and run the programs with YES.


'########MENU########
'1-Clock
'2-Pressure
'3-Temp 1-4
'4-Humidity
'5-Light
'6-Interval
'7-Start


'########PINS########
'Display		b.5
'Open LOG write	a.1
'Open LOG read	
'LED			b.7
'Temp T0		c.5
'Temp T1		c.6
'Temp T2		c.7
'Temp T3		b.0
'Temp T4		b.1
'Botton1		b.4
'Botton2		b.3
'Botton3		b.2
'I2C SDA TXI?	c.4
'I2C SCL RXD?	c.3


'#######SYMBOLS######
symbol arrow_up=pinb.4 
symbol arrow_down=pinb.3
symbol ent=pinb.2
symbol prog=b0
symbol YN=b1


'#######START SCREEN#
serout b.5,T9600_8,(254,1)
serout b.5,T9600_8,(254, $01) 
serout b.5,T9600_8,("Select program")
serout b.5,T9600_8,(254,192)
serout b.5,T9600_8,("UP/DOWN or RET")

top:
if arrow_up=1 then goto run_program
if arrow_down=1 then goto clock
pause 100
goto top


'########MENU########
clock:
	pause 300
	prog=101
	serout b.5,T9600_8,(254,1)
	serout b.5,T9600_8,(254, $01) 	
	serout b.5,T9600_8,("Time and date")
		
	peek prog,YN
	gosub check
	
	clock_select:
	if arrow_up=1 then goto run_program
	if arrow_down=1 then goto pressure
	if ent=1 then gosub yes_no
	goto clock_select

pressure:
	pause 300
	prog=102
	serout b.5,T9600_8,(254,1)
	serout b.5,T9600_8,(254, $01) 	
	serout b.5,T9600_8,("Pressure")
		
	peek prog,YN
	gosub check
	
	pressure_select:
	if arrow_up=1 then goto clock
	if arrow_down=1 then goto temp1_4
	if ent=1 then gosub yes_no
	goto pressure_select

temp1_4:
	pause 300
	prog=103
	serout b.5,T9600_8,(254,1)
	serout b.5,T9600_8,(254, $01) 	
	serout b.5,T9600_8,("Temp 1-4")
		
	peek prog,YN
	gosub check
	
	temp1_4_select:
	if arrow_up=1 then goto pressure
	if arrow_down=1 then goto humid
	if ent=1 then gosub yes_no
	goto temp1_4_select

humid:
	pause 300
	prog=104
	serout b.5,T9600_8,(254,1)
	serout b.5,T9600_8,(254, $01) 	
	serout b.5,T9600_8,("Humid")
		
	peek prog,YN
	gosub check
	
	humid_select:
	if arrow_up=1 then goto temp1_4
	if arrow_down=1 then goto light
	if ent=1 then gosub yes_no
	goto humid_select

light:
	pause 300
	prog=105
	serout b.5,T9600_8,(254,1)
	serout b.5,T9600_8,(254, $01) 	
	serout b.5,T9600_8,("Light")
		
	peek prog,YN
	gosub check
	
	light_select:
	if arrow_up=1 then goto humid
	if arrow_down=1 then goto interval
	if ent=1 then gosub yes_no
	goto light_select

interval:
	pause 300
	prog=106
	serout b.5,T9600_8,(254,1)
	serout b.5,T9600_8,(254, $01) 	
	serout b.5,T9600_8,("Interval")
		
	peek prog,YN
	gosub check_int
	
	interval_select:
	if arrow_up=1 then goto light
	if arrow_down=1 then goto run_program
	if ent=1 then gosub int
	goto interval_select
	
run_program:
	pause 300
	prog=107
	serout b.5,T9600_8,(254,1)
	serout b.5,T9600_8,(254, $01) 	
	serout b.5,T9600_8,("Run_program")
			
	peek prog,YN
	gosub check
	
	run_program_select:
	if arrow_up=1 then goto pressure
	if arrow_down=1 then goto clock
	if ent=1 then goto Programs
	goto run_program_select


'#######SUBS####

yes_no:	'(change status YES/NO)
pause 300
peek prog,YN
branch YN,(yes,no)

	no:
	poke prog,0
	serout b.5,T9600_8,(254,192)
	serout b.5,T9600_8,("No ")
	return
	
	yes:
	poke prog,1
	serout b.5,T9600_8,(254,192)
	serout b.5,T9600_8,("Yes")
	return	

	
check:	'(check status YES/NO)
serout b.5,T9600_8,(254,192)
branch YN,(W_N,W_Y)
	
	W_N:
	serout b.5,T9600_8,("No ")
	return
	
	W_Y:
	serout b.5,T9600_8,("Yes")
	return


int:
	pause 200
	peek prog,YN
	YN=YN+1
	serout b.5,T9600_8,(254,1)
	serout b.5,T9600_8,(254, $01) 	
	serout b.5,T9600_8,("Interval")
	serout b.5,T9600_8,(254,192)
	serout b.5,T9600_8,("Every ",#YN,"min")
	poke prog,YN
	return


check_int:
	serout b.5,T9600_8,(254,192)
	serout b.5,T9600_8,("Every ",#YN,"min")
	return


'#########PROGRAMS###################################################

Programs:
run 1
 

Jamster

Senior Member
Does it work in real life? Looks good and provides a nice interface to me :)

I may have an idea to make it shorter but it'll take me a while, hang on :p
 

orjanjan

New Member
Hi

Yes it works in real life. But I want to short the program down. I think I have to use #Slot0 for logging program since #Slot 1-3 is soon full.
I use a pressure sensor that is 16bit and a lot of frational math. (This one I found on the forum). The pressure sensor program uses almost a whole Slot.
I also tend to program the clock so I can Select time interval, or count down. and also set start time for logging.

So shortening the programs would help a lot.

Ørjan
 

Jamster

Senior Member
Ok, here is how I would've programmed it if i'd been asked (I had nothing to do tonight :) ), It comes in at 443 bytes (yours being 673) so not a dramatic saving but reduces the repeated code a bit.

Code:
#slot 0

SYMBOL program  = b0
SYMBOL value = b1

SYMBOL arrow_up  = pinB.4
SYMBOL arrow_down = pinB.3
SYMBOl enter  = pinB.2
SYMBOL CLOCK  = 101
SYMBOL PRESSURE  = 102
SYMBOL TEMP  = 103
SYMBOL HUMIDITY  = 104
SYMBOL LIGHT  = 105
SYMBOL INTERVAL  = 106
SYMBOL START  = 107
SYMBOL YES  = 1
SYMBOL NO   = 0
program = CLOCK
'Start Screen
serout b.5,T9600_8,(254,1)
serout b.5,T9600_8,(254, $01) 
serout b.5,T9600_8,("Select program")
serout b.5,T9600_8,(254,192)
serout b.5,T9600_8,("UP/DOWN or RET")
do 
 'Setup LCD
 serout b.5,T9600_8,(254,1)
 serout b.5,T9600_8,(254, $01) 
 
 'Display text
 select program
 case 101
  serout b.5,T9600_8,("Time and date")
 case 102
  serout b.5,T9600_8,("Pressure")
 case 103
  serout b.5,T9600_8,("Temp 1-4")
 case 104
  serout b.5,T9600_8,("Humid")
 case 105
  serout b.5,T9600_8,("Light")
 case 106
  serout b.5,T9600_8,("Interval")
 case 107
  serout b.5,T9600_8,("Run")
 endselect 
 serout b.5,T9600_8,(254,192)
 'Get current value
 peek program,value
 'If we're on interval then display a different interface
 if program = INTERVAL then
  gosub int_interface
 elseif program = START then
  gosub but_interface
 else
  gosub tog_interface
 endif
 
 
 'Overflow program
 if program = 108 then
  program = CLOCK
 endif
 if program = 100 then
  program = START
 endif
loop 
but_interface:
 do 
  'Get user choice
  if arrow_up = 1 then inc program : return : endif
  if arrow_down = 1 then inc program : return : endif
  if enter = 1 then run 1  : endif
 loop
'OUR INTERFACE FOR NUMBER OPTIONS
int_interface:
 do
  'Display current value
  serout b.5,T9600_8,(#value)
 
  'Get user choice
  if arrow_up = 1 then inc program : return : endif
  if arrow_down = 1 then inc program : return : endif
  if enter = 1 then inc value : poke program,value : endif
 loop
return

'OUR INTERFACE FOR TOGGLE OPTIONS
tog_interface:
 'Display current state
 if value = YES then
  serout b.5,T9600_8,("Yes")
 else
  serout b.5,T9600_8,("NO")
 endif
 
 do 
  'Get user choice
  if arrow_up = 1 then inc program : return : endif
  if arrow_down = 1 then inc program : return : endif
  if enter = 1 then : gosub yntog: poke program,value : return : endif
 loop
 
 
'If alternate between yes/no
yntog:
 if value = YES then let value = NO else let value = YES endif
return
I've changed some variable names to fit with what I'm used to and I've added some upper case constanrts to make the seemingly random values make more sense.

Jamster :)
 

orjanjan

New Member
Hi

Nice :) There is some new code that i never used before. Like Case, Inc, Dec. And the program looks better now I think.

There was only some small changes that had to be made.

- Added pause to be able to control the menu.
- It was written Inc on arrow down. Changed to Dec
- Clear screen on interval. The numbers was written one after the other.
Small changes.

I learned a lot of new things here. I think when adding more choices on the menu, this program saves more memory than my program.

Thank you for your help.
 

Jamster

Senior Member
Sometimes the best way to learn is to disect other peoples code to see how they'd do it, and everyone will do it differently so there's plenty to learn from... :)

And of course I left those errors in on purpose :p

Jamster :)
 
Top