Is it possible to reference outa[Px..Py]?
lyassa
Posts: 52
I am new to Spin so execuse me if this is a simple question ...
In the program snippet below, "outa[4..7]" is used few times. If later I wanted to change it to "outa[5..8]", I will have to make many changes. How can I avoid that?
dira[4..7]~~ ' set as output
outa[4..7] := %1111
...
outa[4..7] := %0011
...
I am hoping for something like this:
LEDs := [4..7]
outa[LEDs] := %1111
...
outa[LEDs] := %0101
...
In the program snippet below, "outa[4..7]" is used few times. If later I wanted to change it to "outa[5..8]", I will have to make many changes. How can I avoid that?
dira[4..7]~~ ' set as output
outa[4..7] := %1111
...
outa[4..7] := %0011
...
I am hoping for something like this:
LEDs := [4..7]
outa[LEDs] := %1111
...
outa[LEDs] := %0101
...
Comments
The first thing that comes to mind is,
Someone probably has a more efficient way.
CON
ledpins = 4
...
PUB
...
dira[ledpin..ledpin+4]~~
outa[ledpin..ledpin+4] := %1010
I thought I could use address reference, e.g. ScoreLeds := @outa[4..7], and then set the value at that address to whatever I need. However, that statement does not compile. I think because outa is a register, not a memory locaton? Not sure.
PUB main
...
ScoreLEDS(%1101)
...
ScoreLEDS(%1010)
PRI ScoreLEDS (val)
outa[4..7] := val
This way, outa[4..7] appears only once in the code.