Program Design of Dot-matrix Chinese Character Display Based on 51 Single-chip Microcomputer

Program Design of Dot-matrix Chinese Character Display Based on 51 Single-chip Microcomputer

1. Practical purpose

This practice uses the minimum system of 51 single-chip microcomputer as the core, and uses 16×16 LED dot matrix composed of 4 pieces of 8×8 LED dot matrix, 2 pieces of 74HC595 shift register chips as the row driver of 16×16 LED dot matrix, and 2 pieces of 74HC138 decoding The device chip is used as the column driver of 16×16 LED dot matrix and the 51 single-chip microcomputer system composed of 8 independent keys to realize the display of Chinese characters on the LED dot matrix screen with multiple functions: realize static display, dynamic display including moving up and down Move, move left, move right, move display pause and resume, move acceleration and deceleration functions.

2. Experimental equipment and software based on practice

1. Equipment

51 single-chip microcomputer, 74HC595 chip, 74HC138 chip, independent buttons, LED dot matrix screen, program downloader, etc.

2. Software

Software for writing 51 MCU code: Keil uVision4, software for drawing schematic diagram and PCB: EasyEDA, software for simulation: Proteus 8 Professional.

2. System or device design

1. Hardware schematic design

The schematic diagram includes 51 single-chip microcomputer, crystal oscillator circuit, reset circuit, USB power interface circuit, 74HC595 register serial port to parallel port chip circuit, 74HC138 decoder chip circuit, 16×16 dot matrix Chinese character display circuit composed of four 8×8 LED dot matrix And independent button circuit. The drawn schematic diagrams are shown in Figure 2.1 to Figure 2.5.

insert image description here

图2.1:51单片机、晶振电路和复位电路组成51单片机最小系统

The 51 single-chip microcomputer is the core of the whole system, controlling functions such as 595 chips and 138 chips driving LED dot matrix Chinese character display. The crystal oscillator circuit provides a clock signal for the 51 single-chip LED dot matrix Chinese character display system.
insert image description here

图2.2:独立按键与USB电源接口电路

The USB power interface circuit provides power for the system, and the independent button circuit realizes the mode switching function of the LED dot matrix Chinese character display. Its specific function is to control the upward movement, downward movement, leftward movement, and rightward movement of the LED dot matrix display Chinese characters by the keys key1~key4 respectively. The button key5 controls the LED dot matrix to display Chinese characters to pause and continue to move. Key7 and key8 respectively control the moving speed of Chinese characters displayed on the LED dot matrix screen.

insert image description here

图2.3:两块595芯片电路

The 74HC595 register serial port to parallel port chip circuit drives the line selection of the 16×16 dot matrix screen. When the output port is high level, the corresponding line of the LED dot matrix is ​​selected. That is, the behavior of the LED dot matrix is ​​active high.

insert image description here

图2.4:两块138芯片电路

The 74HC138 decoder chip circuit drives the column selection of the 16×16 dot matrix screen. When the output port is low, the column corresponding to the LED dot matrix is ​​selected. That is, the columns of the LED dot matrix are active low.

insert image description here

图2.5:16×16LED点阵电路

The 16×16 dot matrix is ​​composed of four 8×8 dot matrix circuits. The 16×16 dot matrix Chinese character display circuit can realize the static display effect of Chinese characters and the dynamic scrolling display effect of upward, downward, left and right.

2. Printed board drawing

According to the drawn schematic diagram, it is first converted into a PCB diagram, and then its components are reasonably laid out, and then the wiring operation is performed with the automatic wiring function of the software. The drawn printed board diagram is shown in Figure 2.6
insert image description here

图2.6:51单片机LED点阵汉字显示系统PCB图

3. Program framework and main algorithm flow chart and description

insert image description here

图2.7:程序的基本框架流程图

The basic framework of the program starts from the main function. Firstly, the relevant variable initialization operation is performed, and then the timing interrupt initialization operation is performed. The timer of the 51 single-chip microcomputer is turned on to control the scrolling speed of the Chinese characters displayed on the LED dot matrix screen. After the relevant variables are initialized, enter the while (1) loop, and select the display mode according to the value of the variable modeSelect. Finally, at the end of the loop, call the function keyProcess() for key processing to determine whether there is a key pressed, and if there is a key, update the value of the modeSelect variable to update the LED dot matrix Chinese character display mode.

insert image description here

图2.8:按键处理流程图

The key processing adopts the judgment method of the if statement to judge whether there is a key. When a button is pressed, the related variable value will be set. For example, when the button key1 is pressed, the following variables are set

TR0 = 1;							// 定时器开
modeSelect = 1;					// 显示模式变量
speed = 10; 						// 汉字移动速度变量
moveBitNum = 0;					
net = zong1;						// 上下移动相关控制变量

The above is the setting of the related variable value when the button key1 is pressed. For the setting of the related variable value of other buttons, please refer to the appendix: complete code.

Fourth, the realization of the system or device

1. Physical installation and commissioning of the system or device

insert image description here

图3.1:51单片机LED点阵汉字显示系统实物图

2. Code and debugging

