CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

How many bytes a char use on program memory?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
restman
Guest







How many bytes a char use on program memory?
PostPosted: Wed Nov 21, 2007 8:54 am     Reply with quote

Hi.
My problem is (if it is a problem); when i declare a variable as a constant, it uses 2 bytes on program memory. (i look at it in Proteus) Is this natural or is there any setting for this to use one byte?

Thanks for your helps...
Ttelmah
Guest







PostPosted: Wed Nov 21, 2007 9:25 am     Reply with quote

You don't say what processor?.
The answer varies with the chip.
On the older PIC12/16 chips, there is no ability to directly access program memory, so a single byte, is coded as the instruction:
RETLW n
Where 'n' is the value required. Here, a single byte will always use one _word_ of program memory.
On PIC16 chips where the program memory can be directly accessed, though the whole word can now be retrieved, the problem is that the word, is 14bits long, and hence can't hold two bytes. There have been programs posted here in the past, to encode two 7bit ASCII values, into one of these locations.
On the PIC18, the locations can now hold two bytes, but the bytes have to be 'word aligned' at the start of the declaration. So, if you store 5 bytes, it'll use just three words, but storing a single byte, will use one word (the same applies with the fourteen bit encoding programs mentioned above).

Best Wishes
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Wed Nov 21, 2007 11:12 am     Reply with quote

ie:
http://www.ccsinfo.com/forum/viewtopic.php?t=20782
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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