View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Dec 21, 2005 2:46 pm |
|
|
Quote: | but is there no way to create a simple table of strings, and then use simple indexes "info[x]" to reach? |
Here is one example. It displays:
Quote: |
ABCD
Hello
Hi there
123456789
|
Code: | #include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#define NUM_STRINGS 4
#define STRING_BUF_SIZE 10
const char array[NUM_STRINGS][STRING_BUF_SIZE] =
{
{"ABCD"},
{"Hello"},
{"Hi there"},
{"123456789"}
};
void main()
{
int8 i;
int8 j;
int8 c;
for(i = 0; i < NUM_STRINGS; i++)
{
for(j = 0; j < STRING_BUF_SIZE; j++)
{
c = array[i][j];
if(c == 0) // If reached end of string
{
putc(10); // then display CRLF and break
putc(13);
break;
}
else
putc(c);
}
}
while(1);
} |
|
|
|
LTS
Joined: 08 Dec 2005 Posts: 8
|
|
Posted: Wed Dec 21, 2005 2:54 pm |
|
|
Great, thats exactly what i meant.. but.. how many elements and how many chars per element can i use? I really need each element to contain between 50-100 chars.. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Dec 21, 2005 3:13 pm |
|
|
Unfortunately, you can't do it. CCS says this in the manual:
Quote: | ROM arrays may not occupy more than 256 locations. |
So you can't do it with one large two-dimensional const array.
Example:
This compiles OK:
Code: | const char array[2][128] =
{
{"ABCD"},
{"Hello"},
}; |
But this gives an error because 2 x 129 = 258, and that's greater than 256.
Code: | const char array[2][129] =
{
{"ABCD"},
{"Hello"},
}; |
|
|
|
LTS
Joined: 08 Dec 2005 Posts: 8
|
|
Posted: Wed Dec 21, 2005 3:20 pm |
|
|
Damn... I guess I could use several arrays, but then again I get an indexing problem. What is the best way to store several strings around 100 chars, and easily use an integer to reach the correct one? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Dec 21, 2005 3:38 pm |
|
|
Here is one way. The code below displays this:
Quote: | ABCD
Hello World
The quick brown fox jumps over the lazy dogs back |
Code: | #include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
const char msg1[] ={"ABCD"};
const char msg2[] ={"Hello World"};
const char msg3[] ={"The quick brown fox jumps over the lazy dogs back"};
void display_msg(int8 index)
{
switch(index)
{
case 1:
printf(msg1);
break;
case 2:
printf(msg2);
break;
case 3:
printf(msg3);
break;
}
printf("\n\r");
}
//=====================================
void main()
{
display_msg(1);
display_msg(2);
display_msg(3);
while(1);
} |
|
|
|
LTS
Joined: 08 Dec 2005 Posts: 8
|
|
Posted: Wed Dec 21, 2005 3:49 pm |
|
|
Yeah, that would work. Thanks! |
|
|
|