Help with sdcclib

  • Ashwin Vijayakumar

    I am back again with yet another doubt. Piklab is giving me nightmares but I still insist to stick on to it because of it's support to PIC2 Debug programmer. Here's something I am stuck with:

    Consider the following codes: (Please note that the codes don't make any sense but are just to delineate my doubts)


    #include "main.h"

    void main(void)


    #include "main.h"

    void delay_us(unsigned char d)
        unsigned char i,j;


    void delay(unsigned char delay)
        unsigned char i,j;



    #include "main.h"

    void lcd_init()
        RS = 1;
        EN = 0;

    void lcd_char(unsigned char data)
        RS = 1;
        PORTA = data;


    #include <pic18f675.h>

    void delay_us(unsigned char d);
    void delay(unsigned char delay);

    #define RS = PORTA.1
    #define EN = PORTA.2

    void lcd_init();
    void lcd_char(unsigned char data);

    Inorder to create a library of lcd.c and delay.c, I understand that I am supposed to compiler these two files using sdcc -c lcd.c and sdcc -c delay.c and then create a library using sdcclib -a delaylcd.lib delay.rel lcd.rel. I am stuck here.

    1. How do I pass RS and EN definitions to lcd.c?
    2. Once I have the library, how to I compile the project (main.c)?

    • Raphael Neider

      Raphael Neider - 2008-07-09

      1. You cannot pass bits/fields of a bitfield to functions in C/SDCC. Either pass the address of the SFR and a mask, teach your function the position of the relevant bit and only pass the address of the SFR or use global macros (as you did, though you want PORTA.RA1 rather than .1 and put them in some header file for use in all .c files).

      2. The pic targets do not use sdcclib. We use gputils (most notably gpasm, gplink, and occasionally gplib). Try
         sdcc $CFLAGS -c part1.c
         sdcc $CFLAGS -c part2.c # and so on for all .c files
         sdcc $C_LDFLAGS part1.o part2.o # and all other previously generated .o files

         You might have to append libc18f.lib libio18f675.lib and/or libm18f.lib to the end of the .o file list if you use any library routines.

      Hoping that helps,


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