Just need to clarify...


Closed Thread
Results 1 to 15 of 15

Hybrid View

  1. #1

    Default Just need to clarify...

    In the PBP manual under the REPEAT..UNTIL command it shows this example:
    i = 0
    REPEAT
    PORTB.0[i] = 0
    i = i + 1
    UNTIL i > 7

    I understand how it repeats until i is equal to 7 then moves on but what does the [i] in PORTB.0[i] do? That is the only example that I can find in the manual, other than where serial and the [] Versus is shown.

    Thanks
    Last edited by tazntex; - 29th March 2010 at 14:17.

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    i is the bit index. PORTB.0[i] = 0 is PORTB.BIT[i] = 0. i increments from 0 to 7, so it clears
    PORTB.0 to PORTB.7.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Thanks for the quick reply Bruce,
    So if I understand correctly, by
    i = 0
    REPEAT
    PORTB.0[i] = 0
    i = i + 1
    UNTIL i > 7

    i = i + 1 ' increments PORTB.0 thru 7 and
    PORTB.0[i] = 0 ' places a 0 in each bit

    Well, I'm good for the day, Learned something new.

    Thanks again Bruce

  4. #4
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bruce View Post
    i is the bit index. PORTB.0[i] = 0 is PORTB.BIT[i] = 0. i increments from 0 to 7, so it clears
    PORTB.0 to PORTB.7.

    I'm happy you posted this question tazntex. I never used the REPEAT instruction, but as a programmer I know I would have fallen into one of those see-what-you-want traps, something like this:

    i = 0
    REPEAT
    PORTB.[i] = 0
    i = i + 1
    UNTIL i > 7

    I would have looked at this code for hours before seeing where I went wrong.


    (I wished we had a button that allowed us to use the CODE command, I can never remember the syntax.)
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  5. #5
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default I would'nt have got it

    I for one have called the good people over at MElabs and requested(suggested) that they spend more effort on better syntax examples in the manual. Why waste all those clean white pages? (They agreed, by the way)

    As I look at this example it still does not make sense to me.
    I would have tried it the same as Robert, and banged my head against the wall for hours...

    This one does not look intuitive at all.

    Thanks for the heads up...

    Dwight

  6. #6
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    699


    Did you find this post helpful? Yes | No

    Default

    Tazntex,

    In your first post you said

    I understand how it repeats until i is equal to 7 then moves on but what does the [i] in PORTB.0[i] do?
    Technically speaking, it repeats until I=8 then it exits the loop. Of course, it won't execute the line PORT[I]=0 for I=8.

    Robert

  7. #7


    Did you find this post helpful? Yes | No

    Default

    Thanks goes to all for you help and interest.

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