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

RAM allocation in PIC18F6720

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



Joined: 15 Sep 2003
Posts: 75

View user's profile Send private message

RAM allocation in PIC18F6720
PostPosted: Mon Sep 17, 2007 7:02 am     Reply with quote

Hi,

1. I have over 150 global RAM variables (containing different types) and would like to allocate them from 0x100. I know #locate can be used to allocate a variable to a RAM location but it is quite tedious for 150 variables. Can someone suggest a more efficient method?

2. How do I assign data in RAM from a starting address to an end address in a function? e.g. Assign addresses 0x100 to 0x105 with 0xFF.

I use PCWH V3.249.

Thank you in advance.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

Re: RAM allocation in PIC18F6720
PostPosted: Mon Sep 17, 2007 7:26 am     Reply with quote

TL wrote:
1. I have over 150 global RAM variables (containing different types) and would like to allocate them from 0x100. I know #locate can be used to allocate a variable to a RAM location but it is quite tedious for 150 variables. Can someone suggest a more efficient method?
Try to minimize the use of global variables. The compiler can generate more efficient code when you use local variables and the code will be easier to understand and maintain.

For the remaining variables you can use the typemod identifier (replaced by addressmod in the v4 compiler).
Code:
typemod <,,,0x100,0x2ff> LargeMemBank;             // Define a large memory area

int8 LargeMemBank GprsRxBuffer[GPRS_RX_SIZE];
int8 LargeMemBank GprsTxBuffer[GPRS_TX_SIZE];


Note that with typemod you only declare a memory region for the variables, you can not specify the exact location of the variables within that region. Be carefull, there is no compiler warning on exceeding the memory region so you will have to check the symbol file for conflicts.

Quote:
2. How do I assign data in RAM from a starting address to an end address in a function? e.g. Assign addresses 0x100 to 0x105 with 0xFF.
Why would you want to do this? Using hard coded addresses like this sounds like bad programming practice. Try to reference the data using standard C mechanisms.
Code:
buf[5] = {0xFF,0xFF,0xFF,0xFF,0xFF};
or
memset(Buf, 0xFF, sizeof(Buf) );
TL



Joined: 15 Sep 2003
Posts: 75

View user's profile Send private message

PostPosted: Mon Sep 17, 2007 11:42 am     Reply with quote

Hi Ckielstra,

Thanks for your comments. Yes, I have tried typemod and it works. However, the strategy I was thinking would not work because I cannot assign data to RAM addresses.

I think I’ll use a STRUCTURE to encapsulate all the variables. This way, I can control the data more effectively without knowing the RAM addresses. I’m trying to read data from internal EEPROM to RAM. Also, if the internal EEPROM data is corrupted, I need to copy EEPROM data (backup) from a remote unit to RAM. Therefore, a structure in RAM should be fine.
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: RAM allocation in PIC18F6720
PostPosted: Mon Sep 17, 2007 11:44 am     Reply with quote

TL wrote:
Hi,

1. I have over 150 global RAM variables (containing different types) and would like to allocate them from 0x100. I know #locate can be used to allocate a variable to a RAM location but it is quite tedious for 150 variables. Can someone suggest a more efficient method?

2. How do I assign data in RAM from a starting address to an end address in a function? e.g. Assign addresses 0x100 to 0x105 with 0xFF.

I use PCWH V3.249.

Thank you in advance.


You can create a structure and locate the structure.

Using global variable for everything is a trade off. Global variables prevent RAM from being reused so less RAM is available but program code size will also be reduced if variable are not passed to functions because the variables are global. Bank switching can also be reduced if variables are located carefully.
Hans Wedemeyer



Joined: 15 Sep 2003
Posts: 226

View user's profile Send private message

Re: RAM allocation in PIC18F6720
PostPosted: Tue Sep 18, 2007 2:11 pm     Reply with quote

Neutone wrote:
TL wrote:
Hi,

1. I have over 150 global RAM variables (containing different types) and would like to allocate them from 0x100. I know #locate can be used to allocate a variable to a RAM location but it is quite tedious for 150 variables. Can someone suggest a more efficient method?

2. How do I assign data in RAM from a starting address to an end address in a function? e.g. Assign addresses 0x100 to 0x105 with 0xFF.

I use PCWH V3.249.

Thank you in advance.


You can create a structure and locate the structure.

Using global variable for everything is a trade off. Global variables prevent RAM from being reused so less RAM is available but program code size will also be reduced if variable are not passed to functions because the variables are global. Bank switching can also be reduced if variables are located carefully.

I agree with Neutone use a structure and locate it.

I posted a question a long time ago about the 18F6720 and memory problems. Someone suggested to NOT start the #locate below 0X300 which will prevents conflicts with the CCS compiler. Of course that was a long time ago.
However once I did that the memory problems were fixed...
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