8x8 dot matrix display graphics or dynamic display string

8x8 lattice

Display principle

The LED dot matrix screen is composed of several independent LEDs, which are arranged in the form of matrix

The structure of LED dot matrix screen is similar to that of nixie tube, which only arranges the pixels of each column in an "8" shape

Like the nixie tube, LED dot matrix screen has two connection methods: common Yin and common Yang. Different connection methods correspond to different circuit structures

The LED dot matrix screen needs to be scanned line by line or column by column in order to display all LEDs at the same time

Common anode connection method: the anode pins of light-emitting diodes in each row are connected together

The common cathode connection rule is that the cathode pins of light-emitting diodes in each row are connected together

The dot matrix on the development board can be understood as the row labels from top to bottom are h, G, F, e, D, C, B and a respectively, and the column labels from left to right are P0 respectively_ 7~P0_ 0, a, B and C numbers can be ignored. Anyway, the high bit of the data is in the high bit part in the 8x8 dot matrix, that is, the part relying on the LCD

74HC595

Because 8x8 dot matrix needs more pins, in order to save the IO port of MCU, 74HC595 chip is used to realize serial input and parallel output to drive the dot matrix

74HC595 is a shift register with serial input and parallel output. It can input serial data with 3 lines and output parallel data with 8 lines. After multiple chips are cascaded, it can output 16 bits, 24 bits and 32 bits. It is commonly used for IO port expansion.

//74HC595 shift register configuration
void _595sendByte(u_char dat)
{
	unsigned char i;
	for(i = 0;i < 8;i++)
	{
		SER = dat&(0x80>>i);//Starting from the high bit of dat, the values are the same as the upper 0x80,0x40,0x20 Then you can take out the value of the corresponding bit and put it into SER
		SRCLK = 1;	//Each rising edge moves one bit
		SRCLK = 0;	//Reset 0 to prepare for the next rising edge
	}
	RCLK1 = 1;	//When all the shifts are completed, RCLK will move all the data to the right port for parallel output
	RCLK1 = 0;
}

To sum up: SER puts in the data to be output in parallel, which can only be put in bit by bit. After putting in, SRCLK moves the put bit downward to the rising edge. After all the data is put in and moved to the right position, RCLK moves all the data to the port for parallel output

Blanking operation

Because the cpu is also constantly scanning the dot matrix screen, the 8x8 dot matrix is also similar to the nixie tube. The shadow elimination operation needs to be carried out in the case of continuous display to ensure that there is no string position when the light is on

Port P0 can be set to 1 after one data is lit

Display a graphic

First, use the font software to take out the data of the graphics you want to display

#include <REGX52.H>
#include "Delay.h"

typedef unsigned char u_char;

sbit RCLK1 = P3^5;
sbit SRCLK = P3^6;
sbit SER = P3^4;

//Data of graphics to be displayed, round face
unsigned char icon[] = {0x3C,0x42,0x95,0x85,0x85,0x95,0x42,0x3C};	

//74HC595 shift register configuration
void _595sendByte(u_char dat)
{
	unsigned char i;
	for(i = 0;i < 8;i++)
    {
		SER = dat&(0x80>>i);//Starting from the high bit of dat, the values are the same as the upper 0x80,0x40,0x20 Then you can take out the value of the corresponding bit and put it into SER
		SRCLK = 1;	//Each rising edge moves one bit
		SRCLK = 0;	//Reset 0 to prepare for the next rising edge
	}
	RCLK1 = 1;	//When all the shifts are completed, RCLK will move all the data to the right port for parallel output
	RCLK1 = 0;
}

/**
  * @brief graphic display
  * @param column Control column, dat control row
  * @retval nothing
  */
void show_graphics(u_char column,u_char dat)
{
	_595sendByte(dat);		//Control line, 595 chip outputs data in parallel
	P0 =~ (0X80>>column);	//Control column: select which bit of P0 is 0 according to the parameter. When column is 0, P0 = ~ 0x80, P0_ Port 7 is low level
	Delay(1);			
	P0 = 0xFF;				//After the delay, set all P0 ports to 1 for shadow elimination
}

