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

Problem with memory map

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



Joined: 14 Aug 2006
Posts: 17

View user's profile Send private message

Problem with memory map
PostPosted: Thu Jan 25, 2007 9:19 am     Reply with quote

I'm working on a project with multiple LCD's (24 to be exact) and keyboard input. The project also requires that I save the user keyboard input. Everything works fine up to LCD 16, but from lcd 17-24, it repeats the memory information from LCD's 1-8. I'm using the 18F4525 with the latest CSC compiler. This is how I have the memory configured:
Code:

unsigned int32 memMap(int8 lcdNum){
   switch(lcdNum) {
      case 1 : return 0x0000; break;
      case 2 : return 0x0040; break;
      case 3 : return 0x0080; break;
      case 4:  return 0x00C0; break;
      case 5:  return 0x0100; break;
      case 6:  return 0x0140; break;
      case 7:  return 0x0180; break;
      case 8:  return 0x01C0; break;
      case 9:  return 0x0200; break;
      case 10:  return 0x0240; break;
      case 11:  return 0x0280; break;
      case 12:  return 0x02C0; break;
      case 13:  return 0x0300; break;
      case 14:  return 0x0340; break;
      case 15:  return 0x0380; break;
      case 16:  return 0x03C0; break;
      case 17:  return 0x1000; break;
      case 18:  return 0x1040; break;
      case 19:  return 0x10C0; break;
      case 20:  return 0x1100; break;
      case 21:  return 0x1140; break;
      case 22:  return 0x1180; break;
      case 23:  return 0x11C0; break;
      case 24:  return 0x1200; break;
   }
}

//This is how i'm reading the memory:

void handle_read_memory(){
   for (lcdNum=1; lcdNum <= numberofLCDs; lcdNum++){
      read_string(memMap(lcdNum));
   }
}

This is how i'm writing to memory:

void handle_save_memory(){
   write_string(memMap(lcdNum), userLabel);
}

//readstring function

void read_string(unsigned int16 address ) {
      int i =0;
   char c;
      
   for (i=0; i < 16; i++){
      c=read_eeprom(address);
               address++;
   }
}

//writestring function - function to take string array from keyboasrd and //write to eeprom
void write_string(unsigned int16 address, int8 string[]) {
      int8 ctr=0;
   
   for(ctr = 0; ctr < 16; ctr++){
      write_eeprom(address++,string[ctr]);
   }
}


Is there anything obvious that i'm doing wrong with my memory setup?
Ttelmah
Guest







PostPosted: Thu Jan 25, 2007 11:08 am     Reply with quote

A couple of comments.
First, why fiddle around with your 'memmap' function. Why not just declare this as a constant array?.
So, something like:
Code:


const int16 memmap[] = {
      0x0000,0x0000,0x0040,0x0080,
      0x00C0,0x0100,0x0140,0x0180,
      0x01C0,0x0200,0x0240,0x0280,
      0x02C0,0x0300,0x0340,0x0380,
      0x03C0,0x1000,0x1040,0x10C0,
      0x1100,0x1140,0x1180,0x11C0,0x1200 };


Then 'memmap[lcdnum]', will access the required value (note the extra '0' entry, since C arrays start at 0).

Now then, one thing leaps out. You appear to have a local variable, and a global, of the same name. In the 'handle_read_memory' function, you access 'lcd_num', which is not declared in this function, so is presumably 'global', but then in the MemMp function, you use a local 'lcd_num' value. Now this is meant to be OK, but I'd always consider it to be potentially dangerous...

Best Wishes
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Thu Jan 25, 2007 12:04 pm     Reply with quote

What is the size of the eeprom? If your eeprom is too small, you might be rolling over. Notice the address of 17, 0x1000 which could get confused with LCD 1's 0x0000.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Thu Jan 25, 2007 12:17 pm     Reply with quote

unsigned int32 memMap(int8 lcdNum);

It should be int16


Humberto
Joseph88



Joined: 14 Aug 2006
Posts: 17

View user's profile Send private message

PostPosted: Fri Jan 26, 2007 7:07 am     Reply with quote

Thanks for the help guys. I changed the memory structure so that it doesn't pass 0x1000, and it did the trick.

Joe
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