Help with sdcclib

Help
2008-06-28
2013-03-12
  • Hi,
    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)

    /*--------main.c---------*/

    #include "main.h"

    void main(void)
    {
        lcd_init();
        delay_us(10);
        lcd_char(0x30);
    }

    /*--------delay.c---------*/

    #include "main.h"

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

        for(i=0;i<delay;i++)
            for(j=0;j<delay;j++)
    }

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

        for(i=0;i<delay;i++)
            delay_us(100);
    }

    /*--------lcd.c---------*/

    #include "main.h"

    void lcd_init()
    {
        RS = 1;
        delay_us(400);
        EN = 0;
    }

    void lcd_char(unsigned char data)
    {
        RS = 1;
        delay_us(400);
        PORTA = data;
    }

    /*--------main.h---------*/

    #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,
      Raphael