void main()
{
	u_char i;
	SRCLK = 0;	//Initialize SRCLK and RCLK to 0
	RCLK1 = 0;
	while(1)
	{
		/*On the development board, it can be understood that from top to bottom is h,g,f,e,d,c,b,a, and from left to right is P0_7~P0_0
		a,b,c The number can be ignored. Anyway, the high position of the data is in the high position part in the 8x8 dot matrix, that is, the part relying on the LCD*/
		//_595sendByte();
		for(i = 0;i < 8;i++)
		{
            /*For fast scanning, i controls the column, because the data of the row has been generated by font software. As long as the row of this column is displayed when i column is displayed, it depends on the human eye 			 If the afterglow stays, you can see a figure*/
			show_graphics(i,icon[i]);
		}
	}
}

Dynamic display of characters or graphics

The experimental phenomenon is Hello! Scroll right to left

#include <REGX52.H>
#include "Delay.h"

typedef unsigned char u_char;

sbit RCLK1 = P3^5;
sbit SRCLK = P3^6;
sbit SER = P3^4;

//Data of graphics to be displayed
//Hello!
unsigned char code icon[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
							0xFE,0x10,0x10,0x10,0xFE,0x00,0x3C,0x42,
							0x4A,0x4A,0x32,0x00,0xFE,0x02,0x02,0x00,
							0xFE,0x02,0x02,0x3C,0x42,0x42,0x42,0x3C,
							0x00,0xFD,0x00,0x00,0x00,0x00,0x00,0x00,
							0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
//74HC595 shift register configuration
void _595sendByte(u_char dat)
{
	unsigned char i;
	for(i = 0;i < 8;i++)
	{	
		SER = dat&(0x80>>i);//Starting from the high bit of dat, the values are the same as the upper 0x80,0x40,0x20 Then you can take out the value of the corresponding bit and put it into SER
		SRCLK = 1;	//Each rising edge moves one bit
		SRCLK = 0;	//Reset 0 to prepare for the next rising edge
	}
	RCLK1 = 1;	//When all the shifts are completed, RCLK will move all the data to the right port for parallel output
	RCLK1 = 0;
}

/**
  * @brief graphic display
  * @param column Control column, dat control row
  * @retval nothing
  */
void show_graphics(u_char column,u_char dat)
{
	_595sendByte(dat);		//595 chip parallel output data control line
	P0 =~ (0X80>>column);	//Select which bit of P0 is 0 according to the parameter. When column is 0, P0 = ~ 0x80, P0_ Port 7 is low level
	Delay(1);			
	P0 = 0xFF;				//After the delay, set all P0 ports to 1 for shadow elimination
}
void main()
{
	u_char i;
	u_char offset = 3;		//Define offset
	u_char count = 0;		//For counting
	SRCLK = 0;				//Initialize SRCLK and RCLK to 0
	RCLK1 = 0;
	while(1)
	{
		for(i = 0;i < 8;i++)
		{
			show_graphics(i,icon[i+offset]);	//Data plus offset
		}
		count++;
		if(count > 10)	//Controls the speed of scrolling. The smaller the scrolling speed, the faster the scrolling speed
		{
			count = 0;
			offset++;
			if(offset > 35)		//Prevent access array overflow
			{
				offset = 0;
			}
		}
	}
}

code

When defining the data of displaying characters or graphics, the data is often large. If you define it directly without adding other keywords, it will be saved in the RAM area, and the size of ram is relatively small, which may not fit. Therefore, you can add keyword code to define the data in the ROM area, that is, flash area, but the data in the ROM area can only be read and cannot be changed. If you want to modify a value in the array, it is not allowed

unsigned char code icon[] = {0xFE,0x10,0x10,0x10,0xFE,0x00,0x3C,0x42};	//Put the array in the ROM area, which can only be read but not written

Attention

Is it feasible to directly drive these ports (not necessarily 8x8 dot matrix) with the pins of the single chip microcomputer without using the chip?

The answer is not feasible

Because the pin of the single chip microcomputer is weak pull-up, it is connected with a pull-up resistance. If the output low level is still normal, if the output high level driving ability is not enough, it will be very dark when driving the LED lamp

Solution: you can add a triode between the MCU pin and the pin receiving the signal, and the triode is connected with a VCC. At this time, the high level of the MCU is equivalent to the signal. Instead of driving directly, turn on the triode and drive other pins with the level of VCC

Address code: https://gitee.com/qiuzhixiong/dynamicdisplay.git

Tags: C Embedded system Single-Chip Microcomputer 8051 microcontroller

Posted by hoogie on Fri, 20 May 2022 23:08:03 +0300