当前位置:网站首页>LCD1602 string display (STM32F103)

LCD1602 string display (STM32F103)

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

One 、 summary

1602 Liquid crystal is 5V Voltage driven , With backlight , Two lines can be displayed , Each row 16 Characters , Chinese characters cannot be displayed , built-in 1128 A character ASCII Character set , Parallel communication mode . This test is passed STM32F103C8T6 The minimum system drives the LCD to display a string of characters .

Two 、 Experimental materials

1、STM32F103C8T6 Minimum system
2、LCD1602 liquid crystal
3、 There are several DuPont lines

3、 ... and 、 Basic operation sequence

state Input Output
Read status RS=L,RW=H,E=HD0-D7= state
Write instructions RS=L,RW=L,D0-D7= Instruction code ,E= High pulse nothing
Reading data RS=H,RW=H,E=HD0-D7= data
Writing data RS=H,RE=L,D0-D7= data ,E= High pulse nothing

Four 、 Hardware connection

 Insert picture description here

5、 ... and 、 Program code

1、GPIO initialization

void Lcd1602_Pin_Init(void)
{
    
	GPIO_InitTypeDef GPIO_InitStruct;
	
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
	
	GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_OD;
	GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | 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_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_Init(GPIOB,&GPIO_InitStruct);
}

2、LCD1602 initialization

void Lcd1602_Init(void)
{
    
	Lcd1602_Pin_Init();
	
	delay_ms(15);
		
	Lcd1602_Write_Cmd(0X38);
	Lcd1602_Write_Cmd(0X0C);// On display does not display the cursor 
	Lcd1602_Write_Cmd(0X06);// Write a pointer plus 1
	Lcd1602_Write_Cmd(0X01);// Clear the screen 
	Lcd1602_Write_Cmd(0X80);// Set data pointer start point  
}

3、 Detect busy state

void Lcd1602_Check_Busy(void)
{
    
	u8 signal;
	LCD_RS = 0;
	LCD_RW = 1;
	do
	{
    
		LCD_EN = 1;
		signal = LCD_BUSY;
		LCD_EN = 0;
	}while(signal);
}

4、 Write instructions

void Lcd1602_Write_Cmd(int cmd)
{
    
	Lcd1602_Check_Busy();// Detect busy state 
	LCD_RS = 0;
	LCD_RW = 0; 
	LCD_EN = 0;
	
	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(2); 
	LCD_EN = 1;
	delay_us(2);
	LCD_EN = 0;
	delay_ms(15);
}

5、 Writing data

void Lcd1602_Write_Data(int data)
{
    
	Lcd1602_Check_Busy();// Detect busy state 
	LCD_RS = 1; 
	LCD_RW = 0;
	LCD_EN = 0;
		
	data<<= 8;
	GPIOB->ODR = ((GPIOB->ODR & 0X00FF) | (data& 0XFF00));
	
	delay_us(2);
	LCD_EN = 1;
	delay_us(2);
	LCD_EN = 0;
	delay_ms(15);
}

6、 Show characters

// @u8 row: That's ok 
// @u8 col: Column 
// @int ch: character 
void Lcd1602_DisplayChar(u8 row,u8 col,int ch)
{
    
	// Display position 
	int add = 0;
	// Judgment is that line 
	if(row == 2)
	{
    
		// The first address on the second line  0x40
		add += 0x40;
	}
	// The first address on the first line  0x80
	add += 0x80 + col - 1;
	Lcd1602_Write_Cmd(add); 
	// According to the content  
	Lcd1602_Write_Data(ch);	
}

7、 display string

// @u8 row: That's ok 
// @u8 col: Column 
// @u8 *str: String first address 
void Lcd1602_DisplayString(u8 row,u8 col,u8 *str)
{
    
	while(*str != '\0')
	{
    
		Lcd1602_DisplayChar(row,col,*str);
		col += 1;
		str++;
	}
}

8、 The main program

int main(void)
{
    
	u8 buf[] = {
    "I Love You!"};
	u8 date[] = {
    "2021/2/7"};
	u8 author[] = {
    "Qing"};
	
	Sys_Delay_Init();
	Lcd1602_Init();
	
	// Single character 
// Lcd1602_DisplayChar(2,2,'A');
	// character string 
	Lcd1602_DisplayString(1,1,buf);
	Lcd1602_DisplayString(2,1,date);
	Lcd1602_DisplayString(2,13,author);
	
	while(1)
	{
    
		
	}
}

6、 ... and 、 Experimental results

 Insert picture description here
Complete procedure and LCD1602 LCD related information :
link :https://pan.baidu.com/s/1Ok-P7IACpib_vLQX57ikVg
Extraction code :hcyp

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

原网站

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