BasicMicroUK - Forums

www.basicmicro.co.uk
It is currently Mon Jan 22, 2018 1:25 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: how to use the if, goto, then command
PostPosted: Sun Jul 28, 2013 11:46 am 
Offline
Guru

Joined: Sat Mar 30, 2013 10:19 pm
Posts: 51
hi all, as a new programmer im trying to get my head around using the if, goto, then, else command. I have three switches which on presses goto 3 lcd menus all starting from a main menu. What id like to do is, after entering one of the 3 menus if there is no action return to the main menu.
So... if 'no button press after 10 sec' goto 'main menu'. Any suggestions or sample code would be great. thanks in advance


Top
 Profile  
 
 Post subject: Re: how to use the if, goto, then command
PostPosted: Sun Jul 28, 2013 4:51 pm 
Offline
Master

Joined: Wed Oct 19, 2011 2:28 am
Posts: 123
Hi,
Attached it is a program that will read 3 ports and go to the selected LCD when you press the any switch. It's does not wait for 10 sec but as requested. Remember if you stayed too long in the subroutine the micro will stop other task. The best way it is select it when you want or like this:

Code:
main
program 1
program 2
gosub read switch routine
program 3
goto main

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
main
gosub read_switch_sub
goto main

'************************Program subroutines*************************
read_switch_sub
   if IN0 = 1 then
         gosub lcd_1_sub
   elseif IN1 = 1
         gosub lcd_2_sub   
   elseif IN2 = 1   
         gosub lcd_3_sub         
   endif      
return   
'*******************************************************************
lcd_1_sub
serout s_out ,i9600,["LCD 1 selected ",13]
return
'********************************************************************
lcd_2_sub
serout s_out ,i9600,["LCD 2 selected ",13]
return
'*******************************************************************
lcd_3_sub
serout s_out ,i9600,["LCD 3 selected ",13]
return         
'********************************************************************


Top
 Profile  
 
 Post subject: Re: how to use the if, goto, then command
PostPosted: Tue Mar 10, 2015 6:20 am 
Offline
Master

Joined: Wed Oct 19, 2011 2:28 am
Posts: 123
Hi,
If I understood what you want whta you need to do it is add the following if statement at the beginning or emmediatly you enter the the lcd subroutine.
'*******************************************************************
lcd_1_sub
if INO<> 1 then return <----------------------------------- it will return immediately
}
}
serout s_out ,i9600,["LCD 1 selected ",13]
return
'********************************************************************
lcd_2_sub
if IN1<> 1 then return <----------------------------------- it will return immediately
)
)
serout s_out ,i9600,["LCD 2 selected ",13]
return
'*******************************************************************
lcd_3_sub
if IN2 <> 1 then return <----------------------------------- it will return immediately
))
serout s_out ,i9600,["LCD 3 selected ",13]
return
'********************************************************************


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO