Page 1 of 1

Address of variables

Posted: Sat Oct 30, 2021 7:55 pm
by Osta
Hey!
Tell me how to find out the address of the declared variables?
Thanks!

Re: Address of variables

Posted: Sun Oct 31, 2021 7:52 am
by mnfisher
Hi Osta,

You need to use a little bit of C. Since FC doesn't have an address type - use an int large enough to hold the address (so 16bit or 32 bit)

In a C block

Code: Select all

FCL_ADDR = &FCV_VARNAME;
Where addr is defined as a local variable - and varname a global - note that FC capitalises the variable name and adds FCL (local) or FCV (global).

Note that to read or write to the address you'll also need to use some C:

Martin

Re: Address of variables

Posted: Sun Oct 31, 2021 11:48 am
by Osta
Thanks Martin!
Got it.
Regards Osta.

Re: Address of variables

Posted: Wed Nov 24, 2021 12:24 pm
by medelec35
There is an alternative method.
When you compile there are various files created.
For PIC if you look in the .sym file and search (using ctrl F) for your variable, the stored address is shown in hex
The format is _FCV_YOURVARIABLE (for global) or _FCL_YOURVARIABLE (For local).
Stored address.png
Stored address.png (11.9 KiB) Viewed 1973 times
Depending on the side of the variable using more than one address could be used.
Both the above are bytes so only one location each is used.
with integers, it will be two, etc.
I'm not sure about AVR.

Re: Address of variables

Posted: Fri Jan 14, 2022 8:53 am
by Osta
Thank you so much!!!!