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 CCS Technical Support

16F1829 Arrays and EEPROM

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



Joined: 22 Feb 2008
Posts: 14
Location: Germany

View user's profile Send private message

16F1829 Arrays and EEPROM
PostPosted: Tue Oct 14, 2014 1:40 pm     Reply with quote

Hello world,

since some weeks I am struggling with an array of 128 int elements and programming data into the EEPROM while burning the chip.

PCM 5.027
MPLAP 8.92


I need an array of 128 elements type UNSIGNED INT, value 0-255.

Code:

unsigned int array [128];


for testing I fill it in a for() loop with 128 numbers, e.g. 0 - 127.

In the watch window of MPLAB I can see about 70 numbers, after it comments "restricted memory".

I know that the 16F1829 only has 80 byte in a common "cluster".
Question: Is there a trick to force the compiler to build one big array or do I have to move to two 64 element arrays? Possible for me but not so nice.

Next problem is to store data in the EEPROM when programming the chip. I did this with a 16F690 by using

Code:

#rom 0x2100 = {1,2,3,4,5,6}


This does not work with the 16F1829 and I could not find the fault. I was told that the 0x2100 is correct for 16F... PIC but I am not sure if this address is also valid for the 16F1829.


Hope someone can help me in thus matter. At the moment it drives me crazy and make me mad.
Thanks in advance for your support.

Best regards from Germany

Uwe
stinky



Joined: 05 Mar 2012
Posts: 99
Location: Central Illinois

View user's profile Send private message

PostPosted: Tue Oct 14, 2014 3:17 pm     Reply with quote

not sure about the array.
For the eeprom try:

Code:
#ROM getenv("EEPROM_ADDRESS") = {1,2,3,4,5,6}
Ttelmah



Joined: 11 Mar 2010
Posts: 19551

View user's profile Send private message

PostPosted: Wed Oct 15, 2014 12:48 am     Reply with quote

The problem here is MPLAB.
Key thing to understand, is that it 'receives' from the .cof file passed after the compile, the 'start address' of the array, and the 'watch' tries to view this, as if it occupied consecutive memory locations (which it can't)...
Code:

#include <16F1829.h>
#device ADC=16
#device *=16
#use delay(crystal=20000000) //Obviously adjust this area and fuses
//To suit your chip and setup

void main()
{
   unsigned int array [128];
   unsigned int ctr;
   for (ctr=0;ctr<128;ctr++)
      array[ctr]=ctr;
   while(TRUE)
   {
      //something
   }
}

Note the *=16.

Then look at the symbol file:
021-06F,0A0-0D0 main.array

See how the array occupies two blocks of memory.

Run the code, and then look in the 'file registers' at first 0x21, where you will find 0x00, through to 0x4E in location 0x6F. Then look at Location A0, where you then find 0x4F to 0x7F held in location D0.

If instead you use the 'watch', on 'array', you see the values up to address 0x6F, but it then carries straight on, and displays the next 16 locations (up to 7F), which don't contain part of the array, and then starts trying to display from restricted memory....

The compiler correctly handles splitting the array in two, but the watch can't do this. You can add a second watch to look at the top half of the array, or just look in the file register window directly at the memory.

If you are having problems, look again at how you are accessing the array, and what you are writing to it.
aerodactyl



Joined: 22 Feb 2008
Posts: 14
Location: Germany

View user's profile Send private message

PostPosted: Wed Oct 15, 2014 10:57 am     Reply with quote

@Stinky
That works fine.
Thanke for the hint. The cstring EEPROM_ADDRESS is not liseted in my book.

@Hamlett
Clear so far and thank you very much for the nice explanation why MPLAB indicates it wrong.
For me it is important that the compiler build 1 complete array and split it into 2 parts automatically without any necessary action from my side.

Thanks for your support.

Uwe
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