I am trying to interface LCD 16x2 with STM32 for learning purpose. I already interfaced with AVR, PIC etc. that code ported some of. But its not working. What am I doing wrong?
`
void LCD_init(void)
{
HAL_Delay(20);
lcd_cmd(0x30);
HAL_Delay(20);
lcd_cmd(0x30);
HAL_Delay(20);
//Delay_Us(100);
lcd_cmd(0x28);
HAL_Delay(20);
lcd_cmd(0x28); // Function set (4-bit interface, 2 lines, 5*7Pixels)
lcd_cmd(0x28); // Function set (4-bit interface, 2 lines, 5*7Pixels)
lcd_cmd(0x0c); // Make cursorinvisible
lcd_Clear(); // Clear screen
lcd_cmd(0x6); // Set entry Mode(auto increment of cursor)
}
oid lcd_cmd(__uint16_t cmd)
{ GPIOB->ODR =0;
HAL_GPIO_WritePin(GPIOB,GPIO_PIN_10, GPIO_PIN_RESET);
cmd = (cmd << 8) ;
GPIOB->ODR = (cmd & 0xf000);
lcd_Strobe();
cmd = (cmd << 4) ;
GPIOB->ODR = (cmd & 0xf000);
lcd_Strobe();
GPIOB->ODR =0;
}
void lcd_data(__uint16_t lcd_data)
{ GPIOB->ODR =0x0000;
// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_10, GPIO_PIN_SET);
lcd_data = (lcd_data << 8) ;
GPIOB->ODR = (lcd_data& 0xf000)|0x400;
lcd_Strobe();
GPIOB->ODR =0;
lcd_data = (lcd_data << 4) ;
GPIOB->ODR = (lcd_data & 0xf000)|0x400;
lcd_Strobe();
GPIOB->ODR =0;
}
void lcd_Clear(void)
{
lcd_cmd(0x01);
HAL_Delay(5);
}
void lcd_String(const char *ptr) // ptr pointing the address of displaying string
{
while (*ptr) // check weather the endo of file then exit the loop
{
lcd_data(*ptr++); // Sending data to LCD_data functions
}
}
`