[51 microcontroller series] Use 74HC595 to control the digital tube display

Use 74HC595 combined with digital tube to display characters.

The proteus simulation design is as follows. The output end of the 74HC595 is connected to the bit selection of the dynamic digital tube and the segment selection of the static digital tube. The segment selection of the dynamic digital tube is connected to the P0 port. Both digital tubes share a common cathode.

74HC595 combined with digital tube to display characters

The static digital tube displays characters 0-F. The software design is as follows:

/*
	实现功能:74HC595芯片控制静态数码管显示字符0-F
	[2023-12-11] zoya
*/
#include "reg52.h"
#include "intrins.h"
#include "HC595.h"

// 共阴极数码管编码
u8 code smg[] = {
    
    0x3F, 0x06, 0x5B, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f,  // 0~9
0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71, 0x00}; // a~f+不显示
	
// 延时函数,i=1时延时10us
void Delay(u16 i)
{
    
    
	while(i--);
}

void main()
{
    
    
	u8 i;
	while(1)
	{
    
    
		for(i=0;i<17;i++)
		{
    
    
			HC595SendByte(smg[i]);  // 发送段选数据
			Delay(50000);
		}
	}
}

HC595SendByteFor function reference, please refer to the previous article "[51 Microcontroller Series] 74HC595 extended experiment using 74HC595 chip to display numbers in LED dot matrix".

Simulation results:

74HC595 controls the static digital tube to display 0-F

The dynamic digital tube displays 0-7, and the software code is as follows:

/*
	实现功能:74HC595芯片控制动态数码管显示0-7
	[2023-12-11] zoya
*/
#include "reg52.h"
#include "intrins.h"
#include "HC595.h"

#define GPIO_LED P0

// 共阴极数码管编码
u8 code smg[] = {
    
    0x3F, 0x06, 0x5B, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f,  // 0~9
0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71, 0x00}; // a~f+不显示

u8 duan = 0xfe;
// 延时函数,i=1时延时10us
void Delay(u16 i)
{
    
    
	while(i--);
}

// 数码管显示函数
void digDisplay()
{
    
    
	u8 i;
	for(i=0;i<8;i++)
	{
    
    
		HC595SendByte(duan);
		GPIO_LED = smg[i];
		Delay(150);
		duan = _crol_(duan,1);
		GPIO_LED = 0x00;
	}
}

void main()
{
    
    
	while(1)
	{
    
    
		digDisplay();
	}
}

Simulation results:

74HC595 controls dynamic digital tube display 0-7

When displaying the dynamic digital tube, I tried to use multiple delay times, but none of them could achieve the effect of the 38 decoder stably displaying 0-7. This is also a bug. I hope to learn more about it and solve it in the future.

Guess you like

Origin blog.csdn.net/sinat_41752325/article/details/134929606