• 我的C51延时程序


    基础延时程序经过了严格计算得出的,保证精准。

    #include <intrins.h>
    
    /********************************
    *            基础延时           *
    ********************************/
    
    //适用于12MHz晶振,如果不需要请注释掉
    void delay1s(void)   //延时1秒 误差 0us
    {
        unsigned char a,b,c;
        for(c=46;c>0;c--)
            for(b=152;b>0;b--)
                for(a=70;a>0;a--);
        _nop_();  //if Keil,require use intrins.h
    }
    void delay1ms(void)   //延时1毫秒 误差 0us
    {
        unsigned char a,b;
        for(b=199;b>0;b--)
            for(a=1;a>0;a--);
    }
    
    //适用于11.0592MHZ晶振,如果不需要请注释掉
    void delay1s(void)   //误差 -0.00000000024us
    
    {
        unsigned char a,b,c;
        for(c=95;c>0;c--)
            for(b=26;b>0;b--)
                for(a=185;a>0;a--);
    }
    void delay1ms(void)   //误差 -0.651041666667us
    {
        unsigned char a,b;
        for(b=4;b>0;b--)
            for(a=113;a>0;a--);
    }

    常用延时才是日常应用的主角,通过调用基础延时来实现,误差很小。

    /********************************
    *            常用延时           *
    ********************************/
    void delay(unsigned int time)	//延时time秒
    {
    	do
    		delay1s();
    	while(--time);
    }
    
    void delay_ms(unsigned int time)	//延时time毫秒
    {
    	do
    		delay1ms();
    	while(--time);	 
    }					  
  • 相关阅读:
    python中列表排序的方法
    pyrhon3中字符串方法
    python数据探索与数据与清洗概述
    2020年日期表-python实现
    python中字符串离散化的例子
    python中常见的日期处理方法
    如何简单地理解Python中的if __name__ == '__main__'
    我的老爸老了
    关于
    关于
  • 原文地址:https://www.cnblogs.com/catmelo/p/2255976.html
Copyright © 2020-2023  润新知