View previous topic :: View next topic |
Author |
Message |
Study
Joined: 09 Apr 2009 Posts: 29
|
How to define variable in specific address of data memory? |
Posted: Thu Apr 09, 2009 11:13 am |
|
|
Hi friends
I use PCW 4.057.
what should i do to define specific address for a variable? ie,when I use 18F452, I want to define 16bit variable in 0x120 and 0x121 of internal ram. what should i write in CCS to locate my variable in these addresses?
Regards _________________ Sorry if i have much mistakes, my english is not good.
Thanks a lot for your helps.
Have a good time |
|
|
Ttelmah Guest
|
|
Posted: Thu Apr 09, 2009 2:45 pm |
|
|
There are actually several ways of doing this.
The 'correct' way, depends on whether you want to stop any other variable using the same area as well.
Code: |
int16 val;
#byte val=0x120
|
The int16 variable 'val', is now located at 0x120/121
The area can _still be used by C for other variables_. This is the approach normally used to locate a named variable 'on' one of the internal registers, since you need to still allow other variables the compiler may have mapped to the same locations, to be in the same spot.
Code: |
int16 val;
#locate val=0x120
|
The int16 variable 'val', is again located at 0x120/121, but now C won't use the area for anything else.
Best Wishes |
|
|
Guest
|
|
Posted: Fri Apr 10, 2009 1:21 am |
|
|
Thanks a lot Ttelmah, I understand. But can I write other things instead of int16 too?
Thanks again |
|
|
Study
Joined: 09 Apr 2009 Posts: 29
|
|
Posted: Fri Apr 10, 2009 1:23 am |
|
|
Anonymous wrote: | Thanks a lot Ttelmah, I understand. but can i write other things instead of int16 too?
Thanks again |
Sorry this is my post, i forgot to login before sending post _________________ Sorry if i have much mistakes, my english is not good.
Thanks a lot for your helps.
Have a good time |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Fri Apr 10, 2009 3:26 am |
|
|
Quote: | But can I write other things instead of int16 too?. |
1. Consider #locate as a general CCS specific command and try to answer the question yourself.
2. In case of doubt, consult the compiler manual |
|
|
|