Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 4th February 2009, 07:10 AM   #1
Default Problem in using Pointer functions in C18 compiler

Hi,

I have attached my code for correction since i am getting warning as

Warning [2054] suspicious pointer conversion


[CODE]
#include"string.h" // is included


void main()
{

printlcd1(" Hello world ");

}

void printlcd1(unsigned char *str)
{
unsigned char len,i;//RCIE=0;
len = strlen(str);
set_add(0x80); //sets display position in the first line
for(i=0;i<len;i++)
{
data_lcd(*str); //displays the character on LCD
str++;
}
//return;
}[CODE]




Above is the code when i build i am getting warning as

Warning [2054] suspicious pointer conversion

wat corrections is to be made
kindly reply for this
Jyothi@Pic is offline  
Old 4th February 2009, 08:29 AM   #2
Default

There are two kinds of pointers on a Pic chip. One to ram and one to rom. Your function is defaulting to a ram pointer and the constant data "Hello World" is in rom.

There are two ways to fix this. First make them both rom pointers,
Code:
printlcd1((rom unsigned char*)" Hello world ");

void printlcd1(rom unsigned char *str)
The other way is to make them both ram pointers but the compiler will still store the constant string data in rom. You then have to copy the rom image to a ram buffer and point your function at the buffer.

Note that strlen expects a ram pointer so you would be better doing something like,
Code:
    while(*str){
        data_lcd(*str); //displays the character on LCD
        str++;
    }
Mike.
Pommie is online now  
Old 4th February 2009, 08:56 AM   #3
Default

Thanks it worked
Jyothi@Pic is offline  
Reply

Tags
c18, compiler, functions, pointer, problem

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
Strange Problem Encountered Using MicroChip MPLAB IDE C Compiler skyflyer54 Micro Controllers 48 10th July 2008 10:14 AM
C18 PIC18F4550 pointer problem HerbertMunch Micro Controllers 7 30th January 2008 06:58 PM
rtos_msg_send problem.. ccs c compiler overmind Micro Controllers 7 22nd January 2008 02:13 AM
MC18 compiler. C pointer question. HerbertMunch Micro Controllers 3 8th January 2008 05:39 PM
Problem setting up timer Interrupt using C18 compiler elec123 Micro Controllers 4 14th November 2007 11:59 AM



All times are GMT. The time now is 04:26 PM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker