Shop OBEX P1 Docs P2 Docs Learn Events
Propellers' highbyte and lowbyte — Parallax Forums

Propellers' highbyte and lowbyte

HumanOzzHumanOzz Posts: 13
edited 2010-09-04 07:07 in Propeller 1
Hey guys,
i need some help with this,
well, i would like to know whether its possible to access each byte of a word.
for eg, defined blabla as word
then, i would like to know if its possible to access each byte in the propeller?
like in bs2, i can just use blabla.highbyte and blabla.lowbyte to access the bytes.
Basically what i want is to write or read the high and low byte of a word.
Is there really a command in propeller which does this?

Comments

  • HumanOzzHumanOzz Posts: 13
    edited 2010-09-03 20:25
    hmm, nvm, i think i can just shift and OR the bytes together..
    because i was thinking of combining two bytes into 1 word, 1 of the byte will become the highbyte and the other will be the lowbyte of the word..
    so, if i initially set the two bytes to 16-bit size, shift the 1st byte (which will become the highbyte) by 8, den OR them together..
    I should be getting the one 1 want right.
    (will test later)
  • Mike GreenMike Green Posts: 23,101
    edited 2010-09-03 21:11
    You can use BYTE[] to access the individual bytes of a LONG or a WORD. If you have a LONG variable called myLong, you can say BYTE[@myLong][ 0 ] or BYTE[@myLong][ 1 ] or BYTE[@myLong][ 2 ] or BYTE[@myLong][ 3 ].

    It works the same way to access individual bytes of a WORD variable or individual words of a LONG variable.
  • John AbshierJohn Abshier Posts: 1,116
    edited 2010-09-04 07:07
    Simplier syntax
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    control  
    OBJ
      Sio  : "FullDuplexSerialPlus"        
    Var
      Word Glued
    
    Pub Main | i
      Sio.start(31,30,0,115200)  ' Rx,Tx, Mode, Baud
      waitcnt(clkfreq * 4 + cnt)
      Glued.BYTE[1] := $20  'X     'HIGH BYTE  
      Glued.BYTE[0] := $4B  'Y     'LOW BYTE
      Sio.hex(Glued, 4)      
    

    I assume it works for longs but didn't check

    John Abshier
Sign In or Register to comment.