function parameters pic14 problem

  • Jorus

    Jorus - 2006-10-03


    I try to manage an lcd to work with my pic 16f84a. So I writed a function named lcd_send_char :
    static void lcd_send_char(unsigned char charToSend);

    This function works perfectly. But when I use an other function named lcd_write_string :
    static void lcd_write_string(unsigned char stringToSend[17]) {
    for(i=0;i<16;i++) {

    It doesn't work the parameter has not the right value. I call the function like this :
    static unsigned char bonjour[17] = "hello baby !!!"
    static void main() {

    But if I use directly bonjour in the lcd_write_string function, it works...

    Did I do something wrong ?

    Thanks in advance.

    • Anonymous - 2006-10-03

      I guess this isn't much SDCC-related. Anyway, try

      static void lcd_write_string(unsigned char *stringToSend) { ... }

      and static unsigned char *bonjour="...";

      You should pass pointers, not entire arrays, as function parameters.

    • Raphael Neider

      Raphael Neider - 2006-10-04

      I cannot reproduce your problem with SDCC r4399; the .asm looks good (once I added a "char i;" in lcd_write_string). If your problem still occurs in a recent SDCC snapshot, please post more information (SDCC version/revision, compileable source to demonstrate your problem. You may want to file a support request and attach the required files or mail them to me directly rather than posting them here...

      Please also obey mlynki's hints.


      • Jorus

        Jorus - 2006-10-08

        Hello all,

        With sdcc r4400, the problem is the same. I tried to pass a 'unsigned char' (not a pointer) to my function 'lcd_write_string' and so to display the first character 16 times (the length of a lcd line). It works. So the problem is not in the loop.
        I tried to use a function local pointer on the char array to display but it doesn't work. So it is not only a passage parameter problem, but it seems that there is a pointer problem somewhere. But where ?
        Tecodev, I send you by mail my source code (lcd.c and lcd.asm). Did you received them ?


        • Raphael Neider

          Raphael Neider - 2006-10-10

          Yes, I did get your files and found two problems:

          (1) You are pretty much out of memory.
          From the .map file, I gather that you have exactly one byte of memory available...

          (2) There is memory where SDCC puts the stacks, which is used for passing arguments around...
          One (byte of the ) argument(s) is passed in W---that's why your firt two examples passing only a char work fine.
          Passing pointers requires to put 2 bytes on the pseudo "stack" (usually a sharebank register region). For the 16f84a, the stack is magically pinned to 0x70..0x7F; these memory cells read as 0 on the 16f84a, so you were bound to get queer results.

          This is actually a compiler bug, but even a manual worksaround (moving the sharebank allocated for the pseudo stack in the .asm file) does not work; you simpy have no memory left to place it!

          Sorry for the bad news,
          Raphael Neider

          PS: The location and size of the pseudo stack can now be defined via --stack-loc=0x40 and --stack-siz=16 arguments to SDCC; new in SDCC r4405.

          • Frieder Ferlemann

            Hi Raphael,

            there seems to be a problem with passing the argument. Why is the '=' required?

            'Old' (2.6.1 #4378) versions of SDCC would silently accept the argument without '=':

            sdcc -mpic14 -p16f84a --stack-loc 0x40  main.c

            whereas #4405 would barf:
            -:0: warning 119: don't know what to do with file '0x30'. file extension unsupported

            Likewise the 'old #4378' version would barf on the new syntax with the '='

            -:0: warning 117: unknown compiler option '--stack-loc=0x30' ignored

            Shouldn't the 'old' syntax be kept?

            • Raphael Neider

              Raphael Neider - 2006-10-10

              > Why is the '=' required?
              Because I am a fool... I just looked at the way arguments were parsed in the pic14 port and hacked my own approach; though SDCCmain.c already provides a much nicer way for getting int arguments.
              Additionally, I did not recognize the name-clash between the new pic14 args and existing mcs51 args...

              > Shouldn't the 'old' syntax be kept?
              Yes, it should.

              Thanks for your quick report.

              Essentially reverted to previous version, implemented again using existing code and committed as r4408.

          • Jorus

            Jorus - 2006-10-11

            Hello Raphael,

            [quote]Sorry for the bad news,[/quote]
            Oh no, the bad news is to not know ! :D

            Thanks for your help. Sometimes I forget that I am on a little friendly µcontroller. And it don't have 1 Go of memory ! :D

            Now I will see what I can reduce in my code. If I am able to make it works, I will provide a return on my experience.

            I am very grateful to you for your assistance.


    • Jorus

      Jorus - 2006-10-04


      First thanks your help.
      In my code, 'i' is global, it is why you don't see it in my function. But I can try to make it local
      I use the SDCC r4390. I will upgrade to r4399 tonight.
      I tried the mlynki solution but with no success.
      So if I always have the problem after updating to r4399, I will send you by mail my files.

      Thanks again


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks