Shop OBEX P1 Docs P2 Docs Learn Events
array help using .byte[1] — Parallax Forums

array help using .byte[1]

Zap-oZap-o Posts: 452
edited 2009-05-22 20:53 in Propeller 1
Why wont this work ?

[b]
tempvar := buffer [noparse][[/noparse] count ].byte [noparse][[/noparse] 2 ] 
[/b]




Where buffer is a long and tempvar is a byte. Count is a long, but just used to index my buffer

Comments

  • AleAle Posts: 2,363
    edited 2009-05-22 19:34
    Wherever you got that syntax... it does not compile.

    if buffer is an array of longs, just do:

    tempvar := (buffer[noparse][[/noparse]count] & $00ff0000) >> 16

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Visit the home of pPropQL, pPropQL020 and OMU for the pPropQL/020 at omnibus.uni-freiburg.de/~rp92
  • Zap-oZap-o Posts: 452
    edited 2009-05-22 19:39
    Thanks, but what if I only need to access byte 2 in an array that is a long

    [b]
    Ser.tx(@buffer [noparse][[/noparse] count ].byte [noparse][[/noparse] 2 ] )
    [/b]
    
    
  • jazzedjazzed Posts: 11,803
    edited 2009-05-22 19:41
    tempvar := byte[noparse][[/noparse]@buffer+count*4+2]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve


    Propalyzer: Propeller PC Logic Analyzer
    http://forums.parallax.com/showthread.php?p=788230
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2009-05-22 20:53
    Zap-o,

    Here is a way to define an array as a long and access the individual bytes without having to do any additional multiplying or shifting. The only drawback is that you need to define your variables in the DAT section.


    This example lights the corresponding LEDs on the Propeller DemoBoard
    [b]CON[/b]
        [b]_clkmode[/b] = [b]xtal1[/b] + [b]pll16x[/b]                           
        [b]_xinfreq[/b] = 5_000_000
    
    [b]PUB[/b] MainProgram|i,tempvar
        buffer[noparse][[/noparse]*0] := %11110011_11100111_11001100_10010010
        buffer[noparse][[/noparse]*1] := %11111111_01010101_10101010_00011000
        buffer[noparse][[/noparse]*2] := %00000011_00000111_00001111_00011111
        buffer[noparse][[/noparse]*3] := %11000000_11100000_11110000_11111000            
    
        [b]dira[/b][noparse][[/noparse]*16..23]~~
        [b]repeat[/b] i [b]from[/b] 0 to 15
          tempvar := bufferBytes[noparse][[/noparse]*i]
          [b]outa[/b][noparse][[/noparse]*16..23] := tempvar
          [b]waitcnt[/b](clkfreq+[b]cnt[/b])
    
    [b]DAT[/b]
    buffer        [b]long[/b]
    bufferBytes   [b]byte[/b]      0,0,0,0 '<-buffer[noparse][[/noparse]*0]
                  [b]byte[/b]      0,0,0,0 '<-buffer[noparse][[/noparse]*1]
                  [b]byte[/b]      0,0,0,0 '<-buffer[noparse][[/noparse]*2]
                  [b]byte[/b]      0,0,0,0 '<-buffer[noparse][[/noparse]*3]
    
    



    ...or, you can simplify the DAT section to something like this if you have a large array...

    [b]DAT[/b]
    buffer        [b]long[/b]
    bufferBytes   [b]byte[/b] 0[noparse][[/noparse]16] '<-buffer[noparse][[/noparse]0..3] 
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 5/22/2009 9:25:11 PM GMT

Sign In or Register to comment.