“This is the 10th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.”

Small code farming 12864 LCD attack SCM again

LCD12864 profile

Abnormal LCD12864 LCD screen, the back of 3 COB cow shit pile, a master chip ST7920, the other two shift chip ST7921

image-20211005080146245


The function of main control chip ST7920 is

1. Communicate with our microcontroller in parallel

2. Character library ROM, CGROM, DDRAM

3. Scan com0-COM31

4. Column scan SEG0-SEG63

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

The function of the drive chip ST7921 is

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

2. According to signal requirements, two chips drive Seg64-Seg159 and Seg160-SEG255 respectively

image-20211005093951823


Schematic diagram

image-20211005133240359


LCD12864 sequence diagram

parallel

image-20211005112719150


Write instruction function LCD12864_Write_Cmd

void LCD12864_Write_Cmd(u8 add)// Write the command, because the operation is 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;
}
Copy the code

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;	
}
Copy the code

These write instructions and write data functions are the same as 1602 because their sequence diagrams are the same, and therefore the program is the same

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

  1. Write command process: RS low level, then the command is loaded to D0- -D7, E pin produces falling edge, the command is received by 12864 and executed.
  2. Write content process: RS high level, and then the data is loaded into D0- -D7, E pin produces falling edge, the data is received and displayed by 12864.

Serial (we did not use, want to use their own analysis of the sequence diagram is ok)

image-20211005112901724


LCD12864 command, CGRAM, DDRAM, DDROM, GDRAM

1. Basic command, address range is 0x00- 0x3f. Used to operate the LCD hardware configuration and other basic functions

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

3.CGRAM, address range 0x40–0x7f Used to save other custom images that the LCD does not have

4.DDRAM, the address range is 0x80 to 0x8F. Used to save ASCII code values, through THE ASCII code pointing to the first address of custom CGRAM image data or the first address of photoengraving CGRAM image data

5.GDRAM, address range is 0x80– 0xFF. Allows extension of instructions after use for drawing

image-20211005143704693


The previous initialization section can be used directly with 1602, the effect is the same, see another picture of that

Initialization function LCD12864_Init

image-20211005145620692


void LCD12864_Init(a)
{
	P4M1 = 0;
	P4M0 = 0;// Set P4 to a standard IO port
	// Write the sequence according to the sequence diagram
	LCD12864_Delay(250);		    // wait at least 15ms before writing commands to the LCD
	LCD12864_Delay(250);			// wait at least 15ms before writing commands to the 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);
}
Copy the code

To see how the initialization looks, let’s display a character, just write it under initialization for the moment, and see what’s wrong with the code if it doesn’t display it

image-20211005152046828


Chinese error display

image-20211005153931962


Correct Display of Chinese

image-20211005154351271


To make it easier to display Chinese characters, we create a cache array of Chinese characters. (Of course, this is not a convenient operation, but it is the best operation for beginners to understand the principle.)

image-20211005155843390


It is very important to show the defects of Chinese characters

image-20211005172226611


LCD service

// LCD display service
void LCD12864_Display_Ser(a)
{
	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]);/ /,
}

Copy the code

LCD data distribution

void LCD12864_Allot(a)// Always remember that LCDS are slow modules
	// It doesn't need to be brushed very fast (because it is brushed fast in main) so we do
// In order not to affect other devices, we let it brush the number of times is reduced
{
	static xdata u16 count = 0;
	count++;
	if(count>500)
	{
		count = 0;
		// Two bytes in a group of numbers
		LCD12864_Write_Buffer[0] = 0x30+2;// Convert to ASCII instead of 2
		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();
}
Copy the code
image-20211005172054101


Various memory diagrams of 12864 liquid crystal

image-20211005120729234


The following figure is the storage address structure diagram of DDRAM, and the Chinese characters to be displayed are displayed here. The LCD circuit is the left and right half screen splicing, but the display is actually the upper and lower half screen splicing. A0H–A7H, B0H–B7H, these two lines are the upper half screen but not displayed, which are used for up-down screen winding operation. A8H–AFH, B8H–BFH, is the volume cache of the lower half of the screen

If you move the screen left and right, 88H will be displayed at 87H. However, the address number and content are not changed, but the display position is changed

The structure of an internal circuit

image-20211005121900412


The actual position above the display

image-20211005123658502


1. Initialize the LCD

After the reset, write instructions in sequence (0x0C on display) and (0x01 clear screen), and then delay for some time

2. Direct display of English and Chinese operations

image-20211005124648092


image-20211005124938066


3. Display custom character operations

image-20211005125128849


image-20211005125154133


image-20211005181504476