×
单片机 > 单片机程序设计 > 详情

C51全局初始化及精确延时程序

发布时间:2020-06-19 发布时间:
|

/*********************************************************************************************************
*                                          Initialization Program
*                                               QiZhao,2007
*                                           All Rights Reserved
* File      : initial.h
* By        : QiZhao
* Contact   : zq1987731@163.com
*
* Version   : V2.1 γ
* Corrector : QiZhao
* Date      : 2008.2.1 (Last modified)
*
* Remarks   : Common set of macro definitions keyword, and by setting controlled
*             crystal oscillator frequency precision delay subroutine.
*
*********************************************************************************************************/

    #ifndef   _initial_h_
    #define   _initial_h_

/*********************************************************************************************************
*
*                                         Global macro definitions
*
*********************************************************************************************************/
    #include               // AT89S52
    #include              // Absolute address access
    #include              // Related to the string
    #include             // Related to Assembly Language
    #include               // Unicode conversion
    #include                // Mathematics functions packet
    #include               // Standard input or output
    #include              // Memory Management

    #define TRUE    1
    #define FALSE   0
    #define bool    bit             // Boolean variable
    #define uchar   unsigned char
    #define uint    unsigned int
    #define ulong   unsigned long

    #define FOSC    12000000UL      // The frequency of crystal
    #define NOP     _nop_();

/*********************************************************************************************************
*
*                                          Accurate delay(5us,10us)
*
*********************************************************************************************************/

    void delay10us (void)            // FOSC->12000000
    {
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
    }

    void delay5us (void)             // FOSC->12000000
    {
        NOP
    }

/*********************************************************************************************************
*
*                                          Accurate delay(1ms~255ms)
*
*********************************************************************************************************/

    #define WAITE_HI (FOSC / 2 / 12 / 1000 >> 8 )
    #define WAITE_LOW (FOSC / 2 / 12 / 1000 & 0xFF)

    void delayms (uchar time)
    {
        do
        {
            uchar j;

            #if WAITE_HI != 0
                j = 0;
                {
                    uchar i;
                    for(i = WAITE_HI; i > 0; i--)
                    {
                        while (--j);
                    }
                }
            #endif

            #if WAITE_LOW != 0
                j = WAITE_LOW;
                while (--j);
            #endif

        }while (--time);
    }

/*********************************************************************************************************
*
*                                            Includes not repeat
*
*********************************************************************************************************/

    #endif


关键字:C51  全局初始化  精确延时

『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
单片机中高阻态的实质及意义