This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

help

hello my friendes.

please help me.
l have an error in my project : main.c(25746): error C8 code size exceeds 64K
Keil development tools for the XC16x, C16x, and ST10 Microcontroller
PK166 Professional Developer's Kit
please say
tanks very much ,




Parents
  • In global.h

    extern int glovar;
    

    In global.c

    int glovar = 123;
    

    This type of construct should work on any remotely functional C compiler from the last 3 decades.

    If you have an error you're going to need to be a lot more explicit about the details reported by the compiler and/or linker.

    Review some large project on GitHub to see how people successfully partition code.

    Having lots of random global variables is something people in general have tried to limit in the past. Consider using structures to collect things together, and review if the use of scoped auto/local variables can reduce the need to commit resources across the life of the application.

Reply
  • In global.h

    extern int glovar;
    

    In global.c

    int glovar = 123;
    

    This type of construct should work on any remotely functional C compiler from the last 3 decades.

    If you have an error you're going to need to be a lot more explicit about the details reported by the compiler and/or linker.

    Review some large project on GitHub to see how people successfully partition code.

    Having lots of random global variables is something people in general have tried to limit in the past. Consider using structures to collect things together, and review if the use of scoped auto/local variables can reduce the need to commit resources across the life of the application.

Children
  • You'd have thought that someone working on such a large, "Industry" project would understand this - or, at least, have co-workers who could provide guidance & support ...

  • I made a small mistake that I defined the variables in the original file and immediately gave them the initial value, then I copied these variables the same way in another file, I used the "external" for the variables in the attached file. But I forgot that these variables should not be initialized in two separate files. The reason for this was my rush in programming. In this case, the compiler provides a link error and states that this variable (symbol) is defined in several files and is not capable of linking.

    in main file

    
    #include <>
    #include ""
    
    // global variable
    unsigned int gtmp1 = 0,gtmp2 = 0,gtmp3 = 0;
    unsigned short adc_data[16] = {0};
    
    void main(){
       unsigned int tmp1,tmp2,tmp3;
    
    while(true){
     ......
     ......
    
     } // end of while loop function
    } // end of main function
    
    
    

    in adc header file

    
    #ifndef __ADC
    #define __ADC
    
    // Prototypes - Note: ISRs prototyped above.
    void adc_init(void);
    void get_adc(char chan1, char chan2);
    void adc_pec_init(unsigned short adc_data[], unsigned char num);
    
    #endif
    
    

    in adc source file

    #include "adc.h"
    
    //
    extern unsigned short adc_data[16] = {0};
    
    
    //
    void adc_init(void) {
    
      ADCIC      =  0x007F;      // 0x0078;
      P5DIDIS    =  0xFFFF;      // load Port 5 digital input disable register
      ADDAT      =  0x0000;      // load A/D converter result register
      ADDAT2     =  0x0000;      // load A/D converter 2 result register
      ///  - auto scan continuous conversion mode is selected
      ///  - repeatedly converts channel 15
      ///  - ADC start bit is set
      ///  - 'wait for ADDAT read mode' is disabled
      ///  - converter basic clock tbc is fcpu / 4
      ///  - sample time tsc is tbc * 8
      ADCON     =  0x00BF;      // load ADC control register
      IEN = 1;                  // Global Interrupt enable
    }
    
    //
    void adc_pec_init(unsigned short adc_data[], unsigned char num){
      ///  - auto scan continuous conversion mode is selected
      ///  - repeatedly converts channel 15
      ///  - ADC start bit is set
      ///  - 'wait for ADDAT read mode' is disabled
      ///  - converter basic clock tbc is fcpu / 4
      ///  - sample time tsc is tbc * 8
    
      ///  -----------------------------------------------------------------------
      ///  Configuration of the used ADC Interrupts:
      ///  -----------------------------------------------------------------------
      ///  - Conv service request node configuration:
      ///  - Conv interrupt priority level (ILVL) = 14
      ///  - Conv interrupt group level (GLVL) = 0
    
      /// Use PEC channel 0 for ADC Conv INT:
      ///  - decrement counter
      ///  - increment destination pointer
      ///  - transfer a word
      // load PECC0 control register
      PECC7  =  0x0200 | (num & 0xFF); // ( (sizeof(adc_data) / sizeof(adc_data[0])) );
      SRCP7  =  (unsigned int)&ADDAT;  //
      DSTP7  = _sof_(adc_data);        //
    
    } //  End of function ADC_Init
    
    // example :
    // adc_pec_init(adc_data, sizeof(adc_data));
    //
    void get_adc(void){
    
    
    
    
    }
    
    

    As you can see, the variable one in both files has an initial value that should be in the second file without an initial value and should be modified as follows.

    in adc source file

    #include "adc.h"
    
    
    // modified
    extern unsigned short adc_data[16];
    
    
    //
    void adc_init(void) {
    
      ADCIC      =  0x007F;      // 0x0078;
      P5DIDIS    =  0xFFFF;      // load Port 5 digital input disable register
      ADDAT      =  0x0000;      // load A/D converter result register
      ADDAT2     =  0x0000;      // load A/D converter 2 result register
      ///  - auto scan continuous conversion mode is selected
      ///  - repeatedly converts channel 15
      ///  - ADC start bit is set
      ///  - 'wait for ADDAT read mode' is disabled
      ///  - converter basic clock tbc is fcpu / 4
      ///  - sample time tsc is tbc * 8
      ADCON     =  0x00BF;      // load ADC control register
      IEN = 1;                  // Global Interrupt enable
    }
    
    //
    void adc_pec_init(unsigned short adc_data[], unsigned char num){
      ///  - auto scan continuous conversion mode is selected
      ///  - repeatedly converts channel 15
      ///  - ADC start bit is set
      ///  - 'wait for ADDAT read mode' is disabled
      ///  - converter basic clock tbc is fcpu / 4
      ///  - sample time tsc is tbc * 8
    
      ///  -----------------------------------------------------------------------
      ///  Configuration of the used ADC Interrupts:
      ///  -----------------------------------------------------------------------
      ///  - Conv service request node configuration:
      ///  - Conv interrupt priority level (ILVL) = 14
      ///  - Conv interrupt group level (GLVL) = 0
    
      /// Use PEC channel 0 for ADC Conv INT:
      ///  - decrement counter
      ///  - increment destination pointer
      ///  - transfer a word
      // load PECC0 control register
      PECC7  =  0x0200 | (num & 0xFF); // ( (sizeof(adc_data) / sizeof(adc_data[0])) );
      SRCP7  =  (unsigned int)&ADDAT; //
      DSTP7  = _sof_(adc_data);       //
    
    } //  End of function ADC_Init
    
    // example :
    // adc_pec_init(adc_data, sizeof(adc_data));
    
    // This function is very large
    void get_adc(void){
    
    
    
    
    }
    
    

    A bit of rush in programming and carelessness causes a small error.
    Dear friend, Regards, Thank you for your guidance.