Shop OBEX P1 Docs P2 Docs Learn Events
In a variable, what value to indicate span of pins [16..23] ? — Parallax Forums

In a variable, what value to indicate span of pins [16..23] ?

John KauffmanJohn Kauffman Posts: 653
edited 2010-09-23 07:50 in Propeller 1
I want to put a value into a variable that indicates pins 16..23. I have been unable to phrase this question in a way that gets results from searches in various Spin resources.

Sample:
VAR
long LedsData ' this will get a value that represents pins 16..23

Pub Main
LedsData := ' >>>>> What to put here?? <<<<<
Dira[LedsData]~~
repeat
outa[LedsData] := %10000000 ' desired result: set high pin 16 only

Comments

  • RavenkallenRavenkallen Posts: 1,057
    edited 2010-09-22 20:20
    You would put the first pin number and then the last one. And you would use the OUTA register. Ledsdata will now hold a copy of the outa register...so it would be like

    Ledsdata := OUTA[16..23]

    It does talk about it in the manual. It is under the OUTA entry. The outa register is normally used for outputting data to pins, but it can be read from. This gives a lot more flexibility...hope it helps
  • Mike GreenMike Green Posts: 23,101
    edited 2010-09-22 20:40
    There is no value that represents the notation Pin#..Pin#. If you really want to use a variable range of I/O pins, you'd need two variables that hold the least significant pin number and the number of pins, then use the bit logical operations to manipulate a mask to operate on the whole OUTA and DIRA registers.

    Usually what people want is to use named I/O pins, but these are usually constants. You can use CON to declare named constants and use those names in the Pin#..Pin# notation like this:
    CON 
       firstLED = 16
       lastLED = 23
    
    PRI setLEDs
       OUTA[lastLED..firstLED] := %10101010
    
  • RavenkallenRavenkallen Posts: 1,057
    edited 2010-09-22 21:03
    @John...Yes, Mike is right. Your current code would not do anything. If you want a set a group of output pins to represent the original variable, you will have to change a few things...Lets assume you wanted to read the pins 16- 23 and you wanted to output them on pins 8-15...

    ''Sample
    var
    byte ledsdata

    pub main
    DIRA[16..23]~~
    DIRA[8..15]~~
    OUTA[16..23] := %1000000
    ledsdata := OUTA [16..23]
    repeat
    outa[8..15] := ledsdata
  • John KauffmanJohn Kauffman Posts: 653
    edited 2010-09-23 07:50
    Thanks guys, I see now where it is presented in the manual.
    I was hung up on the idea that since there are 32 pins and the are all represented by 'a', I would have to enter a long that had only the 3rd quarter of the long designated; you can see how I got stuck

    Mike: right, CON is what most people want, including me. Asking VAR was error on my part.
    RK: thanks for demo of actually using a VAR (instead of CON).
Sign In or Register to comment.