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

how to read string from eeprom and parse it to GLCD?

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







how to read string from eeprom and parse it to GLCD?
PostPosted: Sun Jan 16, 2005 12:29 pm     Reply with quote

Hi there,

i have a small problem that i cant solve by my self due to my lack of C skills so i have made this function so i can read a string from EEPROM and return it :
Code:

char GetatIdx(char Idx) {
   char Cnt, Data[7];
   
   Idx = (Idx << 3);
   For (Cnt=0; Cnt < 8; Cnt++) {
      Data[Cnt] = Read_Eeprom(Idx);
      Idx++;
      If (!Data[Cnt]) Break;
   }
   Return Data;
}


now at this point iam useing sprintf so i can use the string from EEPROM with glcd_text57 function, but what do i need to change so i can use it directly in glcd_text57 ??

eg.
glcd_text57(0, 0, GetatIdx(0), 1, ON)


btw. Iam useing a PIC16F877A running at 20mhz and 128x64 KS0108B based GLCD.

Regards
Michael.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jan 16, 2005 4:28 pm     Reply with quote

There's a problem with your routine, or a few problems.
You're attempting to return a pointer to a ram array.
The array is local to that function, and could "disappear"
upon return from that function. The compiler is not
required to maintain its existence. Also, if you're
using 16-bit ram pointers, then you're only returning the
lower 8-bits of the address. What if the MSB of the pointer
is non-zero ? Then your returned address is invalid.

I'd suggest that you make the array be a global array.
Ie., move the declaration out of the function, and put
it above main(). And then, don't return anything from
the function. The result will be in the global array.
Make sure the text in the array has a trailing byte = 0x00,
so that other functions will recognize it as a string.
(Your code looks like it does this).
Assuming that your strings are a maximum of 7 characters
long (with 1 more for the string terminator of 0x00), then
this declaration could be used:

char glcd_data[8];

Then, after you get the string in that global array, display it with this:
glcd_text57(0, 0, glcd_data, 1, ON)

You should also put in some kind of safety feature. What if your
eeprom data doesn't have a 0x00 byte in it, for a particular index ?
Then your global array might be filled with eight 0xFF bytes.
Then when you pass it to the glcd_text57() routine, it wouldn't be
a valid string. You need to guard against this happening.
MichaelG
Guest







PostPosted: Sun Jan 16, 2005 4:46 pm     Reply with quote

Hi,

my function should store a 0x00 at the end of the string, they are defined like this :

#ROM 0x2100 = { 'M', 'e', 'n', 'u', '\0', '\0', '\0', '\0' }

so the un-used char space are 0x00.

But ill try makeing a Global string for glcd_text57.

tnx for you help.

Regards
Michael
MichaelG
Guest







PostPosted: Sun Jan 16, 2005 5:14 pm     Reply with quote

Yep, it working like a charme and i even saved some code space on it Smile

Tnx again.

Regards
Michael.
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