I cannot get rid of this warning. All the documents I have read do not help at all. ( these include Keil forum search, Keil help function, the 8051 "bible", google e.t.c).
void halLcdWriteLine(uint8 line, const char* text) { BYTE sendBuffer[50]; UINT8 i, j; char c; if (text == NULL) return; i = 0; sendBuffer[i++] = LCD_ADDR; sendBuffer[i++] = REG_SEL_0; sendBuffer[i++] = ((line == HAL_LCD_LINE_1) ? LINE1_ADDR : LINE2_ADDR); smbSend(sendBuffer, i); i = j = 0; sendBuffer[i++] = LCD_ADDR; sendBuffer[i++] = REG_SEL_1; while( ( (c = text[j]) != '\0' ) && j < HAL_LCD_LINE_SIZE ){ sendBuffer[i++] = lcdConvertChar(c); j++; } for ( ;j < HAL_LCD_LINE_SIZE; j++){ sendBuffer[i++] = lcdConvertChar(' '); } smbSend(sendBuffer, i); }
This function writes a line of text on an LCD (communicates using I2C). A typical call to this function looks like this:
halLcdWriteLine(1, "Hello world");
Please help if you can.
I added the memory space specifier in the source file (it wasn't there before) and that is how i got less warnings. The declaration (in the header file) had a memory space identifier but the function definition did not.
To eliminate the warnings, I decided to use generic pointers throughout the program and it worked. I'll try tailoring the system for efficiency (use memory specific pointers) later once I know that at least everything works. Thanks guys, couldn't have done it without you.
What did you actually change?
Since most embedded processors are low on RAM, a compiler would normally place constant strings into the flash, i.e. CODE space.
Your function seems to expect that you always do a sprintf() or similar to format a string into a temporary buffer before passing the data for display.
It is always a big problem figuring out the best function signatures when working with processors with separate address spaces. The generic solutions tends to waste a lot of RAM or CPU time, while the possible optimizations are non-generic and tends to fail for some situations.
Thanks Andy, I have considerably less warnings now. It seems in the declaration (in a header file), the function is meant to receive an XDATA type pointer but this wasn't reflected when the function was defined.
i.e In the header (.h) file:
void halLcdWriteLine(uint8 line, const char XDATA *text);
In the source (.c) file:
void halLcdWriteLine(uint8 line, const char* text){....}
In spite of this, not all the warnings have gone away. Now i find the same warning wherever this function is called. An example of this function being called.
The string "Hello world" is passed directly to the function.
"Yes, I do understand what memory spaces are"
Good - but many people don't, so it was necessary to check!
" I guess the warning is meant to tell me that there is a mismatch in the types of pointers"
Yes, that's it.
"The warning always refers to the first line of code"
Hmm... that doesn't seem to make much sense - are you sure there isn't a prototype for that function somewhere, and the line you've shown doesn't (quite) match the prototype...?
Yes, I do understand what memory spaces are and almost everything around memory-specific and generic pointers. I guess the warning is meant to tell me that there is a mismatch in the types of pointers being compared (e.g i'm passing a memory specific pointer where a generic pointer is expected OR where a code-specific pointer is expected, a data-specific pointer is being passed).
This does not generate an error , it's only a warning. The warning always refers to the first line of code, i.e
void halLcdWriteLine(uint8 line, const char* text)
Where, precisely, is this error reported?
Do you understand the concept of the different Memory Spaces ("mspaces") in the 8051 architecture?
View all questions in Keil forum