1. System Description
1. Hardware Description: Using parallel transmission, the controller is ST7920, and the data lines DB0-DB7 are connected to the microcontroller P0 port; RS is connected to P3.5; RW is connected to P3.6; the parallel signal enable pin EN is connected to P3.4; the serial/parallel selection interface PSB is connected to P3^7.
2. Functionality: Initialize and display the contents of str1[] to str4[], then display the contents of str5[] to str8[].
3. Design Plan: The display initialization program must be placed outside of while(1), and the display operation should only be executed once upon entering the program.
4. Note: For the clear screen function clrram(), if placed in the display program after initialization, it may cause excessive flickering on the display due to high frequency of clearing the screen, even resulting in no display.
5. The modular compilation interface based on Keil5 for the parallel LCD12864, the display initialization effect diagram, and the stable display effect diagram are shown below.
Figure 1: Modular Programming for LCD12864 Parallel Programming Compilation Interface
Figure 2: Display Initialization Interface
Figure 3: Interface after Display Stabilization
2. Main Function File main.c: The main function is the entry point of the program, mainly completing the call to the modular lcd12864bx.c source program. The specific main.c program is as follows.
#include “lcd12864bx.h”
uchar code str1[] = {” YuLin University “};
uchar code str2[] = {” School of Energy Engineering “};
uchar code str3[] = {“www.yulinu.edu.c”};
uchar code str4[] = {” WeChat Public Account: YuYuan Microcontroller”};
uchar code str5[] = {” Graphic LCD Display Project”};
uchar code str6[] = {” Temperature Collection Project “};
uchar code str7[] = {” IIC Bus Project “};
uchar code str8[] = {” SPI Bus Project “};
void main()
{
uchar i;
lcd_init();
lcd_pos(0,0);/* Display Initialization */
while(str1[i] != ‘\0’)
{
lcd_dat(str1[i]);
i++;
}
i = 0;
lcd_pos(1,0);
while(str2[i] != ‘\0’)
{
lcd_dat(str2[i]);
i++;
}
i = 0;
lcd_pos(2,0);
while(str3[i] != ‘\0’)
{
lcd_dat(str3[i]);
i++;
}
i = 0;
lcd_pos(3,0);
while(str4[i] != ‘\0’)
{
lcd_dat(str4[i]);
i++;
}
delay(50000);
delay(50000);
clrram();
while(1)
{
i = 0;
lcd_pos(0,0);
while(str5[i] != ‘\0’)
{
lcd_dat(str5[i]);
i++;
}
i = 0;
lcd_pos(1,0);
while(str6[i] != ‘\0’)
{
lcd_dat(str6[i]);
i++;
}
i = 0;
lcd_pos(2,0);
while(str7[i] != ‘\0’)
{
lcd_dat(str7[i]);
i++;
}
i = 0;
lcd_pos(3,0);
while(str8[i] != ‘\0’)
{
lcd_dat(str8[i]);
i++;
}
}
}
3. The lcd12864bx.c source file: Mainly completes the definitions of functions declared in the lcd12864bx.h header file, specific content as follows.
#include “lcd12864bx.h”
void delay(uint z)
{
while(z–);
}
void lcd_busy()
{
RW = 1;
RS = 0;
DataPort = 0xff;
E = 0;
E = 1;
delay(1);
while((DataPort & 0x80) == 0x80);
E = 0;
}
void lcd_cmd(uchar cmd)
{
lcd_busy();
RW = 0;
RS = 0;
DataPort = cmd;
E = 0;
E = 1;
delay(1);
E = 0;
}
void lcd_dat(uchar dat)
{
lcd_busy();
RW = 0;
RS = 1;
DataPort = dat;
E = 0;
E = 1;
delay(1);
E = 0;
}
void lcd_pos(uchar x, uchar y)
{
uchar pos;
if(x == 0)
{x = 0x80;}/* First line address */
else if(x == 1)
{x = 0x90;}/* Second line address */
else if(x == 2)
{x = 0x88;}/* Third line address */
else if(x == 3)
{x = 0x98;}/* Fourth line address */
pos = x + y;
lcd_cmd(pos);/* Specific display position */
}
void lcd_init()
{
PSB = 1;/* Using parallel transmission */
lcd_cmd(0x30);/* lcd12864 basic instruction set */
delay(5);
lcd_cmd(0x0c);/* Turn on display, do not show cursor, cursor does not blink */
delay(5);
lcd_cmd(0x06);/* After displaying a character, address pointer adds 1 */
delay(5);
lcd_cmd(0x02);
delay(10);/* Return to address */
lcd_cmd(0x01);/* Clear screen */
delay(5);
}
void clrram()/* Clear screen function */
{
lcd_cmd(0x30);
delay(5);
lcd_cmd(0x01);
delay(50000);
}
4. The lcd12864bx.h header file: Mainly completes the declarations of functions that need to be used externally and the bit declaration operations of the hardware. To avoid multiple source files simultaneously referencing the header file and causing repeated compilation, it is necessary to handle the non-repetitive inclusion, specific content as follows.
#ifndef __LCD12864BX_H__
#define __LCD12864BX_H__
#include
#define uint unsigned int
#define uchar unsigned char
#define DataPort P0
sbit RS = P3^5;
sbit RW = P3^6;
sbit E = P3^4;
sbit PSB = P3^7;
extern void delay(uint z);
extern void lcd_busy();
extern void lcd_cmd(uchar cmd);
extern void lcd_dat(uchar dat);
extern void lcd_init();
extern void lcd_pos(uchar x, uchar y);
extern void clrram(void);
#endif