当前位置:网站首页>LCD12864 (ST7565P) Chinese character display (STM32F103)

LCD12864 (ST7565P) Chinese character display (STM32F103)

2022-06-24 19:23:00 Me-Space

One 、 summary

LCD12864 Belongs to dot matrix graphics LCD module , Able to display characters 、 Chinese characters and graphics , It can be divided into two kinds: with Chinese character library and without Chinese character library . This routine is based on without Chinese character library 12864 LCD module , The mode of communication is 8080 parallel signal communication , The LCD module uses ST7565P Chip driver .

Two 、 Experimental materials

1、STM32F103C8T6 Minimum system .
2、LCD12864 LCD screen .
3、 There are several DuPont lines .

3、 ... and 、 Hardware connection

 Insert picture description here

Four 、 Program code

1、GPIO initialization

void Lcd_Pin_Init(void)
{
    
	GPIO_InitTypeDef GPIO_InitStrcurt;
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | 
							RCC_APB2Periph_GPIOB,ENABLE);
	
	//PA8 PA11
	GPIO_InitStrcurt.GPIO_Mode = GPIO_Mode_Out_OD;
	GPIO_InitStrcurt.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_11 ; 
	GPIO_InitStrcurt.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_Init(GPIOA,&GPIO_InitStrcurt);
	
	//PB0 PB1 PB2
	GPIO_InitStrcurt.GPIO_Mode = GPIO_Mode_Out_OD;
	GPIO_InitStrcurt.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2;
	GPIO_InitStrcurt.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_Init(GPIOB,&GPIO_InitStrcurt);	
	
	// Data pins 
	GPIO_InitStrcurt.GPIO_Mode = GPIO_Mode_Out_OD;
	GPIO_InitStrcurt.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 
								| GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
	GPIO_InitStrcurt.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_Init(GPIOB,&GPIO_InitStrcurt);	
}

2、 Detect busy state

void Lcd_CheckBusy(void)
{
    
	u8 signal;
	
	LCD_RS = 0;
	LCD_WR = 1;
	
	do
	{
    
		LCD_RD = 0;
		delay_us(2);
		
		// read BF state 
		signal = BUSYIN;//PB15
		
		delay_us(2);
		LCD_RD = 1;
	}while(signal);
}

3、 Writing data

void Lcd_Send_Data(int data)
{
    
	Lcd_CheckBusy();// State judgement 
	LCD_RS = 1;
	LCD_CS = 0;
	LCD_RD = 1;
	LCD_WR = 0;
	delay_us(5);
	
	// data 
	data=data<<8;
	GPIOB->ODR=((GPIOB->ODR & 0x00FF)|(data&0xFF00));//PB15-8 It's data bits ,PB0-7 The data can't change 
	delay_us(5);
	LCD_WR = 1;
}

4、 Write orders

void Lcd_Send_Cmd(int cmd)
{
    
	Lcd_CheckBusy();// State detection 
	LCD_RS = 0;
	LCD_CS = 0;
	LCD_RD = 1;
	LCD_WR = 0;
	delay_us(5);
	
	// data 
	cmd=cmd<<8;
	GPIOB->ODR=((GPIOB->ODR & 0x00FF)|(cmd&0xFF00));//PB15-8 It's data bits ,PB0-7 The data can't change 
	delay_us(5);
	LCD_WR = 1;
}

5、 Clear the screen

void Lcd_Clear(int clear_data)
{
    
	u8 i = 0, j = 0;
	
	for(i = 0; i < 8; i++)
	{
    
		Lcd_Send_Cmd(0xB0 + i);// Page address 
		Lcd_Send_Cmd(0x10);    // Column address  
		Lcd_Send_Cmd(0x00);    // List the addresses 
		for(j = 0; j < 132; j++)
		{
    
			Lcd_Send_Data(clear_data);// Clear screen data 
		}
	}
}

6、 The driver

