This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

not able to use printf statement in keil uvision 4

not able to use printf statement in keil uvision 4

Parents Reply Children
  • I AM GETTING ERROR LIKE "UART_0_1.c(206): warning: #167-D: argument of type "unsigned char *" is incompatible with parameter of type "const char *"

    so how can i solve this problem help me out

  • Start by trying to figure out the meaning of that const type.

  • // Header:
    // File Name: serial_led.c
    // Author:
    // Date:          14/06/2007
    #include <stdio.h>
    #include "LPC214x.h"
    #include <string.h>
    #define CR     0x0D
    
    
    
    char sendchar1 (char ch);
    char getkey1(char ch);
    char getkey0(void);
    void init_serial0(void);
    void init_serial1(void);
    unsigned char Disp[]="UART1";
    
    
    
    
    void lcd_initialize(void);
    void LCD_puts(unsigned char *,  unsigned char);
    void lcd_cmd(unsigned char);
    void lcd_data(unsigned char);
    void delay1(unsigned int);
    void lcd_display(void);
    unsigned char msg[] = {"VEHICLE LOCATION"};                                           //msg
    unsigned char msg1[]= {"USING GSM & GPS"};
    
    void gets_USART(unsigned char *);
    void Get_GPS_USART0(unsigned char *);
    
    const unsigned char cmd[4] = {0x38,0x0c,0x06,0x01};     //lcd commands
    
    unsigned long int DATA;
    unsigned char Chr,i=0,Str_GPS[100],*ptr,LAT[]="LAT:",LAN[]="LAN:";
    unsigned  char str1[]="GPRMC";
    //char * strstr(unsigned char *GPS_Str, const char *str1);
    
    void delay (void)
    {
    
            unsigned int i,j;
            for(i=0;i<50;i++)
            {
                    for(j=0;j<50;j++)
                    {
                            ;
                    }
            }
    }
    
    int main(void)
    {
    
            unsigned char i=0;
    
            IODIR0  = 0xFFFFFFFF;
                    delay1(10);
    
                    IODIR0 = 0XFFFFFFFF;    //PORT [P0.16--P0.31] output
                    IODIR1 = 0X00Ff0000;    //PORT [P1.20--P1.23] output
                    delay1(10);
                    lcd_initialize();               //Initialize LCD
                    delay1(10);
                    delay1(15);
                    lcd_display();
                    delay1(15);
            init_serial1();
            init_serial0();
            while(1)
            {
                    init_serial0();
                    Get_GPS_USART0(Str_GPS);
                    lcd_cmd(0x80);
                    LCD_puts(LAT,4);
                    LCD_puts(ptr,11);
                    ptr = ptr+13;
            //      send_sms(ptr);
            lcd_cmd(0xC0);
                    LCD_puts(LAN,4);
                    LCD_puts(ptr,11);
                    //ch = getkey();
                    printf("\nUART0\n");
                    i=0;
                    delay();
                    U1THR = '\n';
                    while(Disp[i]!= '\0')   {
    
                            sendchar1(Disp[i++]);
                            delay();
                    }
                    U1THR = '\n';
                    sendchar1(0x20);
            }
    }
    
    
    
    
    //----------------------------------
    //              LCD Initialize
    //----------------------------------
    void lcd_initialize(void)
    {
            int i;
            for(i=0;i<4;i++)
            {
                    IOCLR0 = 0x00FF0000;
                    lcd_cmd(cmd[i]);
                    delay1(15);
            }
    
    }
    
    //----------------------------------
    //              LCD Command Send
    //----------------------------------
    void lcd_cmd(unsigned char data)
    {
            IOPIN0  = data << 16;
            IOCLR1  |= 0x100000;            //RS
            IOCLR1  |= 0x200000;            //RW
            IOSET1  |= 0x400000;            //EN
            delay1(15);
            IOCLR1  |= 0x400000;            //EN
    }
    
    
    
    //----------------------------------
    //              LCD Data Send
    //----------------------------------
    void lcd_data(unsigned char data)
    {
            IOPIN0  = data << 16;
            IOSET1  |= 0x100000;            //RS
            IOCLR1  |= 0x200000;            //RW
            IOSET1  |= 0x400000;            //EN
            delay1(15);
            IOCLR1  |= 0x400000;            //EN
    }
    
    
    
    
    //----------------------------------
    //              LCD Display Msg
    //----------------------------------
    void lcd_display(void)
    {
            char i;
    
            /* First line message */
            IOCLR0 = 0x00FF0000;
            lcd_cmd(0x80);
            delay1(15);
            i=0;
            while(msg[i]!='\0')
                    {
                            IOCLR0 = 0x00FF0000;
                            lcd_data(msg[i]);
                            i++;
                            delay1(15);
                    }
            delay1(15);
                    /* sECOND line message */
            IOCLR0 = 0x00FF0000;
            lcd_cmd(0xC0);
            delay1(15);
            i=0;
            while(msg1[i]!='\0')
                    {
                            IOCLR0 = 0x00FF0000;
                            lcd_data(msg1[i]);
                            i++;
                            delay1(15);
                    }
            delay1(15);
    
            }
    
    void LCD_puts(unsigned char *string, unsigned char n)
    {
            while((*string) && ((n--)>0))
            lcd_data(*string++);
    }
    
    
    void gets_USART0(unsigned char *string)                                  //  Receive a batch of characters via USART1, without interrupt
    {
                                                                                                             //  The String Must Ended with "Carriage return" ie "Enter key"
            unsigned char i=0,J=0;
    
            do
            {
                    *(string+i)= getkey0();
                     J = *(string+i);
                     i++;
            }while((J!='\n') && (J!='\r'));
            i++;
            *(string+i) = '\0';
    }
    
    void Get_GPS_USART0(unsigned char *GPS_Str)
    {
            gets_USART0(GPS_Str);
    
            while(!(strstr(GPS_Str,str1))) gets_USART0(GPS_Str);
            ptr = strstr(GPS_Str,str1)+19;
    }
    
    void delay1(unsigned int Ms)
    {
            int delay_cnst;
            while(Ms>0)
            {
                    Ms--;
                    for(delay_cnst = 0;delay_cnst <220;delay_cnst++);
            }
    }
    

    this is my code i am getting that warning argument of type unsigned char* is incompatible with const char* in strstr function

  • You think char and unsigned char are the same data type?

    Would there be any implications if you typecast between unsigned char and char?

    //char * strstr(unsigned char *GPS_Str, const char *str1);
    

    Don't even begin to create alternative prototypes for strstr().

  • char * strstr(unsigned char *GPS_Str, const char *str1);

    i gave this prototype but it is displaying the same error ........UART_0_1.c(39): error: #147: declaration is incompatible with "char *strstr(const char *, const char *)" (declared at line 237 of "E:\Keil ARM\ARM\RV30\INC\string.h")

  • Of course. You decided to try to lie to the compiler and making a false claim.

    A $20 bill will still be a $20 bill even if you try to tell someone it is a $100 bill.

    That function takes the arguments that it did when Keil compiled the C runtime library. And Keil implemented their runtime library based on the C language standard. Trying to lie to the compiler and claim strstr() takes different data types by writing a new function prototype is not the route to go.

    So did you try out Google? Didn't you see any answers that seemed relevant to your problem? What is your view on type casts? What they are? And if they may be applicable to this problem? Would a type cast be able to keep the compiler happy, while also make strstr() still perform a correct job?

  • i need sample code on arm9 lpc 2929 i have a development board on that...........

  • hi, i need to port linux on ARM 9 LPC2929, so i need a help. and i need the steps to port the os help me out sir..

  • "hi, i need to port linux on ARM 9 LPC2929, so i need a help. and i need the steps to port the os help me out sir.."

    What does that have to do with using printf()?

  • What does that have to do with using printf()?

    Andrew Neil obviously knows.

  • No, he doesn't.

    But he knows where to ask: www.lmgtfy.com

  • sir, i didn't get the proper information from the link u gave so kindly support how to port linux on ARM 9 LPC2929

  • The documentation that you require to tell you how to perform a Linux port is called a "Porting Guide".

    The search link gives you links to plenty of Porting Guides - so what, exactly, is it that you require?

    Note that performing a Linux port is not a trivial or beginners task - you need to have a deep understanding of the Linux kernel, and a good understanding of your target hardware, and very good 'C' skills...

  • Isn't it rather obvious that "i need the steps to port the os" means: "where can I downloaded an already ported version"?

    Otherwise, the message would probably have been "I have tried to port Linux to xxx but am currently stuck getting xxx to work - anyone have any idea?"

  • sir, thanks for your reply sir...