Shop OBEX P1 Docs P2 Docs Learn Events
outa and dira alias — Parallax Forums

outa and dira alias

Charlie JohnsonCharlie Johnson Posts: 147
edited 2007-01-16 21:39 in Propeller 1
In PBASIC you can do:

Segs      VAR  OUTL  ' Segments on P0 - P7
SegsDIR   VAR  DIRL  ' DIRS for segments 


Is it possible to alias outa and dira?· If so, what is the syntax?

Charlie

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-01-16 16:49
    No. What you appear to want is a way to name a series of I/O pins and the corresponding directions and this isn't possible in SPIN. If you don't use the special notation (outa[noparse][[/noparse]bit1..bit2]), then you can do something that probably will work by using bit masks. For example, if you have a 7 segment display on pins 3 through 9, you could write:
    CON
      segMask = %1111111_000
      segShift = 3
    PUB setSegments(a)
      outa := (outa & !segMask) | (a << segShift & segMask)
    
    PUB enableSegments
      dira |= segMask  ' make segments outputs
    
    PUB disableSegments
      dira &= !segMask  ' make segments inputs
    
    


    You could get fancier by defining the highest pin # and lowest pin # and computing (as a constant) the bitmask and shift count like
    CON
    firstSegBit = 3
    lastSegBit = 9
    segMask = |<lastSegBit ^ (|<firstSegBit >> 1)  ' in other words %1111111_111 ^ %0000000_111
    segShift = firstSegBit
    
    
  • Charlie JohnsonCharlie Johnson Posts: 147
    edited 2007-01-16 21:39
    Mike,

    Thanks for the reply. I am already using something similar to your first example. I was just curious, because I am converting all the StampWorks examples to run on the SS.

    Charlie
Sign In or Register to comment.