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

Is it possible to define an intrinsic function in C51?

Hi, i am interested in knowing if the C51 compiler is able to define initrisic functions...

I mean if there is a way I can define a function that is expanded inline in the assembly language and there are no CALLs or RETs generated for it.

I know there are some built in intrisic funtions in C51 like _iror_ _irol_ and the like, but i wonder if it is possible to define new ones.

Any informations on this?

Parents
  • Ok, this for example:

    file1.c

    UCHAR T1RLH = 0;
    UCHAR T1RLL = 0;
    
    void timer1_interrupt (void) interrupt 3
    {
         TL1 = T1RLL;
         TH1 = T1RLH;
         //Do whatever else you need...
         Time++;
    }
    

    file1.h
    #define init_timer1(reload) TMOD = ((TMOD & 0x0F)| 0x10);\ 
                                 T1RLH = ((reload) / 0x100);\ 
                                 T1RLL = ((reload) % 0x100);\ 
                                 TH1 = T1RLH;\ 
                                 TL1 = T1RLL
    

    file2.c
    #include "file1.h"
    void main(void)
    {
       init_timer1(20000);
    }
    

    What i want from this code is that i can initialize the timer with a macro expansion 'remember readability' and in this way it is not possible, why? T1RLH and T1RLL are variables defined in file1.c and of course are out of scope in file2.c the only way to avoid this is declaring them as public symbols in file1.h that would become:

    file1.h

    #define init_timer1(reload) TMOD = ((TMOD & 0x0F)| 0x10);\ 
                                 T1RLH = ((reload) / 0x100);\ 
                                 T1RLL = ((reload) % 0x100);\ 
                                 TH1 = T1RLH;\ 
                                 TL1 = T1RLL
    
    extern UCHAR T1RLH;
    extern UCHAR T1RLL;
    

    Now this is for a simple timer initialization routine, if things get a little more complicated then you might end up with several 'extern' declarations that could be avoided if the 'init_timer1' macro could be defined as an inline function in file1.c

    Agree?

Reply
  • Ok, this for example:

    file1.c

    UCHAR T1RLH = 0;
    UCHAR T1RLL = 0;
    
    void timer1_interrupt (void) interrupt 3
    {
         TL1 = T1RLL;
         TH1 = T1RLH;
         //Do whatever else you need...
         Time++;
    }
    

    file1.h
    #define init_timer1(reload) TMOD = ((TMOD & 0x0F)| 0x10);\ 
                                 T1RLH = ((reload) / 0x100);\ 
                                 T1RLL = ((reload) % 0x100);\ 
                                 TH1 = T1RLH;\ 
                                 TL1 = T1RLL
    

    file2.c
    #include "file1.h"
    void main(void)
    {
       init_timer1(20000);
    }
    

    What i want from this code is that i can initialize the timer with a macro expansion 'remember readability' and in this way it is not possible, why? T1RLH and T1RLL are variables defined in file1.c and of course are out of scope in file2.c the only way to avoid this is declaring them as public symbols in file1.h that would become:

    file1.h

    #define init_timer1(reload) TMOD = ((TMOD & 0x0F)| 0x10);\ 
                                 T1RLH = ((reload) / 0x100);\ 
                                 T1RLL = ((reload) % 0x100);\ 
                                 TH1 = T1RLH;\ 
                                 TL1 = T1RLL
    
    extern UCHAR T1RLH;
    extern UCHAR T1RLL;
    

    Now this is for a simple timer initialization routine, if things get a little more complicated then you might end up with several 'extern' declarations that could be avoided if the 'init_timer1' macro could be defined as an inline function in file1.c

    Agree?

Children
No data