Skip to main content
luke514
Associate III
July 14, 2022
Question

lcd_i2c_setCursor function for LCD 20x04

  • July 14, 2022
  • 2 replies
  • 10718 views

I hope this is the right section of the site to ask this question, otherwise please redirect this thread.

I just started programming, I am using a 20x04 LCD with stm32F407G and I need the classic function "

lcd_i2c_setCursor (row, col); ". I am not able to implement it by modifying the one already in the 16x02 display library.

So I am asking if you can redirect/send me to a post or link where this function is explained for 20x04 or if someone already has it and can attach the code so that I can "copy-paste" it into my project.

Or if there is a way to modify the function " lcd_i2c_setCursor (row, col); " that I have for the 16x02 LCD ... we can modify it here together:

void lcd16x2_i2c_setCursor(uint8_t row, uint8_t col)
{
 uint8_t maskData;
 maskData = (col)&0x0F;
 if(row==0)
 {
 maskData |= (0x80);
 lcd16x2_i2c_sendCommand(maskData);
 }
 else
 {
 maskData |= (0xc0);
 lcd16x2_i2c_sendCommand(maskData);
 }
}

Thank you.

This topic has been closed for replies.

2 replies

Foued_KH
ST Employee
December 26, 2022

Hello @luke514​ ,

You can refer to this example.

Please find the attachment the I2C-lcd libraries.

 /* USER CODE BEGIN 2 */
 
 lcd_init();
 
 lcd_send_cmd (0x80|0x00);
 lcd_send_string("FIRST");
 
 lcd_send_cmd (0x80|0x40);
 lcd_send_string("SECOND");
 
 lcd_send_cmd (0x80|0x1C);
 lcd_send_string("THIRD");
 
 lcd_send_cmd (0x80|0x54);
 lcd_send_string("FINISH");
 
 /* USER CODE END 2 */
 
 /* Infinite loop */
 /* USER CODE BEGIN WHILE */
 while (1)
 {
 /* USER CODE END WHILE */
 
 /* USER CODE BEGIN 3 */
	 for (int i=0; i<5; i++)
	 {
		 lcd_send_cmd (0x1C); // display shift right
		 HAL_Delay(350);
	 }
 
	 for (int i=0; i<5; i++)
	 {
		 lcd_send_cmd (0x18); // display shift left
		 HAL_Delay(350);
	 }
 }
 /* USER CODE END 3 */

Foued

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
luke514
luke514Author
Associate III
January 8, 2023

Thank you for your reply! I finally managed a few weeks ago to find the function I needed.