1. Use the keil4 software to create the ledData.h header file, use the Chinese character acquisition software to obtain the character data of dot matrix Chinese characters, and write it into the ledData.h header file. In the ledData.h header file, define which output pin of the control 138 decoder is valid, as shown in the following code

/*
	38译码器的输出端口的选择
*/
uchar code columnSlect[] = 		// 行选
{
    
    
	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
	0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
};

2. Then create a main.h header file. In the main.h header file, define the pins of the 51 single-chip microcomputer driver chip as follows

sbit ds = P1^0;	  				// 数据端口
	sbit shcp = P1^2;				// 数据输入时钟线
	sbit stcp = P1^1;				// 输出存储器锁存时钟线

	sbit key1 = P3^4;				// 向上移动控制按钮
	sbit key2 = P3^5;				// 向下移动控制按钮
	sbit key3 = P3^6;				// 向左移动控制按钮
	sbit key4 = P3^7;				// 向右移动控制按钮

	sbit key5 = P3^3;				// 静态显示显示的控制按钮
	sbit key6 = P3^2; 				// 闪烁显示的控制按钮

	sbit key7 = P1^6;   			// 控制汉字移动速度增加的控制按钮
	sbit key8 = P1^7;				// 控制汉字移动速度减小的控制按钮

Then define some variables like below

uchar speed = 30;				// 汉字移动速度控制的标志

uchar alt;
uint net, index;
uint zong, zong1;
uchar modeSelect;				// 	汉字显示的模式方式选择

uchar buff[4];
uchar moveBitNum;
uchar moveBitNumTemp;
	uchar IncNum;				// 上下左右移动的相关控制变量

Among them, the main variable modeSelect controls the selection of the display mode of Chinese characters on the LED dot matrix screen.
Declare some functions and implement related functions, as shown below

void timerInit();				// 定时器初始化函数
	void writedata(uchar);			// 向595芯片写入数据函数
	void clearScreen();				// led点阵显示与清屏
	void keyProcess();				// 按键处理的函数
	void delay(uint);				// 延时函数

timerInit(); To realize the initial operation of the 51 single-chip timer, turn on the timer of the 51 single-chip microcomputer to generate timing to control the speed at which Chinese characters move on the LED dot matrix screen; writedata(uchar); is to write the ledData.h header file The defined Chinese character data is written into the 595 chip to make it effective to control which behaviors of the LED dot matrix. clearScreen(); Realize LED dot matrix clearing and output the data in the 595 register from the parallel port to control the LED display. keyProcess(); is to realize the relevant operation of key processing. When the key is pressed, the corresponding variable is assigned a value, so as to control the way of displaying Chinese characters on the LED dot matrix screen.
3. Create a main.c source file to write the main function, and write the definition of the declared function in the main.h header file to realize the specific function of the corresponding function. The detailed code is in the appendix.
4. After compiling the program with keil4 software, compile and produce the .hex file. 51 MCU LED dot matrix Chinese character display program compilation information is shown in Figure 3.2

insert image description here

图3.2:程序编译的结果

It can be seen from the compiled results that the program has zero errors and no warnings. Then the .hex file produced by the program compilation is simulated in the Proteus software, and the simulation results are shown in Figure 3.3 and 3.4
insert image description here

图3.3:程序开始仿真结果

insert image description here

图3.4:按下按键一的仿真结果:向上移动

From the simulation results, the written program meets the requirements of the 51 single-chip LED dot matrix Chinese character display design function, and the system realizes the static display and dynamic display of the LED dot matrix system: moving up and down, moving left and right, flashing display and moving speed control.

5. System operation and result analysis

1. System running test process

Use the keil4 software to compile the written program to produce a .hex file, and download the program to the microcontroller through the downloader. The initial state of the 51 single-chip microcomputer written in the program is in the state of static display, that is, the first Chinese character is displayed: "electricity". Then press the keys key1~key4 respectively to realize the upward movement, downward movement, leftward movement and rightward movement of the Chinese characters displayed on the LED dot matrix screen. Press the button key5 to realize that the moving Chinese characters on the LED dot matrix screen become static, and when it is pressed again, the static Chinese characters become moving Chinese characters. Press the button key6 to realize the function of LED dot matrix screen flashing and displaying Chinese characters. Press key7 and key8 to increase and decrease the moving speed of Chinese characters respectively. When the single-chip microcomputer presses the RST reset button, the 51 single-chip microcomputer runs in the initial state of displaying static Chinese characters.

2. Summary of functions

Judging from the running results of the hardware, the single-chip dot-matrix Chinese character display system composed of 51 single-chip microcomputers, 16×16 LED dot matrix screens, independent buttons, 595 chips, and 138 chips has basically realized the functions required in practice: obtaining corresponding information from the software. The dot matrix displays the relevant information of Chinese characters; realizes the driving function of 51 single-chip microcomputer and LED dot matrix screen; writes the program of LED dot matrix Chinese character display through kei4 software, and realizes the Chinese characters move up, down, and to the LED dot matrix screen Functions such as moving left, moving right, and flashing display with special effects.

Guess you like

Origin blog.csdn.net/m0_47419053/article/details/125933710#comments_26146124