Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
10/30/05 17:53
Read: times


 
#103143 - Using Multiple C files in SDCC
We are using SDCC for development of 8052 compatible systems. We are not clear despite reading SDCC manual , how to access the variables defined in master C file from another C file and later compile & link them seamlessly. Below is the example.


//master.c file which contains the definitions of all the variables and functions.

# include xyz.h
unsigned char x1,x2,x3,x4;
unsigned int i1,i2,i3;

sbit at 0x80 disp1;
sbit at 0x81 disp2;
sbit at 0xb4 prg_sw;
sbit at 0xb5 set_sw;
sbit at 0xb6 ret_sw;
sbit at 0xb7 inc_sw;

bit in_01;
bit in_02;

void control_logic(void); //prototype declaration of a function which is in another file
//named control.c
void timer1(void)
{
x1++;
in_01=!disp1; //just a sample function which is to be accessed by another
} // C file control.c

void counter1(void)
{
i1=x1*x2;
in_02=!disp2; //just a sample function which is to be accessed by another
} // C file control.c



void main(void)
{
timer1();
counter1();
control_logic();
}


//another C file control.c which makes use of functions defined in master.c

void timer2(void)
{
x2++;
prg_sw=set_sw;
}
void counter2(void)
{
i2=x3+x4;
}


void control_logic(void) //this function is used by master.c
{
ret_sw=inc_sw;
timer1();
counter1();
timer2();
counter2();
}



We are not clear how to make the use of functions & variables defined in one C file in to another C file. Please note that we are compiling these files with SDCC as below.

Sdcc -c control.c

Sdcc -c master.c

Sdcc master.rel control.rel


Please, advise on this problem. Links to practicle examples will be very useful.
Thanks.



Anju Vaghasia




List of 12 messages in thread
TopicAuthorDate
Using Multiple C files in SDCC            01/01/70 00:00      
   Not about the compiler            01/01/70 00:00      
   Nothing to do with SDCC            01/01/70 00:00      
   The joy of C            01/01/70 00:00      
      Sloppy terminology            01/01/70 00:00      
         Using Multiple C files in SDCC            01/01/70 00:00      
            Laziness            01/01/70 00:00      
            example            01/01/70 00:00      
   globals are generally bad ...            01/01/70 00:00      
      "Generally" being the important word!            01/01/70 00:00      
         re Globals            01/01/70 00:00      
      static            01/01/70 00:00      

Back to Subject List