Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Printf routines not working in v2.9 - mcs51

BLRCalvin
2009-06-29
2013-03-12
  • BLRCalvin
    BLRCalvin
    2009-06-29

    Hello,

    I am using mcs51 port of SDCC v2.9 for Windows 2000 released on the web as is without any source modifications.
    SDCC : mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08 2.9.0 #5416 (Mar 22 2009) (MINGW32)

    My target board: Infineon XC878 (8051 Core)

    I am trying to print some data on the hyper terminal using the following code:

    #include <stdio.h>
    #include "xc878.h"

    extern void uart_init(void);

    main() {

    int i = 10;
    char c = 's';
    char str[] = "Hello World !!!";

    uart_init();

    printf("integer(10) = %d\r\n",i);

    printf("char(s) = %c\r\n",c);

    printf("str(Hello World !!!) = %s \r\n",str);

    return 0;
    }

    Output Obtained: int

    Where as expected output:
    integer(10) = 10
    char(s) = s
    str(Hello World !!!) = Hello World !!!

    putchar() and UART initializations are part of the project.

    Problem Description:

    printf() output is NOT correct in small,medium,large models. However, If I replace printf() with printf_small(), I get the

    expected output in small model only but does not work with medium,large.

    Question: Is there a printf routine that works with small, medium and large? In sdccman.pdf sec 3.17.2.1 is good but does

    not specify any limitations on the memory models support for these routines.

    Any help to resolve this is much appreciated. Thanks in advance.

    Build_Small.bat:

    set SDCC_HOME=C:\UserData\SDCC\SDCC_2_9_WEB
    set path=%SDCC_HOME%\bin

    sdcc -mmcs51 --model-small -c Printf_Test.c -o .\model_small_output\

    sdcc -mmcs51 --model-small -c putchar.c -o .\model_small_output\

    sdcc -mmcs51 --model-small -c UART.c -o .\model_small_output\

    sdcc -mmcs51 --model-small .\model_small_output\Printf_Test.rel .\model_small_output\putchar.rel

    .\model_small_output\UART.rel --xram-loc 0xF000 --xram-size 0xC00 -Wl -bBSEG=0x20 --idata-loc 0x80 -o

    .\model_small_output\Printf_Test_ModelSmall.hex

    BTW, Is there a way to include attachments while posting a message?

    Thanks & Best Regards,
    Raghu.

     
    • Maarten Brock
      Maarten Brock
      2009-07-01

      I'd get rid of --idata-loc 0x80. It's not necessary.
      Does the XC878 have an internal watchdog that's enabled by default?

      The forum has no option to include attachments, the tracker system does.

      Greets,
      Maarten

       
    • BLRCalvin
      BLRCalvin
      2009-07-10

      Hi Maarteen,

      Thanks for your reply. XC878 has an internal watchdog but it is NOT enabled by default.
      printf() problem is NOT solved yet. But I could get printf_small() working with large and medium as below:

      XC878-16FF processor has XRAM in memory bank 0x1F. So a SFR  MEX3 has to initialized with 0x1F. With this initialization, printf_small() works fine in all memory models.

      Thanks & Regards,
      Raghu.