The LED dot matrix screen has strong luminous brightness and good indication effect. It can make moving luminous pictures and texts, which is easier to attract people's attention. It has a large amount of information and can be updated at any time. The author here makes a brief introduction to the dynamic scanning display of the LED dot matrix screen.
1. Overview of LED dot matrix display principle
Figure 1-1 is the internal equivalent circuit diagram of an 8x8 LED dot matrix monochromatic row common anode module. For red LEDs, the working forward voltage is about 1.8v, and the continuous working forward current is generally about 10ma, and the peak value is about 10mA. The current can be larger. As shown in the figure below, when a row line is high and a column line is low, the point where the row and column intersect is lit. When a row line is low, no matter what the column line is, all the points in the corresponding row are lit. for dark. The LED dot matrix screen display is to scan line by line at a certain frequency, and the data terminal is continuously inputting data to display. As long as the scanning frequency is high enough, due to the visual residual effect of the human eye, you can see the complete text or pattern information. There are usually 4, 8, and 16 line scanning modes. The fewer the scanning lines, the better the display brightness of the dot matrix, but the more corresponding hardware data registers are required.
Figure 1-1 Internal schematic diagram of lattice
2. Hardware Design
The IO port of the microcontroller cannot flow too much current. When the LED is lit, there is a current of about 10ms. Therefore, the LED dot matrix pins should not be directly connected to the IO port of the microcontroller, but should first pass through a buffer 74HC573. The IO port of the single-chip microcomputer only needs a small current to control the 74HC573 to indirectly control a certain row (or a certain column) of the LED dot matrix, and the 74HC573 output can also load a current of about 10ms. Set the driving current of each LED point to ID=15ma. This current point has good brightness and a certain margin. Even if the output voltage of the power supply is too high, the LED will not be burned. The current limiting resistor value
R = (VCC - VCE - VOL - VLED) / ID
VCC is 5v power supply, VCE is the saturation voltage between transistors C and E, estimated to be 0.2v, VOL is the voltage when 74hc573 outputs low level, different sink current, this value is different, estimated to be 0.2v, see the specification for details, VLED is The red light drive voltage 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 scan signals one by one, scan to the corresponding column (or row), and the corresponding column (or row) data is valid, that is, the information of this column (or row) is displayed. Generally, a special decoder is required to generate a scan signal, such as a three-line eight-line decoder 74HC138, which can ensure that only one column (or one row) is being scanned at any time by hardware, and can reduce the IO port occupation of the microcontroller. The 51 development boards on the market basically do not use a decoder for the design of the LED dot matrix screen, and directly use the IO of the single chip to generate the scanning signal. To be compatible with the software, the author does not add a decoder here, and the software ensures that the IO port generates the corresponding scan signal.
When the LED points of a certain column (or row) are all lit, the current of about 15max8=90ma flows through the common terminal of this column (or row), and the microcontroller IO port cannot directly drive this current, so it needs to be driven by a triode. The level sink current is large, so it is suitable to use a PNP transistor as a driver. The base current of the triode is set to 2ma to saturate the triode, and the maximum drive current is much greater than 90ma. Base bias resistor value
Rb=(VCC-VEB-VOL) / IB
VCC is 5v power supply, VEB is the conduction voltage between transistors E and B, 0.7v, and VOL is the voltage when the IO port of the microcontroller outputs a low level, which can be estimated as 0.2v according to the specification, so Rb= 2k.
Figure 2-1 Schematic diagram of 8X8 common cathode LED dot matrix
3. Driver implementation
The LED dot matrix data port is connected to the P0 port, and the scan selection line is connected to the 0~7 bits of the P2 port. For dynamic scanning, there is a scanning frequency. The lower limit of the scanning frequency of the LED screen is 50HZ. Below a certain scanning frequency, the display will flicker. If the frequency is too high, the brightness will be poor and CPU resources will be occupied. Generally, the whole screen scanning time is about 10ms (that is, the scanning frequency is 100HZ). We use the 8-line scanning method. The lighting time of each line is 1.5ms, and the scanning time is 12ms. In order to ensure this refresh rate, the dot matrix screen is refreshed periodically through a timer.
The display on the display often involves complex operations such as drawing dots, lines, and pictures. To change the information on the screen, only the data in the video memory needs to be processed. Therefore, for the display screen, it is necessary to open up a memory space for use as the video memory. Each point of the 8X8 dot matrix can be represented by 1 bit, a line of 1 byte, and 8 bytes of video memory. Since there are too few pixels on the dot matrix screen, there is no need to implement complex operations such as line drawing and drawing. The author only implements the code for drawing dots on the dot matrix screen and moving the text up and down, left and right.
The content of the dot matrix screen dynamic display function module file Matrix.c is as follows:
#include "reg52.h"
#include "Matrix.h"
// Each LED point needs to be saved by 1 bit, and 8X8 dot matrix needs 8 bytes of video memory
staTIc unsigned char FrameBuffer[8];
// The external module obtains the memory location of the video memory through this function for processing
unsigned char *MatrixGetBuffer()
{
return FrameBuffer;
}
// Dot matrix refresh, guarantee to call refresh at a certain period
void MatrixScan()
{
staTIc unsigned char Select =0; // record the scan select line
// Column data output to dot matrix data port
MatrixOutputData(FrameBuffer[Select]);
// The scan signal is output to the dot matrix scan selection port
MatrixOutputSelect(Select);
Select++; // Go to next line scan
if (Select >= 8) {
Select= 0; // All rows have been scanned, go back to the first row and start scanning again
}
}
// LED dot matrix screen dot function, turn on and off the (x, y) position, and invert the state
voidMatrixSetPoint(unsigned char x, unsigned char y, unsigned char OperaTIon)
{
if (x>7 "| y>7) { // The position is guaranteed to be in the dot matrix screen area
return;
}
switch(OperaTIon) {
case SET: // (x, y) position is set, the light is off
FrameBuffer[x] |= 1《》 y;
break;
case CLEAR: // (x, y) position is cleared, the light is on
FrameBuffer[x] &= ~(1<<y);
break;
case NEGATE: // (x, y) position is negated, the light state changes
FrameBuffer[x] ^= 1《》 y;
break;
default:
break;
}
}
// The LED dot matrix screen clears the screen, the display memory corresponds to the position of 1, the light is off, and the corresponding light of 0 is turned on
voidMatrixClearScreen()
{
unsigned char i;
for (i=0; i<8; i++) {
FrameBuffer[i] = 0xff;
}
}
// Dot matrix translation, translate 1 in four directions, up, down, left, and right, and fill the vacant position with data Filling
void MatrixMove(unsignedchar Direction, unsigned char Filling)
{
unsigned char i;
switch (Direction) { // Determine the direction of balance
case MOVE_UP: // Move up by 1, the 7th position of each column of data is shifted to the 6th position, and so on
for (i=0; i<8; i++) {
FrameBuffer[i] = (FrameBuffer[i]>>1) | ((Filling<<(7-i))&0x80);
}
break;
case MOVE_DOWN: // Move down by 1, the 0th position of each column of data is shifted to the 1st position, and so on
for (i=0; i<8; i++) {
FrameBuffer[i]= (FrameBuffer[i]<<1) | ((Filling>>i)&0x01);
}
break;
case MOVE_LEFT: // Move 1 to the left, the data of the right column is moved 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: // Move to the right by 1, the data of the left column is moved 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 header file Matrix.h of the dot matrix screen module, so that it is convenient to transplant and modify the interface configuration. The module header file also leads to the interface functions of the module. For example, MatrixScan() is the refresh function of the dot matrix screen, which needs to be called periodically to refresh the dot matrix screen display. The content of the dot matrix screen dynamic display function module file Matrix.h is as follows:
#ifndef__Matrix_H__
#define__Matrix_H__
#ifdef__cplusplus
extern "C" {
#endif
#define SET 0x1 //Set 1 operation
#define CLEAR 0x2 // clear operation
#define NEGATE 0x3 //Inversion operation
#defineMOVE_UP 0x1 // move up by 1
#defineMOVE_DOWN 0x2 // move down by 1
#defineMOVE_LEFT 0x3 // shift left by 1
#defineMOVE_RIGHT 0x4 // shift right by 1
// output column data to port P0
#defineMatrixOutputData(Dat) {P0 = (Dat);}
// P2 port outputs the scan select line of the corresponding column, active low
#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 implements calling the dot matrix screen driver function by introducing the module header file Matrix.h of the dot matrix screen. The simple test call (the random translation of the heart shape in the dot matrix screen) is implemented as follows:
#include "reg52.h"
#include "Matrix.h"
// Heart shape coordinate data
static unsigned charcode HeartShape[][2] = {
{3, 3}, {4, 2}, {5, 3}, {5, 4}, {4, 5},
{3, 6}, {2,
Stainless Steel Black Leather Rod
SUS304 Stainless Steel Black Leather Rod, TP304 Stainless Steel Black Leather Rod, Stainless Steel Black Leather Rod Wholesale
ShenZhen Haofa Metal Precision Parts Technology Co., Ltd. , http://www.haofametals.com