The sister of iceberg yuluo, who is worth more than 100 million, said to xiaodiannong, do you have a larger LCD

Keywords: Single-Chip Microcomputer stm32 ARM

For yuluo's sister, cough, in order to expand my knowledge, how can I only use a liquid crystal as small as my brother? Shouldn't I be bigger

Linkage article The iceberg Royal Luo, who is worth more than 100 million, said to xiaomainong, can you display LCD

Introduction to LCD12864

Abnormal LCD12864 LCD screen, three COB cow dung piles on the back, one main control chip ST7920 and two shift chips ST7921

The function of the main control chip ST7920 is

1. Parallel communication with our MCU

2. Font ROM, CGROM, DDRAM

3. Line scan COM0-COM31

4. Column scanning SEG0-SEG63

5. Send data to two ST7921 driver chips in serial mode

The function of the driver chip ST7921 is

1. Receive the serial signal from ST7920 and convert it into parallel port driving voltage

2. According to the signal requirements, the two chips drive seg64-seg159 and seg160-seg255 respectively

schematic diagram

LCD12864 sequence diagram

parallel

Write instruction function LCD12864_Write_Cmd

void LCD12864_Write_Cmd(u8 add)//Write the command because the operation is an address
{
	LCD12864_RS = 0;
	LCD12864_RW = 1;
	LCD12864_E = 0;
	LCD12864_RW = 0;
	LCD12864_Delay(3);
	LCD12864_E = 1;
	LCD12864_DB = add;
	LCD12864_E = 0;
}

Write data function LCD12864_Write_Data

void LCD12864_Write_Data(u8 Dat)//Write data
{
	LCD12864_RS = 1;
	LCD12864_RW = 1;
	LCD12864_E = 0;
	LCD12864_RW = 0;
	LCD12864_Delay(3);
	LCD12864_E = 1;
	LCD12864_DB = Dat;	
	LCD12864_E = 0;	
}

These write instructions and write data functions are the same as 1602, because their timing diagram is the same, so the program is the same

Write operation process of 12864 character LCD (W R/W grounding is low level):

  1. Write command process: RS low level, and then the command is loaded into d0 -- D7. The e pin generates a falling edge, and the command is received and executed by 12864.
  2. Content writing process: RS high level, then the data is loaded into d0 -- D7, the e pin generates a falling edge, and the data is received and displayed by 12864.

Serial (we don't need it. If we want to use it, we can analyze the sequence diagram by ourselves)

LCD12864 command, CGRAM, DDRAM, DDROM, GDRAM

1. Basic command. The address range is 0x00 – 0x3f. It is used to operate the hardware configuration and other basic functions of LCD

2. Extension instruction. The address range is 0x00 – 0x3f. Used for drawing, anti white display and other advanced functions

3.CGRAM, address range 0x40 – 0x7f. It is used to save other customized images that the LCD itself does not have

4.DDRAM, the address range is 0x80 – 0x8f. It is used to save the ASCII code value and point to the custom CGRAM image data header address or the lithographic CGRAM image data header address through the ASCII code

5.GDRAM, the address range is 0x80 – 0xff. When extension instructions are allowed, they are used for drawing

The previous initialization section can be directly used in 1602. The effect is the same. See another figure

Initialization function LCD12864_Init

void LCD12864_Init()
{
	P4M1 = 0;
	P4M0 = 0;//Set all P4 S as standard IO ports, which is not emphasized here
	//At this time, write the sequence according to the sequence diagram
	LCD12864_Delay(250);		    //Wait at least 15ms after power on before writing instructions to LCD
	LCD12864_Delay(250);			//Wait at least 15ms after power on before writing instructions to LCD
	LCD12864_Write_Cmd(0x38);
	LCD12864_Write_Cmd(0x01);
	LCD12864_Delay(50);
	LCD12864_Write_Cmd(0x02);
	LCD12864_Delay(50);
	LCD12864_Write_Cmd(0x06);
	LCD12864_Write_Cmd(0x0c);
	LCD12864_Write_Cmd(0x14);
}

In order to see how initialization works, let's display a character and write it under initialization for the time being. If it can't be displayed, let's see what's wrong with the code

Chinese error display

Correct display of Chinese

In order to facilitate the display of Chinese characters, we create a Chinese character cache array (of course, the following is not a convenient operation, but this is the best operation for beginners to understand the principle)

A very important thing is to show the defects of Chinese characters

LCD service

//LCD service
void LCD12864_Display_Ser()
{
	LCD12864_Write_Cmd(0x80);
	LCD12864_Write_Data(LCD12864_Write_Buffer[0]);
	LCD12864_Write_Data(LCD12864_Write_Buffer[1]);
	LCD12864_Write_Data(LCD12864_Write_Buffer[2]);
	LCD12864_Write_Data(LCD12864_Write_Buffer[3]);
	LCD12864_Write_Data(LCD12864_Chinese_Buffer[14]);
	LCD12864_Write_Data(LCD12864_Chinese_Buffer[15]);//year
	LCD12864_Write_Data(LCD12864_Write_Buffer[4]);
	LCD12864_Write_Data(LCD12864_Write_Buffer[5]);
	LCD12864_Write_Data(LCD12864_Chinese_Buffer[16]);
	LCD12864_Write_Data(LCD12864_Chinese_Buffer[17]);//month
	LCD12864_Write_Data(LCD12864_Write_Buffer[6]);
	LCD12864_Write_Data(LCD12864_Write_Buffer[7]);
	LCD12864_Write_Data(LCD12864_Chinese_Buffer[18]);
	LCD12864_Write_Data(LCD12864_Chinese_Buffer[19]);//day
}

LCD data distribution

void LCD12864_Allot()//Always remember that LCD is a slow module
	//It doesn't need to be brushed quickly (because it is brushed quickly in main), so we
//In order not to affect other devices, we just reduce the number of brushes
{
	static xdata u16 count = 0;
	count++;
	if(count>500)
	{
		count = 0;
		//Two bytes are a set of numbers
		LCD12864_Write_Buffer[0] = 0x30+2;//Cannot directly 2, convert to ASCII value
		LCD12864_Write_Buffer[1] = 0x30+0;
		LCD12864_Write_Buffer[2] = 0x30+2;
		LCD12864_Write_Buffer[3] = 0x30+1;
		LCD12864_Write_Buffer[4] = 0x30+1;
		LCD12864_Write_Buffer[5] = 0x30+0;
		LCD12864_Write_Buffer[6] = 0x30+0;
		LCD12864_Write_Buffer[7] = 0x30+5;
	}
	LCD12864_Display_Ser();
}

Various memory diagrams of 12864 LCD

The following figure is the storage address structure diagram of DDRAM. The Chinese characters to be displayed are displayed here. The LCD circuit is spliced with the left and right half screens. In fact, the display is spliced with the upper and lower half screens, A0H – A7H and B0H – B7H. These two lines are the upper half screens but are not displayed. They are used for the operation of scrolling up and down screens. A8H – AFH and B8H – BFH are the volume cache of the lower half of the screen

If the screen is moved left and right, and the screen is moved left, 88H will display the position of 87H. However, the address number and content will not change, but the display position is modified

Structure of internal circuit

Actual position above the display

1. LCD initialization

After reset, write instructions in sequence (open display 0x0c) and (clear screen 0x01), and then delay for a period of time

2. Direct display of English and Chinese characters

3. Operation of displaying custom characters

Linkage article The iceberg Royal Luo, who is worth more than 100 million, said to xiaomainong, can you display LCD

Posted by The Stranger on Tue, 05 Oct 2021 10:29:31 -0700