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

assembler macro included in C macro

l.s.,

For delay purposes I need NOP's in an assembler macro, the code below doesn't do the trick. Thread 2267.htm doesn't help me either. A C macroloop, with e.g. DELAY(a); a = 10, slows the execution down too much. Can Anyone help me?

thanks, ***

#define DELAY(a) \
{ \
volatile unsigned b; \
for(b = 0; b < a; b++) \
{ \
} \
}

#define DELAYNOP \
{ \
#pragma asm \
NOP \
NOP \
NOP \
NOP \
NOP \
NOP \
NOP \
#pragma endasm \
}

Parents
  • ***,

    The simplest form of a delay is:

    void Delay (unsigned char Cycles)
    {
       // The following generates:
       // C0001: DJNZ R7,C0001   ; 1 to 256 times
    
       while (--Cycles);
    }
    

    If you want to avoid the call use:

    #define Delay(Cycles) { while(--Cycles); }
    

    If you need a longer delay modify the function to be:

    #include <intrins.h>
    
    void Delay (unsigned char Cycles)
    {
       do {
          _nop_();  _nop_(); ...
       } while (--Cycles);
    }
    

Reply
  • ***,

    The simplest form of a delay is:

    void Delay (unsigned char Cycles)
    {
       // The following generates:
       // C0001: DJNZ R7,C0001   ; 1 to 256 times
    
       while (--Cycles);
    }
    

    If you want to avoid the call use:

    #define Delay(Cycles) { while(--Cycles); }
    

    If you need a longer delay modify the function to be:

    #include <intrins.h>
    
    void Delay (unsigned char Cycles)
    {
       do {
          _nop_();  _nop_(); ...
       } while (--Cycles);
    }
    

Children
No data