Shop OBEX P1 Docs P2 Docs Learn Events
Binary Representation of Variables — Parallax Forums

Binary Representation of Variables

Vega256Vega256 Posts: 197
edited 2011-02-17 05:07 in Propeller 1
Hey Guys,

Lets suppose that I would like to set I/O pins [0..8] to output and in a loop set their states' to some binary number that increments after every cycle of the loop. How would I contain this value in a variable, increment the value in the variable and represent that value as a binary number? I used the (%) sign followed by the variable name but that produces a compile-time error.

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2011-02-17 04:51
    What about something like this:
    PUB null
    
      dira[0..8]~~
      repeat
        outa[0..8]++
        waitcnt(clkfreq/4 + cnt)
    

    outa[0..8] := variable++ will also work (as will thousands of other variations).

    Basically there is no special binary state, it's just a different way of looking at it (a variable).
  • Vega256Vega256 Posts: 197
    edited 2011-02-17 05:02
    var
      byte address
    pub first
      address := 0
      dira [16..23] := 1
      repeat
        outa [16..23] := address ++
        waitcnt (3_000_000 + cnt)
    
    When I attached LEDs to the pins using this code, only the first bit is toggled, the second is constantly low.
  • kuronekokuroneko Posts: 3,623
    edited 2011-02-17 05:03
    var
      byte address
    pub first
      address := 0
      dira[16..23] := [COLOR="red"]%1111_1111    ' 1 is equivalent to %0000_0001[/COLOR]
      repeat
        outa[16..23] := address++
        waitcnt (3_000_000 + cnt)
    
  • Vega256Vega256 Posts: 197
    edited 2011-02-17 05:05
    I see. Although the range expression refers to all of the pins in the range, it is still required to list the states individually.
  • kuronekokuroneko Posts: 3,623
    edited 2011-02-17 05:07
    Vega256 wrote: »
    I see. Although the range expression refers to all of the pins in the range, it is still required to list the states individually.
    Correct, the left-hand-side is effectively an 8 bit variable (16..23), so you still have to provide 1 bit each. The post set operator (~~) does exactly that for you. You can also assign TRUE (-1).
Sign In or Register to comment.