cancel
Showing results for 
Search instead for 
Did you mean: 

Hello everyone, I am interfacing stm32f103 to LCD44780 to display character in one location (1,1) but it shows in whole pixel 16x2. could you give me idea ?

Bunty Gtm
Associate II

here is my code

void LCD_Enable()

{

HAL_GPIO_WritePin(GPIOB,GPIO_PIN_14,1);

HAL_Delay(1);

HAL_GPIO_WritePin(GPIOB,GPIO_PIN_14,0);

HAL_Delay(1);

}

void LCD_Send4Bit(unsigned char Data)

{

HAL_GPIO_WritePin(GPIOA,GPIO_PIN_8,Data&0x01);

HAL_GPIO_WritePin(GPIOA,GPIO_PIN_9,(Data>>1)&0x01);

HAL_GPIO_WritePin(GPIOA,GPIO_PIN_10,(Data>>2)&0x01);

HAL_GPIO_WritePin(GPIOA,GPIO_PIN_11,(Data>>3)&0x01);

}

void LCD_SendCommand(unsigned char command)

{

LCD_Send4Bit(command >>4);/* Gui 4 bit cao */

LCD_Enable();

LCD_Send4Bit(command); /* Gui 4 bit thap*/

LCD_Enable();

}

void LCD_Clear()

{

  LCD_SendCommand(0x01);

 HAL_Delay(1000);

}

/* USER CODE END 0 */

void LCD_Init()

{

LCD_Send4Bit(0x00);

 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_12,0);

LCD_Send4Bit(0x03);

LCD_Enable();

LCD_Enable();

LCD_Enable();

LCD_Send4Bit(0x02);

LCD_Enable();

//LCD_SendCommand(0x33);

   //HAL_Delay(100);

//LCD_SendCommand(0x32);

//HAL_Delay(500);

LCD_SendCommand(0x28); // giao thuc 4 bit, hien thi 2 hang, ki tu 5x8

//HAL_Delay(500);

//LCD_SendCommand(0x01);

//HAL_Delay(500);

//LCD_SendCommand(0x06); // cho phep hien thi man hinh

//HAL_Delay(500);

LCD_SendCommand(0x0C); // tang ID, khong dich khung hinh

//HAL_Delay(500);

LCD_SendCommand(0x06); // xoa toan bo khung hinh

LCD_SendCommand(0X01);

//HAL_Delay(500);

}

void LCD_PutChar(unsigned char Data)

{

 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_12,1);

  LCD_SendCommand(Data);

 HAL_GPIO_WritePin(GPIOA,GPIO_PIN_12,0);

}

void LCD_Puts(char *s)

{

//LCD_Gotoxy(x,y);

while (*s){

    LCD_PutChar(*s);

    s++;

   }

}

void LCD_Gotoxy(unsigned char x, unsigned char y)

{

  unsigned char address;

    if(!y)address=(0x80+x);

    else address=(0xC0+x);

    LCD_SendCommand(address);

}

/**

 * @brief The application entry point.

 *

 * @retval None

 */

int main(void)

{

 /* USER CODE BEGIN 1 */

 /* USER CODE END 1 */

 /* MCU Configuration----------------------------------------------------------*/

 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */

 HAL_Init();

 /* USER CODE BEGIN Init */

 /* USER CODE END Init */

 /* Configure the system clock */

 SystemClock_Config();

 /* USER CODE BEGIN SysInit */

 /* USER CODE END SysInit */

 /* Initialize all configured peripherals */

 MX_GPIO_Init();

 /* USER CODE BEGIN 2 */

 /* USER CODE END 2 */

 /* Infinite loop */

 /* USER CODE BEGIN WHILE */

 LCD_Init();

 //LCD_Gotoxy(1,1);

    // LCD_Puts("NEPAL");

 while (1)

 {

 /* USER CODE END WHILE */

 /* USER CODE BEGIN 3 */

 LCD_Gotoxy(1,1);

     LCD_Puts("NEPAL");

 HAL_Delay(1500);

     LCD_Clear();

 }

 /* USER CODE END 3 */

}

0 REPLIES 0