Hot!XC16 addressing data memory question

Author
junky
New Member
  • Total Posts : 3
  • Reward points : 0
  • Joined: 2017/11/07 17:03:44
  • Location: 0
  • Status: offline
2017/11/09 15:12:05 (permalink)
0

XC16 addressing data memory question

Hello,
 
I have been able to assign some ram at a specific address in ram but my question is, is there a simple way to extract the data from the ram location using the address rather than the variable name?  I am somewhat of a newbie to programming and I can not seem to find an easy way to get this information.
 
Much Thanks,
Jim
 
 
#1

6 Replies Related Threads

    NKurzman
    A Guy on the Net
    • Total Posts : 14951
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: XC16 addressing data memory question 2017/11/09 15:54:16 (permalink)
    4 (2)
    You can Use a C language pointer.  But that may not be the best way.  Why Not the Name?
    #2
    junky
    New Member
    • Total Posts : 3
    • Reward points : 0
    • Joined: 2017/11/07 17:03:44
    • Location: 0
    • Status: offline
    Re: XC16 addressing data memory question 2017/11/09 16:36:43 (permalink)
    3 (1)
    Thank you NKurzman,
     
    I'm a hardware electronic engineer learning to how to "code", I have primarily been using dsPics to run control loops but the need for me to increase my coding ability is increasing, much thanks for increasing my learning the pointer works like a champ after I did some reading.
     
    Best Regards,
    Jim
    #3
    NorthGuy
    Super Member
    • Total Posts : 4511
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: online
    Re: XC16 addressing data memory question 2017/11/09 19:31:24 (permalink)
    3 (1)
    I have posted an answer, but my post mysteriously disappeared :(
     
    You can define a variable at absolute address. I think, XC16 does it with __at():
     
    int x __at(0x500);

     
    It is not a good idea too unless there's a good reason to do this. Absolute variables are bad for the compiler when it does allocations because it has to work around them.
     
    You can also do:
     
    v = *(int*)0x500;

     
    but this doesn't reserve the space at the specified address, so the compiler may slap something else to the place.
    #4
    junky
    New Member
    • Total Posts : 3
    • Reward points : 0
    • Joined: 2017/11/07 17:03:44
    • Location: 0
    • Status: offline
    Re: XC16 addressing data memory question 2017/11/10 09:01:12 (permalink)
    0
    Thank you North Guy,
     
    I will try out the __at() as well.
     
    Much Thanks
    #5
    aschen0866
    Super Member
    • Total Posts : 4159
    • Reward points : 0
    • Joined: 2006/01/08 22:18:32
    • Location: San Diego
    • Status: offline
    Re: XC16 addressing data memory question 2017/11/10 09:13:58 (permalink)
    3 (1)
    Make sure "Use CCI Syntax" is checked in the project properties.
    #6
    Batgoy
    New Member
    • Total Posts : 27
    • Reward points : 0
    • Joined: 2004/06/15 04:33:51
    • Status: offline
    Re: XC16 addressing data memory question 2017/11/15 00:32:52 (permalink)
    3 (1)
    Or:
        int __attribute__((address(0x1100)))    var;
    if "Use CCI Syntax" is not checked.
    #7
    Jump to:
    © 2017 APG vNext Commercial Version 4.5