void Lcd_Init(void)
{
    
	Lcd_Pin_Init();
	LCD_RESE = 0;
	delay_ms(2);
	LCD_CS = 0;
	LCD_RESE = 1;
	

	Lcd_Send_Cmd(0XE2);// Software initialization 
	Lcd_Send_Cmd(0XA0);// Segment direction selection 0XA0: Normal direction ( about ) 0XA1: In the opposite direction 
	Lcd_Send_Cmd(0XC8);//0XC8: Ordinary ( Up and down ) Direction  0XC0: Normal direction 
	Lcd_Send_Cmd(0XA6);//0XA6: The font is black , The background is white  0XA7: The font is white , Black background 
	Lcd_Send_Cmd(0XA4);//0XA4: The pixels are normal  0XA5: All pixels on 
	Lcd_Send_Cmd(0XA2);//0XA2: Bias 1/7 0XA3: Bias 1/9
	Lcd_Send_Cmd(0XF8);// Double byte command  0XF8 00 Select boost 4x 
	Lcd_Send_Cmd(0X01);//0XF8 01 Select boost 5x 
	Lcd_Send_Cmd(0X81);// Double byte command 
	Lcd_Send_Cmd(0X23);// Set the background light contrast  0x00 To 0x3f
	Lcd_Send_Cmd(0X25);// Choose to adjust the resistivity 
	Lcd_Send_Cmd(0X2F);// Power settings 
	
	Lcd_Send_Cmd(0X40);// Set display start position 
	Lcd_Send_Cmd(0XAF);
	
	Lcd_Clear(0x00);// Clear the screen 
}

7、 Set the display position

//page: page  col: Column 
void Lcd_Set_Add(int page, int col)
{
    
	Lcd_Send_Cmd(0XB0 + page); 
	Lcd_Send_Cmd(0X10 + ((col & 0XF0) >> 4));// Column address 
	Lcd_Send_Cmd(0X00+ (col & 0X0F));// List the addresses 
}

8、 Character display

//page: page  col: Column  ch: character 
void Lcd_Display_Char(int page,int col,u8 ch)
{
    
	int str = 0;
	int i = 0;
	
	str = ch - ' ';//ch Position in the character set 
	 
	Lcd_Set_Add(page,col);// The first half 
	for(i = 0; i < 8; i++)
	{
    
		Lcd_Send_Data(Aciss_8X16[str * 16 + i]);
	}
	
	Lcd_Set_Add(page + 1,col);
	for(i = 0; i < 8; i++)
	{
    
		Lcd_Send_Data(Aciss_8X16[str * 16 + 8 + i]);
	}
}

9、 String display

//page: page  col: Column  *str: String array first address 
void Lcd_Display_String(int page, int col,u8 *str)
{
    
	while(*str != '\0')
	{
    
		Lcd_Display_Char(page,col,*str);
		col += 8;
		str++;
	}
}

10、 Single Chinese character or picture display

//page: page  col: Column  width: Width  high: Height  *Chinese: The first address of a single Chinese character array 
void Lcd_Display_Chinese(int page, int col,int width,int high,u8 *Chinese)
{
    
	u8 i = 0, j = 0;
	// Single display 
	for(i = 0; i < high / 8; i++)// page 
	{
     
		Lcd_Set_Add(page + i,col);
		for(j = 0; j < width; j++)// Column 
		{
    
			Lcd_Send_Data(Chinese[width * i + j]);
		}
	}
}

11、 Multiple Chinese characters display

//page: page  col: Column  width: Width  high: Height  num: The number of Chinese characters  *Chinese: First address of Chinese character array 
void Lcd_Display_ChinStr(int page, int col, int width, int high, int num, u8 *Chinese)
{
    	
	u8 i = 0, j = 0,k = 0;
	int temp = 0;

	for(k = 0; k < num; k++)
	{
    
		for(i = 0; i < high / 8; i++)
		{
     
			Lcd_Set_Add(page + i,col);
			for(j = 0; j < width; j++)
			{
    
				Lcd_Send_Data(Chinese[temp + j]);
			}
			temp += width;// Record the display position 
		}
		col += width;// Add a word width to the column address 
	}
}

12、 The main program

int main(void)
{
    
	u8 buf[] = {
    "2021/2/4"};
	Sys_Delay_Init();
	Lcd_Init();
	
	while(1)
	{
    
		// display string 
		Lcd_Display_String(6, 48,buf);
		// Show single Chinese 
		Lcd_Display_Chinese(6,112,16,16,Chinese16X16);
		
		// Show multiple Chinese 
		Lcd_Display_ChinStr(2,0,24,24,5,Chinese24X24);		
	}
}

Four 、 Experimental results

 Insert picture description here
Complete procedure and ST7565P Information :
link :https://pan.baidu.com/s/1Jk2jZoc63668NLPsqvZM4Q
Extraction code :cjx6

If there is any mistake, please point out , thank you !

原网站

版权声明
本文为[Me-Space]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202211331530106.html