如何在C

时间:2016-04-16 01:53:13

标签: c time microcontroller elapsedtime nxp-microcontroller

我正在开发一个在MPC5748G上运行的应用程序,我想测量代码块或函数内部之间的经过时间。

我使用了以下代码,但它似乎只适用于Windows,但我想为微控制器使用MPC。

    /* Program to demonstrate time taken by function fun() */
#include <stdio.h>
#include <time.h>

// A function that terminates when enter key is pressed
void fun()
{
    printf("fun() starts \n");
    printf("Press enter to stop fun \n");
    while(1)
    {
        if (getchar())
            break;
    }
    printf("fun() ends \n");
}

// The main program calls fun() and measures time taken by fun()
int main()
{
    // Calculate the time taken by fun()
    clock_t t;
    t = clock();
    fun();
    t = clock() - t;
    double time_taken = ((double)t)/CLOCKS_PER_SEC; // in seconds

    printf("fun() took %f seconds to execute \n", time_taken);
    return 0;
}

当然我没有在MCU端使用printf,而是使用调试器(跟踪32)来读取值......

非常感谢任何帮助

0 个答案:

没有答案