LED dot matrix screen has strong luminous brightness and good indication effect. It can make moving luminous graphics and texts, which is easier to attract people’s attention. It has a large amount of information and can be updated at any time. It has a very good advertising and notice effect. The author here makes a brief introduction to the dynamic scanning display of LED dot matrix screen.

1. Overview of LED dot matrix display principle

Figure 1-1 shows the internal equivalent circuit diagram of an 8X8 LED dot matrix monochrome line common Yang module. For red LED, its working forward voltage is about 1.8V, its continuous working forward current is generally about 10mA, and the peak current can be greater. As shown in the figure below, when a row line is high and a column line is low, the intersection points of its rows and columns are lit. When a row line is low, regardless of the column line, all the points of the corresponding row are dark. LED dot matrix screen display is to scan line by line through a certain frequency, and the data end continuously inputs data for display. As long as the scanning frequency is high enough, due to the visual residual effect of human eyes, you can see the complete text or pattern information. Generally, there are 4, 8 and 16 line scanning modes. The fewer scanning lines, the better the display brightness of the dot matrix, but the corresponding hardware data register needs more.

Design of dynamic scanning display of LED dot matrix screen based on 51 single chip microcomputer

Figure 1-1 internal schematic diagram of dot matrix

2. Hardware design

The IO port of the microcontroller cannot flow excessive current. When the LED is lit, there is about 10ms of current. Therefore, the LED dot matrix pin should not be directly connected to the IO port of the MCU, but should first pass through a buffer 74hc573. The IO port of single chip microcomputer only needs a small current to control 74hc573, which can indirectly control a row (or a column) of LED dot matrix, and the output of 74hc573 can also load about 10ms of current. Set the LED driving current at each point as id = 15mA, which has good lighting degree and certain margin. Even if the power output voltage is high, the LED will not be burned, and the current limiting resistance value will not be changedR = (VCC- VCE– VOL– VLED) / IDVCC is powered by 5V, VCE is the saturation voltage between triode C and E, which is estimated to be 0.2V, Vol is 74hc573, and the output low level voltage is different for different perfusion currents, which is estimated to be 0.2V. For details, see the specification. VLED is the red light driving voltage, which is estimated to be 1.7V. According to the above formula, the current limiting resistance can be calculated as R = 200R.

The LED dot matrix screen needs to receive scanning signals one by one and scan to the corresponding column (or row). The data of the corresponding column (or row) is valid, that is, the information of this column (or row) is displayed. Generally, it is necessary to use a special decoder to generate the scanning signal, such as the three wire eight wire decoder 74HC138. In this way, the hardware can ensure that only one column (or row) is scanning at any time, and the occupation of IO port of microcontroller can be reduced. The 51 development board on the market basically does not use a decoder for the design of LED dot matrix screen. It directly uses MCU IO to generate scanning signal. For compatible software, the author does not add a decoder here. The software ensures that the IO port generates corresponding scanning signal.

When the LED points of a column (or row) are on, the current of about 15max8 = 90mA flows through the common end of this column (or row). The IO port of the microcontroller cannot directly drive this current, so it needs to be driven by a triode. Because the low-level perfusion current of 51 single chip microcomputer is large, it is suitable to use PNP triode as the drive. When the base current of the triode is set to 2mA, the triode can be saturated, and the maximum driving current is much greater than 90mA. Base bias resistanceRb=(VCC- VEB– VOL) / IBVCC is powered by 5V, veb is the conduction voltage between triode E and B of 0.7V, Vol is the low level voltage output by IO port of single chip microcomputer, which can be estimated as 0.2V according to the specification, so RB = 2K.

Design of dynamic scanning display of LED dot matrix screen based on 51 single chip microcomputer

Figure 2-1 schematic diagram of 8×8 common cathode LED dot matrix

3. Driver implementation

The LED dot matrix data port is connected to port P0, and the scanning selection line is connected to bits 0 ~ 7 of port P2. For dynamic scanning, there is a scanning frequency. The lower limit of LED screen scanning frequency is 50Hz. If it is lower than a certain scanning frequency, the display will flash. If the frequency is too high, the brightness is poor and CPU resources are occupied. Generally, the scanning time of the whole screen is about 10ms (i.e. the scanning frequency is 100Hz). We adopt the 8-line scanning mode. The lighting time of each line is 1.5ms and the scanning time is 12ms. To ensure this refresh rate, the dot matrix screen is usually refreshed periodically through a timer.

The display screen often involves complex operations such as drawing points, lines and drawings. Changing the information of the screen only needs to process the data in the video memory. Therefore, for the display screen, it is necessary to open up a memory space for video memory. Each point of 8×8 dot matrix can be represented by 1 bit, 1 byte per line and 8 bytes of video memory. Because there are too few pixels on the dot matrix screen, it is not necessary to realize complex operations such as line drawing and drawing. Here, the author only realizes the code implementation of dot matrix screen drawing and text moving up, down, left and right.

The matrix. C file of dot matrix screen dynamic display function module is as follows:

#include“reg52.h”

#include“Matrix.h”

