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

Compact String Storage

 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
burnsy



Joined: 18 Oct 2003
Posts: 35
Location: Brisbane, Australia

View user's profile Send private message Send e-mail Visit poster's website

Compact String Storage
PostPosted: Thu Oct 21, 2004 7:45 pm     Reply with quote

G'day All,

This is a little utility I wrote after running out of space, and patience, while programming menus on a 16F877. It's in a primitive state, but with a little encouragement, I'll be willing to put in the time to make it more user friendly.

In a nutshell, the VB program takes your source text (see below)

Mary
had
a
little
lamb
and it could program C

.. and converts the text into #ROM so that it can be dropped into your programs (see below)

#org 0x0800,0x0818{}

//Mary
#define LCDMSG_1 0x0800
#rom LCDMSG_1={0x26E1,0x3979,0x0000}

//had
#define LCDMSG_2 0x0803
#rom LCDMSG_2={0x3461,0x3200}

//a
#define LCDMSG_3 0x0805
#rom LCDMSG_3={0x3080}

//little
#define LCDMSG_4 0x0806
#rom LCDMSG_4={0x3669,0x3A74,0x3665,0x0000}

//lamb
#define LCDMSG_5 0x080A
#rom LCDMSG_5={0x3661,0x36E2,0x0000}

//and it could program C
//
#define LCDMSG_6 0x080D
#rom LCDMSG_6={0x30EE,0x3220,0x34F4,0x1063,0x37F5,0x3664,0x1070,0x396F,0x33F2,0x30ED,0x1043,0x0000}

It is suitable for both fixed and variable length strings. It compresses two bytes into 14 bits (by stripping the top bit) so it's suitable for ascii below 0x80 only, and uses a 0x00 as a delimeter. The delimeter can be turned off to save storage space when using fixed length strings.

All your routine needs to do is address the label (eg LCDMSG_6). If you change any strings, just paste the new code in, the software will calculate any changes to the labels and you drop the new code back in your programm with no other changes to your software.

ie

romtolcd(LCDMSG_6);

Will display the MSG number 6 on an lcd. Here is some code for this function. It includes a function to read a byte from flash memory. CCS has its own routines for that also, but I have never used them

//READ BYTES FROM STRING IN ROM AND WRITE TO LCD UNTIL 0X00
void
rom2lcd(int rom_location)
{
char u,x;
/* wr lcd buffer with byte, with bytes stored in flash */
/* copy each byte to lcd_putchar() */
u RESET;
do
{
/* first byte */
x = read_flash(rom_location + u,0);
if (x)
{
lcd_putchar(x);
/* second byte */
x = read_flash(rom_location + u,1);
if (x)
{
lcd_putchar(x);
}
}
u++;
}
while (x != 0x00);
}


//READ BYTE FROM FLASH
char
read_flash(long y, char x)
{
char u;
/* read byte 0x100 */
eeadrh = y >> 8; /* high byte */
eeadr = y & 0x00FF; /* low byte */
eecon1.eepgd SET; /* point to flash */
eecon1.rd SET; /* start read operation */
delay_us(3); /* required delay(two nops) */
/* high or low byte */
if (x == 0)
{
/* high byte */
u = eedath << 1; /* get first 6 bits */
u &= 0x7F; /* clear bit7 */
/* get bit0 */
if (eedata & 0x80)
u |= 0x01;
else
u &= 0xFE;
}
else
{
/* low byte */
u = eedata & 0x7F;
}
return(u);
}


I would like to make the software a little more automatic to save cutting and pasting every time a string is changed. If anyone has some feedback or suggestions, I would welcome them.


The VB program is available from the following address:

http://www.jtekelectronics.com.au/picstuff/stringtorom2.exe
_________________
This is the last code change until its ready....
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library 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