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

first program fails to compile.

Help
William
2011-08-18
2013-03-12
  • William
    William
    2011-08-18

    Hi group,
    my first attempt to compile a simple flash LED will not compile:
    The source:
    #include <12f509.h>
    #define GP0 PIN_B0              // define GP pins
    #define GP1 PIN_B1
    #define GP2 PIN_B2
    #define GP3 PIN_B3
    #define GP4 PIN_B4
    #define GP5 PIN_B5

    #use delay (clock=4000000)      // oscillator frequency for delay_ms()

    // Config: ext reset, no code protect, no watchdog, 4MHz int clock
    #fuses MCLR,NOPROTECT,NOWDT,INTRC

    void main()
    {
       unsigned char    sGPIO = 0;  // shadow copy of GPIO

       while (TRUE) {
            sGPIO ^= 0b000010;      // flip shadow bit corresponding to GP1
            output_b(sGPIO);        // write to GPIO ("port B")

            delay_ms(500);          // delay 500ms
       }                            // repeat forever
    }

    the output:

    sdcc -I /usr/share/sdcc/include bc_l1-flash_led-ccs.c
    bc_l1-flash_led-ccs.c:42:2: error: invalid preprocessing directive #use
    bc_l1-flash_led-ccs.c:45:2: error: invalid preprocessing directive #fuses
    /usr/share/sdcc/include/12f509.h:2: warning 115: unknown or unsupported #pragma directive 'chip PIC12F509, core 12, code 1023, ram 7 : 0x3F'
    /usr/share/sdcc/include/12f509.h:5: warning 115: unknown or unsupported #pragma directive 'resetVector 0'
    /usr/share/sdcc/include/12f509.h:7: warning 115: unknown or unsupported #pragma directive 'config_def 0x0011'
    /usr/share/sdcc/include/12f509.h:17: warning 115: unknown or unsupported #pragma directive 'char OSCCAL @ 5'
    /usr/share/sdcc/include/12f509.h:18: warning 115: unknown or unsupported #pragma directive 'char GPIO @ 6'
    /usr/share/sdcc/include/12f509.h:19: warning 115: unknown or unsupported #pragma directive 'char TRISGPIO @ TRISB'
    /usr/share/sdcc/include/12f509.h:21: warning 115: unknown or unsupported #pragma directive 'bit GPWUF @ STATUS.7'
    /usr/share/sdcc/include/12f509.h:23: warning 115: unknown or unsupported #pragma directive 'bit GP0 @ GPIO.0'
    /usr/share/sdcc/include/12f509.h:24: warning 115: unknown or unsupported #pragma directive 'bit GP1 @ GPIO.1'
    /usr/share/sdcc/include/12f509.h:25: warning 115: unknown or unsupported #pragma directive 'bit GP2 @ GPIO.2'
    /usr/share/sdcc/include/12f509.h:26: warning 115: unknown or unsupported #pragma directive 'bit GP3 @ GPIO.3'
    /usr/share/sdcc/include/12f509.h:27: warning 115: unknown or unsupported #pragma directive 'bit GP4 @ GPIO.4'
    /usr/share/sdcc/include/12f509.h:28: warning 115: unknown or unsupported #pragma directive 'bit GP5 @ GPIO.5'
    bc_l1-flash_led-ccs.c:54: warning 112: function 'output_b' implicit declaration
    bc_l1-flash_led-ccs.c:56: warning 112: function 'delay_ms' implicit declaration
    bc_l1-flash_led-ccs.c:52: error 20: Undefined identifier 'TRUE'
    bc_l1-flash_led-ccs.c:54: error 101: too many parameters
    bc_l1-flash_led-ccs.c:56: error 101: too many parameters

    any ideas?

     
  • Maarten Brock
    Maarten Brock
    2011-08-18

    Please do not double post. It is a waste of your and our time.

     
  • Raphael Neider
    Raphael Neider
    2011-08-18

    SDCC is not a drop-in replacement for other PIC C compilers.
    Thus, you need to replace the compiler-specific #pragma, #use and #fuses with SDCC-style directives.
    Your 12f509.h is not a SDCC device header - SDCC does not support the 12f509 out-of-the-box. You need to adjust your header to match SDCC syntax (have a look at other PIC14 device headers delivered with SDCC).
    The PIC14/SDCC library does not include delay_ms() nor output_b(); even TRUE is not defined in SDCC's standard libraries.

    Here is a compiling example of how SDCC can be used to implement blinky for a supported device here: 12f675):

    /* Avoid polluting the global namespace with aliases for each pin. */
    #define NO_BIT_DEFINES
    /* Include SDCC-specific device header. */
    #include "pic12f675.h"
    /* Define some useful types -- might #include "inttypes.h" instead. */
    typedef unsigned char uint8_t;
    typedef unsigned short uint16_t;
    /* Define config word ("fuses"); see device header file for symbolic constants
     * or use integer literal (0x3fff, 0b11_1111_1111_1111 without underscores). */
    __code uint16_t __at(0x2007) __configword = _CPD_OFF & _CP_OFF & _BODEN_ON
        & _MCLRE_ON & _PWRTE_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT;
    /* Assign val to GPIO port. */
    void output_b(uint8_t val) {
        GPIO = val;
    }
    /* Adjust to your clock frequency (in Hz). */
    #define CLOCKFREQ   (4U*1000U*1000U)
    /* Instructions per millisecond. */
    #define INSNS_PER_MS    (CLOCKFREQ / 4000U)
    /* Delay loop is about 10 cycles per iteration. */
    #define LOOPS_PER_MS    (INSNS_PER_MS / 10U)
    void delay_ms(uint16_t ms) {
        uint16_t u;
        while (ms--) {
            /* Inner loop takes about 10 cycles per iteration + 4 cycles setup. */
            for (u = 0; u < LOOPS_PER_MS; u++) {
                /* Prevent this loop from being optimized away. */
                __asm nop __endasm;
            }
        }
    }
    void
    main (void)
    {
        uint8_t sGPIO = 0;          // shadow copy of GPIO
        while (1) { 
            sGPIO ^= 0b000010;      // flip shadow bit corresponding to GP1
            output_b(sGPIO);        // write to GPIO ("port B")
            delay_ms(500);          // delay 500ms
        }                           // repeat forever
    }
    

    You might want to ask for direct support for the 12f509 in SDCC - if it's not too different from an already supported device, that should be possible with reasonable effort.

     
  • Raphael Neider
    Raphael Neider
    2011-08-18

    Oh, by the way: The example code stored as "blinky.c" can be compiled using

    sdcc -mpic14 -p12f675 --use-non-free blinky.c
    
     
  • Maarten Brock
    Maarten Brock
    2011-08-18

    /* Define some useful types - might #include "inttypes.h" instead. */

    But SDCC does not come with an inttypes.h header file. It only has stdint.h. That is probably enough though.

     
  • William
    William
    2011-08-18

    this is not a double post! the first post was a different problem.

    Thanks for the suggestion. After installing HiTech, I get similar problems. I suspect it is the header files I have installed?

    Thanks for your time.