burnsy
Joined: 18 Oct 2003 Posts: 35 Location: Brisbane, Australia
|
Compact String Storage |
Posted: Thu Oct 21, 2004 7:45 pm |
|
|
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.... |
|