conversion from Keil to SDCC for AT89C51ED2

don89c
2007-08-06
2013-03-12
  • don89c
    don89c
    2007-08-06

    I'm attempting to use SDCC (Version #4 May 31, 2007) to compile a C program previously compiled using Keil demo compiler and run successfully on the target (AT89C51ED2).  I downloaded the AT89C51xD2 header file for the SDCC compiler from the Atmel web site.  Whe I compile the program, I receive three error messages (one each for lines 110, 116, and 118), which is "error 146:  two or more storage classes in declaration for 'type_specifier declaration_specifiers'  Lines 110, 116 and 118 are included below:

    107    // ---------- Data & I/O Variables ----------
    108
    109    unsigned char data g_uc_SPI_data=0;
    110    bit data g_b_SPI_extracted=0;   
    111
    112    unsigned char data g_uc_AC_volt_reading=0; // AC voltage sensor reading value 8-bit
    113
    114    unsigned char data g_uc_detector_AB_id=0; // detector A & B id values 4-bit each
    115
    116    bit data g_b_GFI_bit=0; // ground fault interrupt bit, input (1=GFI circuit trip)
    117
    118    bit data g_b_OverTemp_bit=1; // over temperature bit, output (1=no power)
    119
    120    unsigned char data g_uc_config_bits=0x00; // general configuration bits (6 upper bits)

    I also get three warnings (lines 299, 300 and 461), which is warning 180: using ~ on bit/bool/unsigned char variables can give unexpected results due to promotion to int.  The lines are included below:

    297    void refresh_stat_LEDs()
    298    {
    299    LED1_PORT_BIT=~g_b_OverTemp_bit;
    300    LED2_PORT_BIT=~g_b_GFI_bit;
    301    LED3_PORT_BIT=~0; // unused status LED
    302    }

    461    LED0_PORT_BIT=~LED0_PORT_BIT;

    I'm a newbie at this.  So, although I've searched for more information on the web regarding these errors, I'm still not sure of how to fix these errors/warnings.

    By the way, I'm compiling simply using the command line text:  sdcc TestMIC.c  (which is the name of my file).

    Any help or suggestions would be appreciated!

     
    • Instead of:

      //This confuses SDCC.  Is the variable a bit or an integer in data?
      bit data g_b_SPI_extracted=0;

      Use:

      bit g_b_SPI_extracted=0;

      For the warnings, instead of

      LED1_PORT_BIT=~g_b_OverTemp_bit;

      Use:

      LED1_PORT_BIT=!g_b_OverTemp_bit;

      Which should generate this assembly code:
      mov    c,_g_b_OverTemp_bit
      cpl    c
      mov    _LED1_PORT_BIT,c

      Jesus

       
    • don89c
      don89c
      2007-08-07

      Jesus,

      The variable is a bit.

       
    • don89c
      don89c
      2007-08-08

      Jesus,

      Thanks.  The suggestions you made seemed to have worked.  I can now compile without errors or warnings.  I was able to use packihx to create the hex file from the ihx file and download to the AT89C51.  At least part of my program is now working (blinking of LED).  The serial communication, however, does not work.  I'm using an ISR for this.  I don't have a prototype statement for the interrupt function in my code (which consists only of a header file (.h) and the program file (.c)).  The SDCC manual is a bit confusing as to whether the prototype statement is needed for a program in which the interrupt function and main() are in the same file.  Any other suggestions?

      Thanks!

       
    • Maarten Brock
      Maarten Brock
      2007-08-12

      When the interrupt function and main() are in the same file, a prototype of the ISR should not be necessary.