[51 microcontroller series] 74HC595 realizes the control of LED dot matrix

This article is about the use of LED dot matrix, using the 74HC595 module to control the LED dot matrix.

1. The principle of 8x8 LED dot matrix

1.1 LED dot matrix display principle

LED dot matrix is ​​a display device composed of an arrangement of light-emitting diodes, and is widely used in automobile stop announcers, advertising screens, etc. As follows:

image-20231208092451292

The 8x8 lattice in proteus is as follows:

LED dot matrix in PROTEUS

The most commonly used one is the 8x8 dot matrix. Multiple 8x8 dot matrices can be used to form LED dot matrix displays with different resolutions. For example, a 16x16 dot matrix can be composed of four 8x8 dot matrices.

1.2 LED dot matrix internal structure diagram

The internal structure diagram of the 8x8LED dot matrix is ​​as follows. The two pictures only have different connection methods. To light up the LED, the rows on the left need to be set to high level and the columns to low. The right picture need to set the rows to low. Column is set high.

8x8LED dot matrix internal structure diagram

The 8x8 dot matrix consists of a total of 64 light-emitting diodes, and each light-emitting diode is placed at the intersection of the row line and the column line. When a corresponding row is set to high level and a certain column is set to low level, the corresponding diode will light up.

For example, in the picture on the left, if you want to light up the first point, connect pin 9 of the first row to high level and pin 13 of the first column to low level, and the first point will light up; When the first row is lit, the ⑨ pin of the first row is connected to high level, and all columns (pins 13, 3, 4, 10, 6, 11, 15, 16) are connected to low level, and the first row will light up. On; if you want to light up the first column, connect pin 13 of the first column to low level, and connect all rows (pins 9, 14, 8, 12, 1, 7, 2, and 5) to high level. The columns will light up; if you want to light up the diagonal line, you can display it dynamically. First light up the first point, then light up the point in the 2nd row and 2nd column... In this way, the diagonal line can be displayed in a cycle of lighting. Line points.

If you want to display numbers or characters, light them up at the required position, such as displaying 0 (as shown below), and you can light up the LEDs at the following positions in a cycle.

LED dot matrix displays 0

1.3 LED dot matrix schematic diagram on the development board

The development board uses the 74HC595 chip to realize serial to parallel conversion and connects it to the LED dot matrix module. The schematic diagram is as follows:

LED dot matrix schematic diagram

74HC595 has the function of expanding IO ports. From the schematic diagram, you can see that 74HC595 uses 3 IO port inputs and has 8 IO port outputs. These 8 IO ports control the rows of the LED dot matrix (from the first row to the last row, respectively, D7-D0), and use the P0 port to control the columns of the LED dot matrix (from the first column to the last column, respectively, P07-P00).

For example, as shown in the left picture of the above structure diagram, if you want to light up the first LED, then the P0 port should be set to 0x7f, and D7-D0 should be set to 0x80.

1.4 74HC595 chip

The 74HC595 chip has 8 serial input/output or parallel output shift registers with three-state output (high level, low level, high resistance state). Is a bus-driven parallel output. Typically used for data conversion from serial input to parallel output.

The 74HC595 pin description is as follows:

symbol pin describe
Q0…Q7(QA…QH) 15,1-7 Parallel data output
GND 8 logically
Q7' 9 Serial data output
/MR(/SRCLR) 10 Master reset (active low level), it is in reset state when connected to GND, and it is in high level state when connected to the power supply
SHCP(SRCLK) 11 Shift register clock input
STCP(RCLK) 12 Storage register clock input
/OE 13 The output is valid (active at low level). There is a terminal on the development board. If you want to make the output valid, short it to GND. If you want to make the output invalid, short it to VCC. It can also be connected to an IO port for control. When conducting LED dot matrix experiments, it should be shorted to ground to make the output effective.
DS(SER) 14 Serial data input, the input data is converted into parallel port output by the 74HC595 chip
VCC 16 power supply

The functions of 74HC595 are as follows, H=high level, L=low level, ↑=rising edge, ↓=falling edge, Z=high resistance state, NC=no change, X=invalid

enter enter enter enter enter output output Function
SHCP STCP OE MR DS Q7' Qn
X X L X L NC When MR is low it only affects the shift register
X L L X L L shift register to output register, the rising edge of STCP will output the data
X X H L X L Z Clear the shift register and set the parallel output to high impedance.
X L H H Q6' NC A logic high level is shifted into shift register state 0, including all shift register states shifted into
X L H X NC Qn The contents of the shift register arrive in the storage register and are output from the parallel port
L H X Q6' Qn’ The contents of the shift register are shifted in, and the contents of the previous shift register arrive in the storage register and are output

From the above table, we can know that when the master reset MR is high level and the output enable OE is low level, the data enters the shift register on the rising edge of SHCP and is output to the parallel port on the rising edge of STCP.

Data terminal of 74HC595:

Q0-Q7: Eight-bit parallel output terminals, which can directly control the 8 segments of the digital tube.

Q7': The cascade output terminal can be connected to the SER terminal of the next 595.

SER: Serial data input terminal.

