View Full Version : Typcasting Variables inside of Arrays
MOUNTAIN747
- 20th February 2011, 18:42
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)"?
rsocor01
- 20th February 2011, 18:54
This thread might help you
http://www.picbasic.co.uk/forum/showthread.php?t=544&highlight=arrays
Robert
MOUNTAIN747
- 20th February 2011, 19:00
And there we have it!
Thanks Robert, It looks like I will be adding one more variable to the program.
Darrel Taylor
- 20th February 2011, 20:30
For more versatility, you might consider this ...
The EXT (external) modifier.
Typcasting Variables inside of Arrays
http://www.picbasic.co.uk/forum/showthread.php?t=3891#TYP
MOUNTAIN747
- 21st February 2011, 18:53
For more versatility, you might consider this ...
The EXT (external) modifier.
Typcasting Variables inside of Arrays
http://www.picbasic.co.uk/forum/showthread.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?
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
Darrel Taylor
- 21st February 2011, 19:55
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.
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]
MOUNTAIN747
- 21st February 2011, 21:33
Amazing!
Thanks Darrel.
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.