C51全局初始化及精确延时程序,51单片机精确延时程序
关键字:单片机延时程序
/*********************************************************************************************************
* 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.
*
*********************************************************************************************************/
* 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_
#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
*
* Global macro definitions
*
*********************************************************************************************************/
#include
#include // Absolute address access
#include
#include
#include
#include
#include
#include
#define TRUE 1
#define FALSE 0
#define bool bit // Boolean variable
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
#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_();
#define NOP _nop_();
/*********************************************************************************************************
*
* Accurate delay(5us,10us)
*
*********************************************************************************************************/
*
* Accurate delay(5us,10us)
*
*********************************************************************************************************/
void delay10us (void) // FOSC->12000000
{
NOP
NOP
NOP
NOP
NOP
NOP
}
{
NOP
NOP
NOP
NOP
NOP
NOP
}
void delay5us (void) // FOSC->12000000
{
NOP
}
{
NOP
}
/*********************************************************************************************************
*
* Accurate delay(1ms~255ms)
*
*********************************************************************************************************/
*
* Accurate delay(1ms~255ms)
*
*********************************************************************************************************/
#define WAITE_HI (FOSC / 2 / 12 / 1000 >> 8 )
#define WAITE_LOW (FOSC / 2 / 12 / 1000 & 0xFF)
#define WAITE_LOW (FOSC / 2 / 12 / 1000 & 0xFF)
void delayms (uchar time)
{
do
{
uchar j;
{
do
{
uchar j;
#if WAITE_HI != 0
j = 0;
{
uchar i;
for(i = WAITE_HI; i > 0; i--)
{
while (--j);
}
}
#endif
j = 0;
{
uchar i;
for(i = WAITE_HI; i > 0; i--)
{
while (--j);
}
}
#endif
#if WAITE_LOW != 0
j = WAITE_LOW;
while (--j);
#endif
j = WAITE_LOW;
while (--j);
#endif
}while (--time);
}
}
/*********************************************************************************************************
*
* Includes not repeat
*
*********************************************************************************************************/
*
* Includes not repeat
*
*********************************************************************************************************/
#endif
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。
举报投诉
发布评论请先 登录
相关推荐
51系列单片机复位的作用是什么
51系列单片机是一种广泛应用的微控制器,其复位功能对于系统的稳定运行至关重要。 一、51系列单片机复位的作用 系统初始化 当
51单片机定时器定时1秒程序流水灯结果分析
51单片机是一种广泛应用的嵌入式微控制器,具有高性能、低功耗、易扩展等优势。在实际应用中,定时器常用于定时操作,如控制程序运行时间、生成精确的时间延
keil5mdk怎么编写51单片机程序
可能需要引入一些库文件,以便使用库文件中的函数和宏定义。这些库文件可以提供对单片机特定功能的支持,如延时函数、串口通讯函数等。 初始化设备:在程序的开始部分,你需要对相关硬件设备进行
请问51单片机for需要延时是怎样计算延时的?
请问有谁知道51单片机for语句延时是怎么计算延时的?
delayms(unsigned uchar ij)
{
for(i=1000;i>0;i--)
for(j=110;j&
发表于 10-31 07:35
评论