How to create a delay function in Keil uVision?

∥☆過路亽.° 提交于 2019-12-07 15:09:52

问题


Arduino have a delay(ms) function to pause the program for certain amount of time. It is very accurate in millisecond.

I have a delay function in C used in Keil uVision for AT89C5131 microp:

void delay( unsigned long duration)
{
    while ( ( duration -- )!= 0);
}

This does some delay job but the long value is not accurate like Arduino.

Is there a way to create a function that works like delay() function in Arduino?

The crystal is running at 24Mhz.

Any help will be appreciated.


回答1:


If you want to do busy wait, this is how it's done in Keil:

#pragma O0
void wait(volatile uint32_t cnt) {
    while(cnt--)
        _nop_();
}

http://www.keil.com/support/docs/606.htm




回答2:


Will, I think you can use a Multi-cycle codes, try to add some for(); and I think that if you need a long delay(like some sec.) in 51 MCU, I guess it doesn't need a very good accurate.



来源:https://stackoverflow.com/questions/21553964/how-to-create-a-delay-function-in-keil-uvision

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!