Problem with WHILE - WEND


Closed Thread
Results 1 to 23 of 23

Hybrid View

  1. #1
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Wink

    First:
    Goto should not be used with "While" statement. Use "IF" instead.
    ex:
    Code:
    IF Footsw=1 or Ready=1 then Goto Start


    Second:
    Your statement should have been as below.
    Code:
    While Footsw=1 or Ready=1
    Goto start    'cant'be on the same line with While
    Wend
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  2. #2
    Join Date
    Jan 2006
    Location
    New Hampshire, USA
    Posts
    107


    Did you find this post helpful? Yes | No

    Default

    Thanks for the replies. I had tried IF - THEN but did not do that right either!

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    1. Parenthesis are important in most case
    2. I would never jump out of a WHILE statement using a GOTO. Using a flag or Validate the Conditions to get out of the WHILE/WEND loop is, IMHO, a better practice.

    Could be also..
    Code:
    Start:
        LOW RENCA
        LOW EJECT
        While (FootSw=1) OR (Ready=1) : WEND
    OR
    Code:
    Start:
        LOW RENCA
        LOW EJECT
        SpinHere: If (FootSw=1) OR (Ready=1) then SpinHere
    You may notice that one method generate less code space than the other.
    Last edited by mister_e; - 26th May 2006 at 13:10.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    Jan 2006
    Location
    New Hampshire, USA
    Posts
    107


    Did you find this post helpful? Yes | No

    Default

    Here is my problem: I tried the spinhere loop, it works but the following statements are a loop. I want the program to stay in the loop but as soon as either footsw or ready goes high, the program jumps back to the spinhere loop. I don't want it to do that. How do I do it?

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Code:
    SpinHere:
        LOW RENCA
        LOW Eject
        While (FootSw=0) OR (Ready=0)    
              '
              '    Do your loop here
              '
              wend
        goto Spinhere
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  6. #6
    Join Date
    Jan 2006
    Location
    New Hampshire, USA
    Posts
    107


    Did you find this post helpful? Yes | No

    Default

    I have not explained my problem properly: I want a momentary switch closure (footsw) to cause the program to jump to a loop (freq. I don't want it to jump out of the loop when the switch opens.

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Talking Cookbook available ???

    Hi, Steve

    Keep cool ... keep cool ...

    Alain

    Hi,Russ

    Could you explain EXACTLY what you want to do ...

    I mean : the switch closure lead to jump into the loop, OK ... but what happens if switch released ??? stay in the loop ??? go where ??? do you test your switch continuously after jumping off the loop ??? or just once at the beginning of your program ???

    We're not at school ... no one will copy your project !!!!

    Problem written is half the solution ....

    Alain
    Last edited by Acetronics2; - 26th May 2006 at 15:17.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  8. #8
    Join Date
    Jan 2006
    Location
    New Hampshire, USA
    Posts
    107


    Did you find this post helpful? Yes | No

    Default

    I want a momentary switch closure to jump to a loop and stay there, regardless of further action by the switch. Perhaps an interrupt is what I need? I don't exactly know how to do that, but will experiment. I prefer to use portb.5 for interrupt input, the data sheet says the RBIF flag will be set regardless of the state of the INTCON enable bit?

Similar Threads

  1. Can't read sequential addresses in external EEPROM
    By tjkelly in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th February 2010, 14:46
  2. HSEROUT and Commas, What? Help Me Understand
    By altech6983 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 20th July 2009, 19:12
  3. USART Problem , but don't know where, in pc? or in PIC?
    By precision in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th July 2007, 08:12
  4. while wend problem
    By Russ Kincaid in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 19th March 2007, 02:53
  5. 1 slave 1 master 1 MAX232 1 problem ?
    By SuB-ZeRo in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 31st July 2005, 22:59

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts