数码管简介:
2. 电路分析:(原理如图)==74H573芯片原理分析
74H573芯片相当于一个锁存器,给公共引脚高电平就是给P2.6=1,之后给P0=0XFF,最后再给P2.6=0,就完成输出了。
最后当给了P2.6=0,后0XFF锁存在Q1~Q7,无论P0输入在变化,输出还是0XFF固定
加上210欧电阻防止数码管过亮,WEI对应输出端,前面的芯片对应A~G数码管输入端。所以想让数码管亮,需要给前一个芯片(接a ~g的)加0X00,后一个芯片(接WEI)接0XFF,这样才达到正负导通。
数码管断码编码表计算方法:
代码区:(详细解释看代码区)(调用74H595芯片是用来关闭其他电器的)
段选控制数字显示
位选控制有几个或者第几个显示数字
//共阴极: 位选为低电平(即0)选中数码管, 各段选为高电平(即1接+5V时)选中各数码段(0~f)
//共阴数码管段选表,无小数点:
unsigned char code distab[16] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d, 0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
//共阴数码管段选表,有小数点:
unsigned char code distab[16] = {0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd, 0x87,0xff,0xef,0xf7,0xfc,0xb9,0xde,0xf9,0xf1};
//共阴数码管位选表-8个
unsigned char code distab[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdF,0xbF,0x7F};//位选
/*******************************************************************************************************************/
//共阳极: 位选为高电平(即1)选中数码管, 各段选为低电平(即0接地时)选中各数码段(0~f)
//共阳数码管段选码表,无小数点:
unsigned char code distab[16]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8, 0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
//共阳数码管段选码表,有小数点:
unsigned char code distab[16]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78, 0x00,0x10,0x08,0x03,0x46,0x21,0x06,0x0e};
//共阳数码管位选表-8个
unsigned char code distab[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};//位选
#include"reg52.h"
typedef signed char int8;
typedef signed int int16;
typedef signed long int32;
typedef unsigned char uint8; //字符型
typedef unsigned int uint16;
typedef unsigned long uint32;
sbit duanxuan=P2^5; //段选控制数字显示
sbit weixuan=P2^6; //位选控制有几个或者第几个显示数字
sbit JDQ = P2 ^ 0;
sbit SHIFT_CLOCK_595 = P1 ^ 4;
sbit data_A_595 = P1 ^ 0;
sbit LATCH_CLOCK_595 = P2 ^ 3;
//自加变量,用来测试编码表
uint8 zifu_test; //用来计数
uint8 code zifu[19]={0XC0,0XF9,0XA4,0XB0,0X99,0X92,0X82,0XF8,0X80,0X90,0X88,0X83,0XC6,0XA1,0X86,0X8E,0X89,0X7F,0XBF};
void delay(uint16 x_ms) //延时毫秒
{
uint16 i,j;
for(i=x_ms;i>0;i--)
for(j=114;j>0;j--);
}
void xp74H595(uint16 dat)
{
uint16 i;
for (i = 0; i < 8; i++)
{
data_A_595 = (dat << i) & 0X80;
SHIFT_CLOCK_595 = 0; //时钟上升沿
SHIFT_CLOCK_595 = 1;
}
LATCH_CLOCK_595 = 0; //给锁存器脉冲,上升沿
LATCH_CLOCK_595 = 1;
}
void main(void)
{
P1=0XFF;
xp74H595(0X04); //流水灯
xp74H595(0X00); //关掉74H595所控制的所有电器
zifu_test=0; //先让数组为0
while(1)
{
duanxuan=0; //首先归零
weixuan=0;
P0= zifu[zifu_test++]; //控制输入 , 自加变量,测试编码表
duanxuan=1;
duanxuan=0; //以上是我们锁存器芯片段选的控制
delay(200);
duanxuan=0; //再次归零
weixuan=0;
P0= 0XFF; //位选输入
weixuan=1; //位选控制
weixuan=0; //位选锁存
delay(200);
if(zifu_test>=19)
{
zifu_test=0; //将变量清零
}
}
}
4.中文命名的修改,由于Keil是由美德一起搞得软件,中文命名会报错,当报错时,从那报错从哪改。
上一篇:51单片机~动态数码管的显示,消影,消抖,静态扫描,动态扫描
下一篇:74HC595芯片工作原理细致分析
推荐阅读最新更新时间:2024-11-12 21:07