C51全局初始化及精确延时程序,51单片机精确延时程序

2023-06-07  

/*********************************************************************************************************
* 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


文章来源于:电子工程世界    原文链接
本站所有转载文章系出于传递更多信息之目的,且明确注明来源,不希望被转载的媒体或个人可与我们联系,我们将立即进行删除处理。