Shop OBEX P1 Docs P2 Docs Learn Events
SX/B -- Arrays and Bit-Index — Parallax Forums

SX/B -- Arrays and Bit-Index

PJAllenPJAllen BannedPosts: 5,065
edited 2006-12-18 19:53 in General Discussion
Regarding arrays and bit indexing:

Symbol VAR Byte { (Size) } {.bitIndex}

Can't the·bitIndex number be a VARiable?

  FOR [color=red]X[/color] = 0 TO 7
    iso_bit = xmt_string(0).[color=red]X
[/color]    RA.0 = iso_bit
    PAUSEUS duration
    NEXT

·I'm trying to bit-bang out a byte (on RA.0) without using >>.

·** Post Edit **· No Replies.· Dang.· Moving forward with SHR (a.k.a. >>.)· Transmitting data 1200, 8-E-1.· So far, so good; no parity, frame or block errors.· Huzzah.

  FOR parse = 0 TO 7       
    iso = xmt_str & $01     'result = $00 or $01
    RA.0 = iso.0            'output bit 0 of iso
    parbit = parbit + iso   
    PAUSEUS 833.3
    xmt_str = xmt_str SHR 1 'Shift Right xmt_str
    NEXT                    'NEXT parse

Post Edited (PJ Allen) : 12/17/2006 1:37:26 AM GMT

Comments

  • BeanBean Posts: 8,129
    edited 2006-12-17 02:04
    PJ,
    No the bitIndex CANNOT be a variable. This is mainly due to the fact that the SX processor does not allow it in assembly either.


    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com
    Stuff I'm selling on ebay http://search.ebay.com/_W0QQsassZhittconsultingQQhtZ-1

    "USA Today has come out with a new survey - apparently, three out of every four people make up 75% of the population." - David Letterman
  • JonnyMacJonnyMac Posts: 8,923
    edited 2006-12-18 19:53
    I'm working on a "Life" program for the SX (using an 8x8 array of LEDs) and need to do bit indexing as well. Here's function that I have started with; it may be helpful to you.

    BITVAL        FUNC    1, 2, 3
    
    . . .
    
    ' Use: value = BITVAL someVal, position
    ' -- "someVal" can be a byte or word
    
    BITVAL:
      IF __PARAMCNT = 2 THEN                        ' byte passed?
        tmpW1 = __PARAM1                            ' get byte value
        tmpB1 = __PARAM2                            ' get bit position 
      ELSE                                          ' word passed
        tmpW1 = __WPARAM12                          ' word was passed
        tmpB1 = __PARAM3                            ' get bit position
      ENDIF
      tmpB2 = 0                                     ' assume cleared
      IF tmpB1 >= 0 THEN                            ' position value legal?
        IF tmpB1 <= 15 THEN
          tmpW2 = 1 << tmpB1                        ' create bit mask
          tmpW2 = tmpW2 & tmpW1                     ' clear other bits
          IF tmpW2 > 0 THEN                         ' if not zero
            tmpB2 = 1                               '   bit was 1
          ENDIF
        ENDIF  
      ENDIF
      RETURN tmpB2
    
Sign In or Register to comment.