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

Problem with pointers

2007-08-23
2013-03-12
  • franciscojar
    franciscojar
    2007-08-23

    Hi all,

    I make a bin2ascii function in order to convert the AD value and send it for the UART,
    It works fine alone also the algorithm is capable to convert signed: char, int, long or any other with minor changes, but when compile the whole project, the complier adds 2 more libraries and the function crash!

    The alone function is:

    main.c
    -----------------

    /*
    main.c
    Francisco Alvarez
    06-08-2007

    Prueba de binario a ASCII

    Compile: sdcc -mpic14 -p16f874a -c main.c

    */

    /* Define processor and include header file. */
    #define __16F874A
    #include"pic/pic16f874a.h"

    #define buffer_size    8
    #define campos    5

    void bin2ascii(int valor);

    unsigned char nada[buffer_size] = {0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37};
    unsigned char datoTX[buffer_size] = {0x0D,'h','o','l','a', 0x0D, 0x00, 0x00};
    unsigned char valorASCII[campos + 1] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
    unsigned char datoRX[buffer_size] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
    unsigned char irx = 0, itx = 0;

    void Int(void) interrupt 0
    {
    limpia:
    GIE = 0;
    if(GIE)
      goto limpia;
    irx++;
    itx++;
    datoRX[3] = 0x39;
    }

    void main(void)
    {
    unsigned char i;
    int valor;

    valor = 1023;
    bin2ascii(valor);

    for(i = 1; i < campos; i++)
      datoTX[i] = valorASCII[i];

    for(;;);
    }

    ---------------

    bin2ascii.c
    -----------------

    /*
    bin2ascii.c
    Francisco Alvarez
    14-08-2007

    Compile: sdcc --debug -mpic14 -p16f874a bin2ascii.c
            sdcc (-S o -o) -mpic14 -p16f874a main.c
    Simulate: gpsim -pp16f874 -s bin2ascii.cod

    */

    /* Define processor and include header file. */
    #define __16F874A
    #include"pic/pic16f874a.h"

    #define campos    5

    extern unsigned char nada[];
    extern unsigned char datoTX[];
    extern unsigned char valorASCII[];
    extern unsigned char datoRX[];
    const int inter[campos] = {10000, 1000, 100, 10, 1};

    void bin2ascii(int valor)
    {
    int temp;
    unsigned char cont = '0';
    unsigned char j = 1;

    while(j < campos)
      {
      temp = valor;
      valor = valor - inter[j];
      if(valor < 0)
        {
        valor = temp;
        valorASCII[j] = cont;
        j++;
        cont = '0';
        }
      else
        {
        cont++;
        }
      }
    }

    -------------

    When it compiles, add the library objects:

    sdcc --debug -mpic14 -p16f874a --lib-path /usr/share/sdcc/lib/pic -o exe main.o  bin2ascii.o
    message: using default linker script "/usr/share/gputils/lkr/16f874a.lkr"
    warning: processor mismatch in "_gptrget2.o"
    warning: processor mismatch in "_mulchar.o"
    warning: processor mismatch in "_gptrget1.o"

    but when compile the whole project, adds 2 more libraries:

    sdcc --debug -mpic14 -p16f874a --lib-path /usr/share/sdcc/lib/pic -o exe main.o Cpu.o AD1.o bin2ascii.o valor_ascii.o
    message: using default linker script "/usr/share/gputils/lkr/16f874a.lkr"
    warning: processor mismatch in "_gptrput1.o"
    warning: processor mismatch in "_gptrget2.o"
    warning: processor mismatch in "_mulchar.o"
    warning: processor mismatch in "_gptrget1.o"
    warning: processor mismatch in "_gptrput2.o"

    The libraries _gptrputX.o causes the string nada[], changes from "01234567" to "0x00, 0x00, 0x00, 34567" when bin2ascii function was called, also the valorASCII[] was wrong, it changes from "1023" to "0768"

    Would you tell me when the libraries _gptrputX.o are called, in order to avoid it in other parts of the project.

    Thanks in advance.

    franciscojar

     
    • jpremor
      jpremor
      2007-10-03

      Francisco,

      im starting a new project right now, and this warning about _gptrput is boring me. Can you say what is this error?
      Actually, im using libsdcc and pic16fxxx.lib pre compiled and this warning stills.
      Can anyone explain this warnings? My output have another warning:
      warning: processor mismatch in "idata.o"

      até mais!

      Jose Paulo

       
    • jpremor
      jpremor
      2007-10-03

      well, i found a half answer at other posts,

      https://sourceforge.net/forum/message.php?msg_id=4516613

      but what is this error? why it is happening? Is .lib precompiled different from my project compile options?
      Im  in windows, how can i recompile all libs?

      thanks!