#include<reg52.h> //包含头文件,一般情况不需要改动,头文件包含特殊功能寄存器的定义
#define DataPort P0 //定义数据端口 程序中遇到DataPort 则用P0 替换
sbit LATCH1=P2^2;//定义锁存使能端口 段锁存
sbit LATCH2=P2^3;// 位锁存
unsigned char code dofly_DuanMa[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};// 显示段码值0~F
unsigned char code dofly_WeiMa[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//分别对应相应的数码管点亮,即位码
void Delay(unsigned int t); //函数声明
/*------------------------------------------------
主函数
------------------------------------------------*/
main()
{
unsigned char i=0,num;
unsigned int j;
while(1)
{
DataPort=dofly_WeiMa[i]; //取位码
LATCH2=1; //位锁存
LATCH2=0;
DataPort=dofly_DuanMa[num+i]; //取显示数据,段码
LATCH1=1; //段锁存
LATCH1=0;
Delay(200); // 扫描间隙延时,时间太长会闪烁,太短会造成重影
i++;j++;
8位数码管动态扫描显示变化数据
最新推荐文章于 2022-10-27 17:11:47 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)