74HC595 console description

  • /SCLR (pin 10): main reset pin, clears the shift register when the level is low, usually connected to VCC.
  • SCK (pin 11): The rising edge data register is shifted, and the falling edge shift register data remains unchanged.
  • RCK (pin 12): The data in the shift register enters the storage register at the rising edge, and the data in the storage register remains unchanged at the falling edge.
  • /OE (pin 13): Output is enabled, output is disabled when the level is high.

2. Use the 74HC595 module to achieve the effect of running water lights

The hardware design in proteus is as follows, and the implemented function is to use the 74HC595 chip to achieve the flowing light effect.

74HC595 achieves the effect of running water lights

According to the above introduction to the 74HC595, the DS pin is the input serial data. The rising edge of SHCP will perform the shift operation of the shift register. The rising edge of STCP will output the data to the parallel port.

The software code is as follows:

/*
	实现功能:74HC595芯片控制LED点阵实现LED流水灯的效果
	[2023-12-08] zoya
*/
#include "reg52.h"
#include "intrins.h"

typedef unsigned char u8;
typedef unsigned int u16;

sbit DS = P3^4;  // 74HC595输入数据端口
sbit STCP = P3^5;  // 74HC595存储寄存器端口,上升沿时移位寄存器进入存储寄存器
sbit SHCP = P3^6;  // 74hc595移位寄存器端口,上升沿时移入数据

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

// 74HC595芯片将输入的串行数据转换为并行数据输出
void HC595SendByte(u8 dat)
{
    
    
	u8 i;
	STCP = 1;  // 高电平时存储寄存器数据保持不变
	SHCP = 1;  // 高电平时移位寄存器数据保持不变
	for(i=0;i<8;i++)
	{
    
    
		DS = dat >> 7;  // 每次输入最高位数据
		dat <<= 1;  // 移位后将dat数据左移一位,保证下一次移入的数据在最高位
		// 实现移位寄存器的时序,需要SHCP有一个上升沿,所以先将SHCP置0,然后置1
		SHCP = 0;
		_nop_();  // 空指令,不做任何操作,当做延时使用
		_nop_();
		SHCP = 1;
	}
	
	// 数据已经在移位寄存器了,现在将移位寄存器的数据输出到存储寄存器
	// STCP上升沿时将数据从移位寄存器输出到存储寄存器
	STCP = 0;
	_nop_();
	_nop_();
	STCP = 1;
}


void main()
{
    
    
	u8 ledNum = ~0x01;  // 首先点亮D0
	// HC595SendByte(0xff);
	while(1)
	{
    
    
		HC595SendByte(ledNum);
		ledNum = _crol_(ledNum,1);  // 左移,逐个点亮D0-D7
		Delay(50000);
	}
}

Simulation results:

74HC595 realizes LED running water light effect

3. Use the 74HC595 module to control the diagonal brightness of the LED dot matrix

Design the following LED dot matrix in proteus to realize the function of using 74HC595 to control the diagonal lights of the LED dot matrix.

image-20231208151820036

The code is implemented as follows:

/*
	实现功能:74HC595芯片控制LED点阵实现对角线点亮
	[2023-12-08] zoya
*/
#include "reg52.h"
#include "intrins.h"

#define GPIO_LED P0  // LED点阵列控制IO口

typedef unsigned char u8;
typedef unsigned int u16;

sbit DS = P3^4;  // 74HC595输入数据端口
sbit STCP = P3^5;  // 74HC595存储寄存器端口,上升沿时移位寄存器进入存储寄存器
sbit SHCP = P3^6;  // 74hc595移位寄存器端口,上升沿时移入数据
u8 ledNum = 0x01;

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

// 74HC595芯片将输入的串行数据转换为并行数据输出
void HC595SendByte(u8 dat)
{
    
    
	u8 i;
	STCP = 1;  // 高电平时存储寄存器数据保持不变
	SHCP = 1;  // 高电平时移位寄存器数据保持不变
	for(i=0;i<8;i++)
	{
    
    
		DS = dat >> 7;  // 每次输入最高位数据
		dat <<= 1;  // 移位后将dat数据左移一位,保证下一次移入的数据在最高位
		// 实现移位寄存器的时序,需要SHCP有一个上升沿,所以先将SHCP置0,然后置1
		SHCP = 0;
		_nop_();  // 空指令,不做任何操作,当做延时使用
		_nop_();
		SHCP = 1;
	}
	
	// 数据已经在移位寄存器了,现在将移位寄存器的数据输出到存储寄存器
	// STCP上升沿时将数据从移位寄存器输出到存储寄存器
	STCP = 0;
	_nop_();
	_nop_();
	STCP = 1;
}

void main()
{
    
    
	// 点亮LED点阵的第一个灯,P00=0,其它为1
	u8 dNum = ~0x01;
	GPIO_LED = ledNum;
	while(1)
	{
    
    
		HC595SendByte(dNum);
		GPIO_LED = ledNum;
		Delay(200);
		dNum = _crol_(dNum,1);
		ledNum = _crol_(ledNum,1);
	}
}

Simulation results:

74HC595 realizes the diagonal bright effect of LED dot matrix

Guess you like

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