延时函数、数码管显示头文件(单片机)

延时函数、数码管显示头文件(单片机)

在单片机程序的编写过程中,我们常常要写一段相同的代码,此时我们可以给它做成头文件封装起来,在使用的时候直接调用,在此文章中以常用的延时函数和数码管显示函数为例

数码管显示

typedef unsigned char shumaguan_dehaha;
sbit nageshumaguan_1=P2^2;
sbit nageshumaguan_2=P2^3;
sbit nageshumaguan_3=P2^4;
shumaguan_dehaha code shumaguan[18]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
     0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x38,0x80};

延时函数

#include<reg52.h>
typedef unsigned int delaytime;
 delaytime     delaytime_1;
 void delay  (delaytime delaytime_1 )
{
 delaytime x,y;
 for(x=delaytime_1; x>0; x--)
 for(y=110; y>0; y--)
  {
   ;//???1ms
  }
}
发布了30 篇原创文章 · 获赞 29 · 访问量 9299

猜你喜欢

转载自blog.csdn.net/qq_44629109/article/details/102827016