多位数码管

发布时间:2024年01月06日

工具

1.Proteus 8 仿真器

2.keil 5 编辑器

原理图

讲解

多位数码管不论是共阳还是共阴都有着段选(显示内容)和位选(显示位置)引脚

共阳数码管
16进制显示16进制显示
0xC000x88A
0xF910x83b
0xA420xC6C
0xB030xA1d
0x9940x86E
0x9250x8EF
0x8260x89H
0xF870xC7L
0x8080xBF-
0x9090x7F.

代码

1.只位选最低位,段选循环显示

#include <reg52.h>
#include "DELAY.h"

sbit DLE = P2^0; //段选
sbit WLE = P2^1; //位选
//段
unsigned char Darr[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E,0x89,0xC7,0xBF,0x7F};

main(void) 
{ 
	while(1)
	{
		unsigned char i;
		for(i=0;i<20;i++)
		{
			P0 = Darr[i];  
			DLE = 1;
			DLE = 0; 	 //段选锁存
			P0 = 0x01;
			WLE = 1;  
			WLE = 0;     //位选锁存
			delay_ms(100);
		}
	}
} 

2.按位依次显示0~7

#include <reg52.h>
#include "DELAY.h"

sbit DLE = P2^0; //段选
sbit WLE = P2^1; //位选
//段
unsigned char Darr[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E,0x89,0xC7,0xBF,0x7F};

main(void) 
{ 
	while(1)
	{
		unsigned char i;
		for(i=0;i<8;i++)
		{
			P0 = Darr[i];  
			DLE = 1;
			DLE = 0; 	 //段选锁存
			P0 = 0x01<<1;
			WLE = 1;  
			WLE = 0;     //位选锁存
			delay_ms(100);
		}
	}
} 

3.全部显示(实际上是2的基础上刷新的快了而已并不是同时显示)

#include <reg52.h>
#include "DELAY.h"

sbit DLE = P2^0; //段选
sbit WLE = P2^1; //位选
//段
unsigned char Darr[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E,0x89,0xC7,0xBF,0x7F};

main(void) 
{ 
	while(1)
	{
		unsigned char i;
		for(i=0;i<8;i++)
		{
			P0 = 0x00; 
			delay_ms(1);
			WLE = 1;
			WLE = 0;   //位选锁存
			
			DLE = 0; 	 //段选锁存
			P0 = Darr[i];  
			DLE = 1;
			DLE = 0; 	 //段选锁存
			
			WLE = 0;   //位选锁存
			P0 = 0x01<<i;
			WLE = 1;   
			WLE = 0;   //位选锁存
		}
	}
} 

注意:要先将位选关掉后并锁存?阻止数码管受到P0口信号的影响。 ??

实现

1.只位选最低位,段选循环显示

2.按位依次显示0~7

3.全部显示

文章来源:https://blog.csdn.net/werluo/article/details/135409868
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。