BasicMicroUK - Forums

www.basicmicro.co.uk
It is currently Tue Oct 23, 2018 9:02 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Do...While question
PostPosted: Mon Aug 23, 2010 5:39 pm 
Offline
Citizen

Joined: Wed Aug 20, 2008 5:57 pm
Posts: 27
Do While used to work just fine under M Basic in a 16F887. I ported the code to the Nano 40 and even though it compiles just fine, it doesn't run. A search of the forums doesn't find any reference to anyone using Do While.
I turn on a motor that moves a carriage to a home position. Once home, an optical sensor tells the nano40 to turn off the motor.

do
low p27 ;run the comp motor
while p28=0 ;wait for home switch
high p27 ;turn the motor off



Has anyone using Studio used Do..While ?
Pete


Top
 Profile  
 
 Post subject: Re: Do...While question
PostPosted: Mon Aug 23, 2010 8:35 pm 
Offline
Master

Joined: Mon Aug 18, 2008 1:26 am
Posts: 799
Location: CA bay Area
Try this:
Code:
State var bit
do
low p27 ;run the comp motor
State = IN28
while State=0 ;wait for home switch
high p27 ;turn the motor off


Studio doesn't seem to read P-pins directly, you have to use the IN(P#).
kenjj

_________________
kenjj
http://blog.basicmicro.com/
http://kjennejohn.wordpress.com/


Top
 Profile  
 
 Post subject: Re: Do...While question
PostPosted: Mon Aug 23, 2010 9:48 pm 
Offline
Citizen

Joined: Wed Aug 20, 2008 5:57 pm
Posts: 27
As usual, Ken, has the answer. I thought that might be the case but I didn't think about using IN.
It is working fine now.
Thanks
Pete


Top
 Profile  
 
 Post subject: Re: Do...While question
PostPosted: Tue Aug 24, 2010 5:13 pm 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 7:00 pm
Posts: 1316
Location: Temecula, CA
Just to point out no version of MBasic has ever read P pins. P pins are constant numbers that are only used with commands that take a pin number. So in effect you were waiting on a constant to change.

Also another way of writing your code. You don't need the intermediate variable. IN variables are variables.

Code:
do
   low p27 ;run the comp motor
while IN28=0 ;wait for home switch

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 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