我想要配置一個delay時間函式,我根據以下範例進行配置,但我不知道for迴圈的延遲時間是幾秒,假設我有三種延遲時間 10s、10ms、10us ,如何正確使用for迴圈函式,使他們蒙垢正確的延遲,或是有沒有其他函式可以進行延遲,而這些函式又該如何使用?
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時間函式,我根據以下範例進行配置,但我不知道for迴圈的延遲時間是幾秒,假設我有三種延遲時間 10s、10ms、10us ,如何正確使用for迴圈函式,使他們蒙垢正確的延遲,或是有沒有其他函式可以進行延遲,而這些函式又該如何使用?
或者您可以使用下面的方式
/* DriverLib Includes */ #include <ti/devices/msp432p4xx/driverlib/driverlib.h> /* Standard Includes */ #include <stdint.h> #include <stdbool.h> int main(void) { /* Stop Watchdog */ MAP_WDT_A_holdTimer(); int mclk; while(1) { __delay_cycles(1000); mclk = CS_getMCLK(); } }
__delay_cycles 并不是真正的函数, 只是提供编译器内联展开,该函数并不支持变量参数, 其参数只能是常数.
函数原型
__intrinsic void __delay_cycles(unsigned long __cycles);
该内部函数实现__cycles个CPU周期的延时