Typcasting Variables inside of Arrays


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2009
    Location
    Alabama,USA
    Posts
    232

    Default Typcasting Variables inside of Arrays

    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)"?

  2. #2
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    699


    Did you find this post helpful? Yes | No

    Default Re: Typcasting Variables inside of Arrays

    This thread might help you

    http://www.picbasic.co.uk/forum/show...ghlight=arrays

    Robert
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  3. #3
    Join Date
    Jan 2009
    Location
    Alabama,USA
    Posts
    232


    Did you find this post helpful? Yes | No

    Default Re: Typcasting Variables inside of Arrays

    And there we have it!

    Thanks Robert, It looks like I will be adding one more variable to the program.

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: Typcasting Variables inside of Arrays

    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
    DT

  5. #5
    Join Date
    Jan 2009
    Location
    Alabama,USA
    Posts
    232


    Did you find this post helpful? Yes | No

    Default Re: Typcasting Variables inside of Arrays

    Quote Originally Posted by Darrel Taylor View Post
    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

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: Typcasting Variables inside of Arrays

    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]
    DT

  7. #7
    Join Date
    Jan 2009
    Location
    Alabama,USA
    Posts
    232


    Did you find this post helpful? Yes | No

    Default Re: Typcasting Variables inside of Arrays

    Amazing!

    Thanks Darrel.

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts