Byte array indexing help needed
I have 2 byte array variables.
The TubeStatus[16] array contains byte values that are the equivalent of inventory counts of the 16 different bytes in the array numbered 0 - 15.
The TubeFull[2] array is a 2 byte array that is used as a flag to indicate which of the 16 tubes may be full.
What I am trying to do is read the value of each of the 16 bytes from TubeStatus and compare them to the number $32 Hex. If they are at $32 or more than I want to set the individual bit in TubeFull that corresponds to each byte from TubeStatus. In other words TubeStatus byte [0] would control TubeFull bit 0, TubeStatus byte [1] would control TubeFull bit 1, etc.
Here's the code I was trying but can't get to work:
I had thought about declaring TubeFull as a word and working some magic on shifting bits through the word but then I open another can or worms trying to break up TubeFull into 2 bytes so that it can be transmitted as 2 bytes instead of 1 word. My transmit method has a tx_block command but I can't seem to make it work.
Any and all help much appreciated.
Thanks.
Don
The TubeStatus[16] array contains byte values that are the equivalent of inventory counts of the 16 different bytes in the array numbered 0 - 15.
The TubeFull[2] array is a 2 byte array that is used as a flag to indicate which of the 16 tubes may be full.
What I am trying to do is read the value of each of the 16 bytes from TubeStatus and compare them to the number $32 Hex. If they are at $32 or more than I want to set the individual bit in TubeFull that corresponds to each byte from TubeStatus. In other words TubeStatus byte [0] would control TubeFull bit 0, TubeStatus byte [1] would control TubeFull bit 1, etc.
Here's the code I was trying but can't get to work:
pub Tube_Inventory | s, pos
repeat pos from 0 to 15
s := byte[TubeStatus][pos]
if s => $32
if pos < 8
byte[@TubeFull][0] := (%1 << pos)
else
pos := pos - 8
byte[@TubeFull][1] := (%1 << pos)
I had thought about declaring TubeFull as a word and working some magic on shifting bits through the word but then I open another can or worms trying to break up TubeFull into 2 bytes so that it can be transmitted as 2 bytes instead of 1 word. My transmit method has a tx_block command but I can't seem to make it work.
pub tx_block(pntr, n, ds)
'' TX block of n bytes / words
'' -- address of block is at pntr
'' --ds is data size: 1 for bytes, 2 for words
repeat n
if (ds == 1)
tx(byte[pntr++])
else
tx(word[pntr])
pntr +=2
Any and all help much appreciated.
Thanks.
Don

Comments
Quick first impression: your statement s := byte[TubeStatus][pos] should read s := byte[@TubeStatus][pos].
BTW, if TubeStatus is delcared as a byte array, you can dispense with byte[@TubeStatus][pos] and just write TubeStatus[pos].
-Phil
Here is how Iwould do it:
pub Tube_Inventory : i TubeFull := 0 repeat i from 0 to 15 if TubeStatus[i] => $32 TubeFull |= 1<<i 'and in your send routine, send TubeFull bytewise: tx(TubeFull.byte[0]) tx(TubeFull.byte[1])Andy
- Mine requires no array

wrong posting, Dang pill confused me.Phil- actually I did have the ampersand in my original code. Just forgot to type it in this posting. Thanks for the shortcut tips however.
Ariba- Thanks for your suggestion. I'll give it a whirl and see how I get along. Thanks again.