|
|
View previous topic :: View next topic |
Author |
Message |
rikotech8
Joined: 10 Dec 2011 Posts: 376 Location: Sofiq,Bulgariq
|
#byte |
Posted: Sun Dec 11, 2011 9:19 am |
|
|
I was interested by a #byte function and I tested it. But something disturb me.
Code: |
int8 fred;
#byte fred = 0x60
fred = 10;
printf("fred = %d ",fred); //should display 10, but display 0
printf("freds address = %x ",&fred);
|
written on the screen: fred = 0 freds address = 60
Why the variable fred dont assume the value 10.
I hope you understand my question.
Thank you again! Smile |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Sun Dec 11, 2011 9:59 am |
|
|
First, you need to look at the data sheet of your processor. Is there RAM at address 60?.
Then you need to ensure this is not already used for something important. Is there a special function register (SFR) at this address?. Or does the compiler use this area for it's own functions?.
Seriously, the only main uses for #byte, are:
1) To locate a variable to talk to a SFR.
2) To locate two variables to use the same memory area (similar to a union).
3) Because you are working with other code that needs variables placed at a specific location.
Otherwise don't use it, and if you do, you _must_ study the data sheet.
Now, for example, of you are using a chip like the 16F676, this has RAM from address 0x20 to 0x5F, then from 0xA0 to 0xDF. The compiler puts it's own scratch area at 0x20, and allows 20 bytes for this.
Best Wishes |
|
|
rikotech8
Joined: 10 Dec 2011 Posts: 376 Location: Sofiq,Bulgariq
|
re: #byte |
Posted: Sun Dec 11, 2011 11:52 am |
|
|
I see. Thank you for helping me at this beginner level of knowing CCS. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|