Simple question about While Wend...


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Oct 2008
    Posts
    52

    Default Simple question about While Wend...

    I have been trying for a while to get this simple code to work. Can someone tell me why it won't?

    Thanks, Don

    while porta.2 <> 0
    wend
    high portb.6

    porta.2 has pullup installed but led on portb.6 always lights....... isn't it supposed to sit there until porta.2 becomes low?

  2. #2
    Join Date
    Oct 2004
    Posts
    440


    Did you find this post helpful? Yes | No

    Default Re: Simple question about While Wend...

    "<>0" is the equivalent of "= 1" for a hi low read.


    Norm

  3. #3
    Join Date
    Oct 2008
    Posts
    52


    Did you find this post helpful? Yes | No

    Default Re: Simple question about While Wend...

    Right.... while pin 2 is at a high state shouldn't the program stay in the while/wend loop until it goes low and then jump out and turn on the LED?

  4. #4
    Join Date
    Oct 2004
    Posts
    440


    Did you find this post helpful? Yes | No

    Default Re: Simple question about While Wend...

    Quote Originally Posted by dbachman View Post
    Right.... while pin 2 is at a high state shouldn't the program stay in the while/wend loop until it goes low and then jump out and turn on the LED?
    Yes

    Try if not already:
    Read a PortB pin in place of portA to avoid config errors.
    Initialize Low portB.6
    Is the read pin an input?


    Norm

  5. #5
    Join Date
    Oct 2008
    Posts
    52


    Did you find this post helpful? Yes | No

    Default Re: Simple question about While Wend...

    this is the code..

    Trisa = 1
    Trisb = %00100000
    portb = 0
    while portb.5 = 1
    wend
    high portb.4

  6. #6
    Join Date
    Oct 2004
    Posts
    440


    Did you find this post helpful? Yes | No

    Default Re: Simple question about While Wend...

    Try adding some debugs to see if you can find where the breakdown occurs:

    Code:
    Trisa = 1
     Trisb = %00100000
     portb = 0
    
    if portb.5 = 1 then
    SerOut2 cSEROUT_PIN,cBAUD,["PRE HI",13]
    else  
    SerOut2 cSEROUT_PIN,cBAUD,["PRE LOW",13]
    endif
      
     while portb.5 = 1
    
    if portb.5 = 1 then
    SerOut2 cSEROUT_PIN,cBAUD,["LOOP HI",13]
    else  
    SerOut2 cSEROUT_PIN,cBAUD,["LOOP LOW",13]
    endif
    
     wend
    
    if portb.5 = 1 then
    SerOut2 cSEROUT_PIN,cBAUD,["AFT HI",13]
    else  
    SerOut2 cSEROUT_PIN,cBAUD,["AFT LOW",13]
    endif
    
     high portb.4
    Norm

  7. #7
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229


    Did you find this post helpful? Yes | No

    Default Re: Simple question about While Wend...

    What PIC MCU are you using?

    Should you be using LATB register instead of PORTB register for your High and Low statements?
    Read modify write may be an issue.
    Regards,
    TABSoft

  8. #8
    Join Date
    Oct 2008
    Posts
    52


    Did you find this post helpful? Yes | No

    Default Re: Simple question about While Wend...

    I am using an 18f2550.....

    Norm...I don't think I am experienced enough to use that debug code...

    I have looked back at some other code I have written and have used while/wend the same way.. should I use a pullup on portb.5 to ensure it is high?...I will try that but I think I have already..

    Thanks for helping me figure this out...

  9. #9
    Join Date
    Oct 2008
    Posts
    52


    Did you find this post helpful? Yes | No

    Default Re: Simple question about While Wend...

    I guess that was it...the pullup resistor on the input...apparently it was floating...

  10. #10


    Did you find this post helpful? Yes | No

    Default Re: Simple question about While Wend...

    Hi

    Portb on the 18f2550 has analog inputs. You need to set the those pins to digital.

    Try adding

    ADCON1 = %00111111

    This will make all the analog pins digital, see page 254 data sheet
    Last edited by mark_s; - 26th July 2015 at 02:07.

Similar Threads

  1. Very simple question (for someone)
    By lew247 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 27th December 2009, 03:36
  2. A simple and basic question
    By Ted's in forum mel PIC BASIC Pro
    Replies: 35
    Last Post: - 29th June 2008, 20:01
  3. SIMPLE question
    By ngeronikolos in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 5th February 2008, 19:27
  4. very simple loop question
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 25th January 2006, 07:45
  5. Simple Question
    By koossa in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 14th December 2005, 15:43

Members who have read this thread : 1

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