Binary Representation of Variables
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.
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
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).
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.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)