Why is it that if I define variables by typcasting Variables inside of Arrays I can not use HighByte and LowByte on those variables? When I do, I get an error message that says "attempt to redefine (the variable)"?
Printable View
Why is it that if I define variables by typcasting Variables inside of Arrays I can not use HighByte and LowByte on those variables? When I do, I get an error message that says "attempt to redefine (the variable)"?
This thread might help you
http://www.picbasic.co.uk/forum/show...ghlight=arrays
Robert
And there we have it!
Thanks Robert, It looks like I will be adding one more variable to the program.
For more versatility, you might consider this ...
The EXT (external) modifier.
Typcasting Variables inside of Arrays
http://www.picbasic.co.uk/forum/show...php?t=3891#TYP
Darrel, EXT can't be that versatile. I'm using the EXT modifier, its your code example I'm using.
Serout2 TX_USB, 84,[" DSvolts is ",bin DSvolts.highbyte,bin DSvolts.lowbyte,13,10]
this won't compile. Should it? Or could I have a Bank problem?
Code:DSbuffer VAR BYTE[9] BANK0
ASM ;Typcasting Variables inside of Arrays
DSstat = _DSbuffer ; byte
DStemp = _DSbuffer + 1 ; word
DSvolts = _DSbuffer + 3 ; word
DScurrent = _DSbuffer + 5 ; word
DSthres = _DSbuffer + 7 ; byte
DScrc = _DSbuffer + 8 ; byte
ENDASM
DSstat VAR BYTE EXT ; Status/Configuration
DStemp VAR WORD EXT ; Temperature
DSvolts VAR WORD EXT ; Voltage
DScurrent VAR WORD EXT ; Current
DSthres VAR BYTE EXT ; Threshold
DScrc VAR BYTE EXT ; CRC
PBP can't use HighByte and Lowbyte because it doesn't know where the variable is when PBP is compiling. The location isn't known until it's Assembled.
Try it like this, which specifies the High and Low bytes as EXT too.
Code:DSbuffer VAR BYTE[9] BANK0
ASM ;Typcasting Variables inside of Arrays
DSstat = _DSbuffer ; byte
DStemp = _DSbuffer + 1 ; word
DSvolts = _DSbuffer + 3 ; word
DSvoltsL = _DSbuffer + 3 ; byte
DSvoltsH = _DSbuffer + 4 ; byte
DScurrent = _DSbuffer + 5 ; word
DSthres = _DSbuffer + 7 ; byte
DScrc = _DSbuffer + 8 ; byte
ENDASM
DSstat VAR BYTE EXT ; Status/Configuration
DStemp VAR WORD EXT ; Temperature
DSvolts VAR WORD EXT ; Voltage
DSvoltsH VAR BYTE EXT
DSvoltsL VAR BYTE EXT
DScurrent VAR WORD EXT ; Current
DSthres VAR BYTE EXT ; Threshold
DScrc VAR BYTE EXT ; CRC
Serout2 TX_USB, 84,[" DSvolts is ",bin DSvoltsH,bin DSvoltsL,13,10]
Amazing!
Thanks Darrel.