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

Storing a large 2D structure in program eeprom

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







Storing a large 2D structure in program eeprom
PostPosted: Wed Sep 03, 2008 1:34 am     Reply with quote

Hi Everyone,

I am trying to create a 2D structure that has 3 elements that are all integers. Obviously, the structure was too big for RAM, now I have to store it in program memory and am running into some issues. I'm using a PIC18F8722.

I define the structure and the size and the place in memory to store it in using the addressmod statement. Then later on in the code, I define the actual content of each structure element. My problem is that when I try to find out by reading back the contents of the structure, some locations have the correct data and some don't. My guess is that my definition of the structure in memory is not correct and is messing up the address of the defined elemets. Here's my code below:

Code:

#include <18F8722.h>
#device ADC=10
#include <stdio.h>
#include <math.h>
#include <ctype.h>
#include <stdlib.h>

#fuses H4,NOWDT,NOLVP
#use delay(clock=40000000)
#use rs232(baud=2400, xmit=PIN_C6, rcv=PIN_C7, parity=N, bits=8)

void DataEE_Read(int32 addr, int8 * ram, int bytes)
{
   int i;
   for(i=0;i<=bytes;i++,ram++,addr++)
   {
      *ram=read_program_eeprom(addr);
   }
}

void DataEE_Write(int32 addr, int8 * ram, int bytes)
{
   int i;
   for(i=0;i<=bytes;i++,ram++,addr++)
   {
      write_program_eeprom(addr,*ram);
   }
}

addressmod (DataEE,DataEE_Read,DataEE_Write,0x07FFE,0x1FFFE);

struct   swvar{

int DataEE   x;
int DataEE   y;
int DataEE   io_test_pin;
};

struct   swvar   DataEE   swtest[32][60];
short insertion[32];

void io_meas(void);
void map(int insertion);

void main(void)
{
   long   i   =   0;
   int   insert_count   =   0;
   int   sw_count      =   0;
   int   io_count      =   0;
   
   for(i = 0; i < 32; i++)
   {
      insertion[i]   =   0;
   }

   insertion[29]   =   1;


   for(insert_count = 0; insert_count < 32; insert_count++)
   {
      for(sw_count = 0; sw_count < 60; sw_count++)
      {

         swtest[insert_count][sw_count].x   =0;
         swtest[insert_count][sw_count].y   =0;
         
      }
   }   

   
   for(i = 0; i < 32; i++)
   {
      if(insertion[i]   ==   1)
      {
         map(i);
   
      }
   }

   io_meas();   


}

void io_meas(void)
{
   int i   =   0;
   int j   =   0;
   int   check      =   0;

   unsigned int   test1   =   0;
   unsigned int   test2   =   0;
   

   for(i = 0; i < 32; i++)
   {
      if(insertion[i]   ==   1)
      {
         for(j = 0; j < 60; j++)
         {   
            
            
   
         test1   =   swtest[i][j].x;
         test2   =   swtest[i][j].y;         

         printf("Insertion = %d\r",i);
         printf("Switch = %d\r",j);
         printf("x CTRL = %u\r",test1);
         printf("y CTRL = %u\r",test2);
            
               
         }
      }
   }

   return;   

}

void map(int insertion)
{
   
   switch(insertion)
   {
   

      case 29:
   
         swtest[29][0].x = 59;
         swtest[29][1].x = 60;
         swtest[29][2].x = 61;
         swtest[29][3].x = 59;
         swtest[29][4].x = 60;
         swtest[29][5].x = 61;
         swtest[29][6].x = 59;
         swtest[29][7].x = 60;
         swtest[29][8].x = 61;
         swtest[29][9].x = 59;
         swtest[29][10].x = 60;
         swtest[29][11].x = 61;
         
         swtest[29][0].y = 176;
         swtest[29][1].y = 177;
         swtest[29][2].y = 240;
         swtest[29][3].y = 241;
         swtest[29][4].y = 242;
         swtest[29][5].y = 178;
         swtest[29][6].y = 182;
         swtest[29][7].y = 183;
         swtest[29][8].y = 246;
         swtest[29][9].y = 247;
         swtest[29][10].y = 248;
         swtest[29][11].y = 184;
         
         swtest[29][0].io_test_pin = 25;
         swtest[29][1].io_test_pin = 25;
         swtest[29][2].io_test_pin = 25;
         swtest[29][3].io_test_pin = 26;
         swtest[29][4].io_test_pin = 26;
         swtest[29][5].io_test_pin = 26;
         swtest[29][6].io_test_pin = 23;
         swtest[29][7].io_test_pin = 23;
         swtest[29][8].io_test_pin = 23;
         swtest[29][9].io_test_pin = 27;
         swtest[29][10].io_test_pin = 27;
         swtest[29][11].io_test_pin = 27;

         break;
   }

   return;

}


I'm trying to store the structure in the bottom half of the program eeprom from 0x07FFE to 0x1FFFE to ensure it doesn't overlap the program code. Could someone help me to find out what the problem is. Maybe i'm not using the addressmod command correctly...

Thanks
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed Sep 03, 2008 2:12 am     Reply with quote

I can't compile the code without errors, cause the DataEE type modifier is used incorrectly in swvar definition. (With PCH V4.078). When omitting DataEE in the struct definition, the code compiles and seems to operate meaningfully (a first view).
nverma
Guest







PostPosted: Wed Sep 03, 2008 2:20 am     Reply with quote

I can get my code to compile with the following statement, i'm using 4.047:

Code:

struct   swvar   DataEE   swtest[32][60];


If I remove the DataEE from the above statement, the compiler complains about not enough RAM, hence why I'm trying to store the structure in the program eeprom. So when you compiled the code, you didn't get a RAM error?

And what can I do to resolve the DataEE function? I just need the entire structure to fit somewhere in memory, doesn't matter where...

Thanks
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