//Each LED point needs 1 bit to save, and 8×8 dot matrix needs 8 bytes of video memory

static unsigned char FrameBuffer[8];

//The external module obtains the memory location of video memory through this function for processing

unsigned char *MatrixGetBuffer()

{

return FrameBuffer;

}

//Dot matrix refresh ensures that the refresh is called in a certain cycle

void MatrixScan()

{

staTIc unsigned char Select =0; // Record the scanned selection line

//Column data output to lattice data port

MatrixOutputData(FrameBuffer[Select]);

//The scanning signal is output to the dot matrix scanning selection port

MatrixOutputSelect(Select);

Select++; // Go to the next scan line

if (Select 》= 8) {

Select= 0; // All lines have been scanned. Go back to the first line and start scanning again

}

}

//LED dot matrix screen dotting function to light and turn off the (x, y) position, and the state is reversed

voidMatrixSetPoint(unsigned char x, unsigned char y, unsigned char OperaTIon)

{

If (x “7” | Y “7) {/ / ensure that the position is within the dot matrix screen area

return;

}

switch (OperaTIon) {

Case set: / / (x, y) position is set, and the lamp is off

FrameBuffer[x] |= 1《《 y;

break;

The case clear: / / (x, y) position is cleared and the light is on

FrameBuffer[x] &= ~(1《《 y);

break;

The case negate: / / (x, y) position is reversed, and the lamp state changes

FrameBuffer[x] ^= 1《《 y;

break;

default:

break;

}

}

//The LED dot matrix screen is clear, the display memory corresponds to the position of 1, the light is off, and the corresponding light of 0 is on

voidMatrixClearScreen()

{

unsigned char i;

for (i=0; i《8; i++) {

FrameBuffer[i] = 0xff;

}

}

//Lattice translation, translation 1 in four directions up, down, left and right, and the translation vacancy position is filled with data filling

void MatrixMove(unsignedchar DirecTIon, unsigned char Filling)

{

unsigned char i;

Switch (direction) {/ / judge the direction of balance

case MOVE_ Up: / / shift upward by 1, shift the 7th bit to the 6th bit of each column of data, and so on

for (i=0; i《8; i++) {

FrameBuffer[i] =(FrameBuffer[i]》》1) | ((Filling《《(7-i))&0x80);

}

break;

case MOVE_ Down: / / shift down by 1, shift the 0 of each column of data to the 1, and so on

for (i=0; i《8; i++) {

FrameBuffer[i]= (FrameBuffer[i]《《1) | ((Filling》》i)&0x01);

}

break;

case MOVE_ Left: / / shift 1 to the left, move the data in the right column to the current column, and so on

for (i=0; i《7; i++) {

FrameBuffer[i] = FrameBuffer[i+1];

}

FrameBuffer[i] = Filling;

break;

case MOVE_ Right: / / shift 1 to the right, move the data in the left column to the current column, and so on

for (i=7; i》=1; i–) {

FrameBuffer[i] = FrameBuffer[i-1];

}

FrameBuffer[i] = Filling;

break;

default:

break;

}

}

We implement the macro definition of the module and the implementation of the interface access macro in the dot matrix screen module header file matrix. H, so that it is convenient to transplant and modify the interface configuration. The module header file also leads to the interface function of the module. For example, matrixscan() is a dot matrix screen refresh function, which needs to be called periodically to refresh the dot matrix screen display. The contents of matrix. H file of dot matrix screen dynamic display function module are as follows:

#ifndef__ Matrix_ H__

#define__ Matrix_ H__

#ifdef__ cplusplus

extern”C“ {

#endif

#Define set 0x1 / / set to 1

#Define clear 0x2 / / clear 0

#Define negate 0x3 / / reverse operation

#defineMOVE_ Up 0x1 / / PAN up 1

#defineMOVE_ Down 0x2 / / pan down 1

#defineMOVE_ Left 0x3 / / PAN left 1

#defineMOVE_ Right 0x4 / / PAN right 1

//Output column data to port P0

#defineMatrixOutputData(Dat) {P0 = (Dat);}

//The P2 port outputs the scanning selection line of the corresponding column, and the low is valid

#defineMatrixOutputSelect(Select) {P2 = ~(1《《(Select));}

voidMatrixClearScreen(void);

voidMatrixMove(unsigned char Direction, unsigned char Filling);

unsigned char*MatrixGetBuffer(void);

voidMatrixScan(void);

voidMatrixSetPoint(unsigned char x, unsigned char y, unsigned char Operation);

#ifdef__ cplusplus

}

#endif

#endif/*__ Matrix_ H__*/

The external application calls the lattice screen driving function by introducing the lattice screen module header file matrix. H. The simple test call (random translation of heart shape in the lattice screen) is realized as follows:

#include”reg52.h“

#include”Matrix.h“

//Cardioid coordinate data

static unsigned charcode HeartShape[][2] = {

{3, 3}, {4, 2}, {5,3}, {5, 4}, {4, 5},

{3, 6}

Source; 21ic

 

Leave a Reply

Your email address will not be published. Required fields are marked *