#include "lcd.h"
#include "main.h"
extern void Delay_Us (uint16_t us);
void LCD_Strobe(void)
{
HAL_GPIO_WritePin(GPIOB,GPIO_PIN_11, GPIO_PIN_SET);// LCD Enable PIN to High
HAL_Delay(1);
//Delay_Us(100);
HAL_GPIO_WritePin(GPIOB,GPIO_PIN_11, GPIO_PIN_RESET);// LCD Enable High to Low
//Delay_Us(100);
HAL_Delay(1);
}
void LCD_init(void)
{
HAL_Delay(40);
LCD_cmd(0x28);
HAL_Delay(1);
LCD_cmd(0x28);
HAL_Delay(1);
//Delay_Us(100);
LCD_cmd(0x28);
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)
}
void LCD_cmd(__uint16_t cmd)
{ HAL_GPIO_WritePin(GPIOB,GPIO_PIN_11, GPIO_PIN_RESET);
cmd = (cmd << 8) ;
GPIOB->ODR = (cmd & 0xf000);
LCD_Strobe();
cmd = (cmd << 4) ;
// printf("GPIOB->ODR Value %d \n\r",cmd);
GPIOB->ODR = (cmd & 0xf000);
LCD_Strobe();
}
void LCD_data(__uint16_t LCD_Data)
{
HAL_GPIO_WritePin(GPIOB,GPIO_PIN_11, GPIO_PIN_SET);
LCD_Data = (LCD_Data << 8) ;
GPIOB->ODR = (GPIOB->ODR & 0x0fff) | (LCD_Data & 0xf000);
// LCD_Data =GPIOB->ODR;
// printf("GPIOB->ODR Value %d \n\r",LCD_Data);
LCD_Strobe();
LCD_Data = (LCD_Data << 4) ;
GPIOB->ODR = (GPIOB->ODR & 0x0fff) | (LCD_Data & 0xf000);
LCD_Strobe();
}
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
}
}