Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Using delay.h under pic16

Alex
2007-03-09
2013-03-12
  • Alex
    Alex
    2007-03-09

    This is a simple source:

    #include <delay.c>
    #include <pic18fregs.h>
    main() {
        TRISB=0;
        PORTB=0;
        Delay100tcy(80);
        PORTB=1;
    }

    i try to compile it:

    sdcc -mpic16 -p18f2550 -V -I/home/cyberalex/pic/ -Wl-odelayc.hex -Wl-m -Wl-ainhx32 delayc.c
    delayc.c:6: function 'Delay100tcy' implicit declaration
    delayc.c:6: too many parameters
    delayc.c:7: code not generated for 'main' due to previous errors

    Where am i wrong?

     
    • Raphael Neider
      Raphael Neider
      2007-03-09

      In two places:

      1. #include <delay.h>
         You do not want to import the source, but the interface to the library.

      2. The function is called delay100tcy, with a lowercase `d' up front.

      3. (no error, just ugly) Use `void main(void)' for clarity.

      Good luck...
      Raphael

       
      • Alex
        Alex
        2007-03-09

        Corrected code:
        #include <delay.h>
        #include <pic18fregs.h>
        void main(void) {
            TRISB=0;
            PORTB=0;
            delay100tcy(80);
            PORTB=1;
        }
        But the problem hold over.
        Regards,
        Alex

         
        • Raphael Neider
          Raphael Neider
          2007-03-09

          Do you get other errors, such as
              delayc.c:1:20: error: delay.h: No such file or directory
          In this case, `locate delay.c | grep pic16' and add the (most fitting) path with an -I directive to your command. Also make sure that you do not have a delay.h lying around anywhere else within the include paths *prior* to the pic16/delay.c...

          I use

          sdcc -mpic16 -p18f1220 -I$SDCC/device/include/pic16 -I$SDCC/device/include -L$SDCC/device/lib/pic16/bin -Wl,-m delayc.c

          where SDCC=/home/neider/sdcc points to the head of my svn'ed SDCC source/build tree ($SDCC/ChangeLog exists).

          You may want to look at the (lengthy!) output of (only -E option added)
          sdcc -mpic16 -p18f1220 -I$SDCC/device/include/pic16 -I$SDCC/device/include -L$SDCC/device/lib/pic16/bin -E delayc.c
          and check which delay.h was included; this should give you something like

          # 1 "delayc.c"
          # 1 "<built-in>"
          # 1 "<command line>"
          # 1 "delayc.c"
          # 1 "/home/neider/sdcc/device/include/pic16/delay.h" 1
          # 30 "/home/neider/sdcc/device/include/pic16/delay.h"
          #pragma library c
          # 43 "/home/neider/sdcc/device/include/pic16/delay.h"
          void delay10tcy(unsigned char) __wparam;
          void delay100tcy(unsigned char) __wparam;
          void delay1ktcy(unsigned char) __wparam;
          void delay10ktcy(unsigned char) __wparam;
          void delay100ktcy(unsigned char) __wparam;
          void delay1mtcy(unsigned char) __wparam;
          # 2 "delayc.c" 2
          # 1 "/home/neider/sdcc/device/include/pic16/pic18fregs.h

          If it does not, you need to add the correct -I path to delay.h to your SDCC invokation.

          HTH,
          Raphael

           
          • Alex
            Alex
            2007-03-09

            The error was the same,now i know the cause: in the source file path there was a old file called delay.h -.-
            Thanks you very much for your quick help!
            Regards
            Alex