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 do big number on LCD?

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



Joined: 21 Nov 2003
Posts: 200

View user's profile Send private message

How to do big number on LCD?
PostPosted: Sat Aug 11, 2007 7:45 am     Reply with quote

I have a routine that works on my LCD but it takes up alot of space. I know there is a better way to do this but I am not good with structures and/or pointers. Can someone give me a hand to not use so much code space... here is the code parts...

BYTE CONST NUM_TABLE [128]= {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x03,0x07,0x0F,0x1F,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0xF8,0xF8,0xF0,0xE0,0xC0,0x80,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

BYTE CONST NUM_TABLE2 [128]= {0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x07,0x0F,0x1F,0x3F,0x7F,0x7E,0xFC,0xF8,0xF8,0xF8,0xF8,0xF8,0x7C,0x7F,0x7F,0x3F,0x1F,0x0F,0x03,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0x80,0x00,0x00,0x00,0x00,0x01,0x03,0x07,0x0F,0xFF,0xFF,0xFF,0xFF,0xFE,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x07,0x0F,0x1F,0x3F,0x7F,0xFF,0xFE,0xFC,0xF8,0xF0,0xE0,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x3E,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0x7E,0x7E,0x7E,0x7E,0x7E,0x7E,0x7E,0x7E,0x7E,0x7E,0x7E,0x00,0x00,0x00,0x00,0x00,0x00};

BYTE CONST NUM_TABLE3 [128]= {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x0F,0x1F,0x3F,0x7F,0x7C,0xF8,0xF8,0xF8,0xF8,0xF8,0xF8,0x7C,0x7F,0x3F,0x3F,0x1F,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x0F,0x0F,0x0F,0x1F,0x7F,0xFF,0xFF,0xFD,0xF1,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x03,0x03,0x03,0x03,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0xC0,0xE0,0xFF,0xFF,0xFF,0xFF,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xE0,0xF0,0xF8,0xFC,0x7C,0x3E,0x3E,0x3E,0x3E,0x3E,0x3E,0x3E,0x7E,0xFC,0xFC,0xF8,0xF0,0xE0,0x80,0x00,0x00,0x00,0x00,0x00,0x00};

BYTE CONST NUM_TABLE4 [128]= {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x07,0x1F,0x3F,0x7F,0x7F,0x7F,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x07,0x0F,0x1F,0x3F,0xFE,0xF8,0xF0,0xE0,0xC0,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x1F,0x3F,0xFF,0xFF,0xFF,0xEF,0xCF,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0x0F,0x0F,0x0F,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0xFE,0xFE,0xFE,0xFE,0xFE,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00};

BYTE CONST NUM_TABLE5 [128]= {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xFF,0xFF,0xFF,0xF8,0xF8,0xF8,0xF8,0xF8,0xF8,0xF8,0xF8,0xF8,0xF8,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xFE,0xBE,0x3E,0x3E,0x3E,0x3E,0x3E,0x3F,0x1F,0x1F,0x0F,0x07,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x03,0x03,0x03,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x81,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xE0,0xF0,0xF8,0xF8,0xFC,0x7C,0x3E,0x3E,0x3E,0x3E,0x3E,0x7E,0xFC,0xFC,0xF8,0xF0,0xE0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

BYTE CONST NUM_TABLE6 [128]= {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x07,0x0F,0x1F,0x3F,0x3E,0x7C,0x7C,0x7C,0x7C,0x7C,0x3E,0x3F,0x1F,0x0F,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0x0F,0x0F,0x0F,0x1F,0x1F,0x1F,0x1F,0x0F,0x0F,0x07,0x07,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xFF,0xFF,0xFF,0xFF,0xFF,0x1E,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0xF8,0xFC,0xFC,0xFE,0x7E,0x3E,0x3E,0x3E,0x3E,0x3E,0x7E,0xFC,0xFC,0xF8,0xF0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

BYTE CONST NUM_TABLE7 [128]= {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x7C,0x7C,0x7C,0x7C,0x7C,0x7C,0x7C,0x7C,0x7C,0x7C,0x7C,0x7D,0x7F,0x7F,0x7F,0x7F,0x7F,0x7E,0x7C,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x0F,0x3F,0x7F,0xFF,0xFC,0xF8,0xE0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x1F,0xFF,0xFF,0xFF,0xFE,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3E,0xFE,0xFE,0xFE,0xFE,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

BYTE CONST NUM_TABLE8 [128]= {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x1F,0x3F,0x3F,0x7F,0x7F,0xFC,0xF8,0xF8,0xF8,0xF8,0xFC,0x7F,0x7F,0x3F,0x3F,0x1F,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0xF8,0xFC,0xFD,0xFF,0xFF,0x1F,0x0F,0x0F,0x0F,0x0F,0x1F,0xFF,0xFF,0xFD,0xFC,0xF8,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x7F,0xFF,0xFF,0xFF,0xFF,0xF0,0xC0,0x80,0x80,0x80,0x80,0xC0,0xF0,0xFF,0xFF,0xFF,0xFF,0x7F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xE0,0xF0,0xF8,0xFC,0xFC,0xFE,0x7E,0x3E,0x3E,0x3E,0x3E,0x7E,0xFE,0xFC,0xFC,0xF8,0xF0,0xE0,0x80,0x00,0x00,0x00,0x00,0x00,0x00};

BYTE CONST NUM_TABLE9 [128]= {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x0F,0x1F,0x3F,0x3F,0x7F,0x7E,0xFC,0xF8,0xF8,0xF8,0xFC,0x7E,0x7F,0x7F,0x3F,0x1F,0x0F,0x03,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0x03,0x01,0x01,0x01,0x01,0x01,0x03,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xE0,0xE0,0xF0,0xF0,0xF0,0xF8,0xF8,0xF8,0xF0,0xE0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0xF0,0xF8,0xFC,0xFC,0xFE,0x7E,0x3E,0x3E,0x3E,0x3E,0x7E,0xFE,0xFC,0xFC,0xF8,0xF0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

BYTE CONST NUM_TABLE0 [128]= {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x07,0x0F,0x1F,0x3F,0x7F,0x7E,0xFC,0xFC,0xFC,0xFC,0x7E,0x7F,0x3F,0x3F,0x1F,0x07,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xFF,0xFF,0xFF,0xFF,0xFF,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xF0,0xF8,0xFC,0xFC,0xFE,0x7E,0x3E,0x3E,0x3E,0x7E,0x7E,0xFC,0xFC,0xF8,0xF0,0xE0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00};


show_digit(int what)
{
int j,i;
for(j=0;j<4;j++)
{
send_command(0xB5-j); //Page address set
send_command(0x00);//LCD_COLUM_SET_L //set column
send_command(0x10); //set column
for(i=0; i < 32; i++)
{
switch(what)
{
case 1:
output_data(NUM_TABLE[((j*32)+i)]);
break;
case 2:
output_data(NUM_TABLE2[((j*32)+i)]);
break;
case 3:
output_data(NUM_TABLE3[((j*32)+i)]);
break;
case 4:
output_data(NUM_TABLE4[((j*32)+i)]);
break;
case 5:
output_data(NUM_TABLE5[((j*32)+i)]);
break;
case 6:
output_data(NUM_TABLE6[((j*32)+i)]);
break;
case 7:
output_data(NUM_TABLE7[((j*32)+i)]);
break;
case 8:
output_data(NUM_TABLE8[((j*32)+i)]);
break;
case 9:
output_data(NUM_TABLE9[((j*32)+i)]);
break;
case 0:
output_data(NUM_TABLE0[((j*32)+i)]);
break;
}

}

}
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Aug 11, 2007 11:55 am     Reply with quote

It looks like you have a large number of 0's in your data. If several
columns or rows that are common to all characters are zero-filled, then
you can delete that data from the tables. Then in your routine that
displays the character, have code send out those blank columns or rows.
This will probably save some ROM.
Guest








PostPosted: Sat Aug 11, 2007 12:28 pm     Reply with quote

I thought about that. I will do that . I was thinking along the line of structures and better arrays and such. Let me know if you have any more ideas. Thanx
SimpleAsPossible



Joined: 19 Jun 2004
Posts: 21

View user's profile Send private message

Try RLE or external memory
PostPosted: Tue Aug 14, 2007 8:34 pm     Reply with quote

You might consider run-length encoding, since your data repeats a lot.

Your first table
Code:

BYTE CONST NUM_TABLE [128]= {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x03,0x07,0x0F,0x1F,0x7F,0xFF,0xFF,
0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
(etc.)
};

becomes a table of count/value pairs:
Code:

BYTE CONST NUM_TABLE [40]=
{
    7,0x00, // table starts with seven 0x00s
    2,0x01, // then two 0x01s
    1,0x03, // then one 0x03
    1,0x07, // etc.
    1,0x0F,
    1,0x1F,
    1,0x7F,
    5,0xFF,
   19,0x00,
    3,0xF8,
    1,0xF0,
    1,0xE0,
    1,0xC0,
    1,0x80,
    6,0xFF,
   26,0x00,
    6,0xFF,
   26,0x00,
    6,0xFE,
   13,0x00
};


The big savings is obviously in the ones that occur 26 times in a row, but you even save some space on the ones that happen 6 (and even 3!) times in a row.

As compression schemes go, the implementation is pretty easy. When you read an entry in the array, it's two bytes: a count and a value. Output the value and decrement the counter. On the next loop, check the counter. If it's not zero yet, keep using the same value and decrement the counter again. If the counter is zero at the start of a loop iteration, you read the next entry in the table to get a new value and start the counter again. Stop when an overall counter gets to 128 or you run out of table entries. If you want to make it a little more bulletproof, add a count value at the start of each array (BYTE CONST NUM_TABLE [40]={ 40, 7,0x00, 2,0x01, 1,0x03, etc.), so you know how many entries there are in the table and can avoid running off the end.

Note: as long as the counts (7, 2, 1, etc.) add up to 128, you'll be OK.

(if you're really going for clarity in the code, you should use "struct { char value; unsigned int8 count; }" as your data type in the arrays)

Another approach is to store the data in an external memory of some type. An SPI interface serial EEPROM comes to mind.
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