This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

delay_us(10)与delay_us(a),long a=10 效果不同的问题

问题描述: delay_us(a),long a=10  比   delay_us(10)用定时器实测前者为15us,后者为10us   28377s,delay_us也已经定义到RAM里了,测试方法:程序在线调试通过一个定时器在CCS窗口中看的,又试了delay_us(a),long a=20  比   delay_us(20)也是多5us. a定义成int long float 都试了,都是这个现象。 delay_us是汇编写的,

请问为什么会有这样的现象?还是说汇编写的代码不可以这样用一个变量作为参数,只能写成 10 20之类的数字?

求解。

  • 您指的是下面的语句?

    //
    // DO NOT MODIFY THIS LINE.
    //
    #define DELAY_US(A) F28x_usDelay(((((long double) A * 1000.0L) / (long double)CPU_RATE) - 9.0L) / 5.0L)

    这个是个宏定义,您直接给A赋值即可
  • 您好。是这个。请教一下您说的直接赋值是什么意思?我 比较了 F28x_usDelay(((((long double) 10 * 1000.0L) / (long double)CPU_RATE) - 9.0L) / 5.0L) 和F28x_usDelay(((((long double) a * 1000.0L) / (long double)CPU_RATE) - 9.0L) / 5.0L) ,long a=10,发现前者是10us,后者是15us
  • ;//  The C assembly call from the DELAY_US(time) macro will
    ;//  look as follows:
    ;//  extern void Delay(long LoopCount);
    ;//        MOV   AL,#LowLoopCount
    ;//        MOV   AH,#HighLoopCount
    ;//        LCR   _Delay
    ;//  Or as follows (if count is less then 16-bits):
    ;//        MOV   ACC,#LoopCount
    ;//        LCR   _Delay

    ;There is a 9/10 cycle overhead and each loop
    ;takes five cycles. The LoopCount is given by
    ;the following formula:
    ; DELAY_CPU_CYCLES = 9 + 5*LoopCount
    ; LoopCount = (DELAY_CPU_CYCLES - 9) / 5
    ; The macro DELAY_US(A) performs this calculation for you

    您可以对照一下下图的反汇编

x 出现错误。请重试或与管理员联系。