View previous topic :: View next topic |
Author |
Message |
mutthunaveen
Joined: 08 Apr 2009 Posts: 100 Location: Chennai, India
|
const char strings[x][y] counting only 15 |
Posted: Mon Mar 14, 2016 10:07 am |
|
|
Dear Board
I'm mad at the behavior of my PIC controller.
16F877A, running at 20Mhz with 16x2 LCD - all works fine except last 2 messages
here is my code
Code: |
int lcd_second_line = 14;
int lcd_first_line = 13;
#DEFINE SIZE_COMMAND 18 // Sets the Max command Length including '\0'
#DEFINE TOTAL_STRINGS 17 // Total number of Searchable strings
const char Strings[TOTAL_STRINGS][SIZE_COMMAND]={
"NA\0", // index 1
"SUN\0", // index 2
"MON\0", // index 3
"TUE\0", // index 4
"WED\0", // index 5
"THU\0", // index 6
"FRI\0", // index 7
"SAT\0", // index 8
" SD CARD IN \0", // index 9
" SD PULLED OUT \0", // index 10
" INSERT SD CARD \0", // index 11
" SD CARD OK \0", // index 12
" TEMP MAX \0", // index 13
" TEMP MIN \0", // index 14
" RTC CLOCK FAIL \0", // index 15
" MP3 MODULE FAIL\0", // index 16
"TEMP SENSOR-\0" // index 17
};
void test_code(){
int temp99 = 0;
for(temp99=0; temp99 < total_strings ; temp99++){
printf(lcd_putc,"\f DEMO %i", temp99);
printf(lcd_putc,"\n%s",strings[temp99]);
delay_ms(1000);
}
}
|
my LCD shows untill 15 index very good
and after 16 and 17 are not displaying at all...
Plz someone help me where im mistaken
---
i would like to know if there is some limit for multi dimensional arrays??
also my first line shows the temp99 counting untill 17 but for 16 and 17 line 2 in LCD displays empty
thank you. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Mon Mar 14, 2016 10:31 am |
|
|
1) What compiler version?. There is a limit for any array, on older compilers.
2) You don't need the '\0' declarations. A _string_ is automatically terminated with a NULL. You are making each message one character longer than it needs to be. Because of this your 'TEMP MAX' string is longer than the space available for it.....
In general in C:
"A Test message", uses 15 characters of storage. The fourteen text characters, and the NULL that is automatically added to a string. |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Mon Mar 14, 2016 10:38 am |
|
|
in addition to MR.T's comment -
Code: |
Strings[TOTAL_STRINGS][SIZE_COMMAND]
....vs.....
strings[temp99][?-huh-?] ???
when accessed later
|
i call your attention to the above
and i count only 17 defined elements in your array
and as you count( correctly) from temp99=0 -16 will show them all
your '17' from base 0 to 16 is actually all you defined
it is doing pretty much all it can in displaying just the only 17 strings you defined....
is not the pic or ccs - code is doing what i think you asked
you need to ask it "better" |
|
|
mutthunaveen
Joined: 08 Apr 2009 Posts: 100 Location: Chennai, India
|
4.114 |
Posted: Mon Mar 14, 2016 11:14 am |
|
|
Dears
im using 4.114 ccs compiler
i ve deleted the NULL for optimising. and re runned the code but no change in behaviour
and as asmboy said.
yes its only from 0 - 16
untill index 0-15 (array 0-14) all messages displays on LCD
but index 16-17 (array 15-16) are not displayed over LCD. the forloop is running i checked it.
i hope its very clear now. |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Mon Mar 14, 2016 12:04 pm |
|
|
Quote: |
(array 15-16) are not displayed over LCD. |
what IS displayed ?? anything ?? garbage ?? |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
Re: const char strings[x][y] counting only 15 |
Posted: Mon Mar 14, 2016 12:09 pm |
|
|
mutthunaveen wrote: | Code: |
#DEFINE TOTAL_STRINGS 17 // Total number of Searchable strings
const char Strings[TOTAL_STRINGS][SIZE_COMMAND]={ ... };
for(temp99=0; temp99 < total_strings ; temp99++){
...
} |
|
Your code will only work if you DO NOT have a #case statement (which is the default).
That said, try changing the "total_strings" to "TOTAL_STRINGS" in the for() statement. What you have now is very sloppy and poor practice. Don't mix/change capitalization on defines/variables. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Mon Mar 14, 2016 12:52 pm |
|
|
The answer here is the compiler version.
4.114, is very old. There was a limit of 255 characters maximum in any array stored in ROM back at this time. The original code was written to allow ROM data to be stored in chips that didn't have any ability to actually access ROM. So ROM data was stored as a program that returns the required bytes. This was limited to an int8 index. Later this was changed, and V5 allows larger const arrays. I think it was actually first done in the later V4 versions, but not as early as .114. |
|
|
mutthunaveen
Joined: 08 Apr 2009 Posts: 100 Location: Chennai, India
|
|
Posted: Tue Mar 15, 2016 12:10 am |
|
|
Ttelmah thank you for final root cause identification.
so, its compiler error..
i was expecting a warning message at least. but i dont find any to solve the issue.
now i will limit my size or split it by 2 different variables.
thank you.
i would like to know which is the last stable version of CCS C to work with??
can you suggest? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Tue Mar 15, 2016 10:18 am |
|
|
The current V5 compilers are far more stable than any of the older compilers. |
|
|
|