zoukankan      html  css  js  c++  java
  • 我的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);	 
    }					  
  • 相关阅读:
    html 中 url、scr、href、rel、rev
    MIME 和文件扩展名
    视频文件的容器格式和编码格式
    原型与原型链
    属性特征
    可选参数
    函数的定义(函数是值)
    闭包
    实现异步加载js文件及加载完成后回调
    前端工程打开速度优化的循序渐进总结
  • 原文地址:https://www.cnblogs.com/catmelo/p/2255976.html
Copyright © 2011-2022 走看看