LCD_UART.c

by Marwen Maghrebi
/*
 * Serial-LCD.c
 * Author: Marwen Maghrebi
 */
#include"Serial-LCD.h"

//wait for LCD to power up
void Delay_500ms(void)
{
  HAL_Delay(500);
}

//wait for the clear commande to settle
void Delay_10ms(void)
{
  HAL_Delay(10);
}

// Transmit data via UART
void LCD_UART_Transmit(uint8_t *pData, uint16_t Size) {
  HAL_UART_Transmit(&huart1, pData, Size, HAL_MAX_DELAY);
}

// Send command to the LCD
void LCD_sendCommand(uint8_t command) {
  LCD_UART_Transmit(&command, 1);
}

// Send data to the LCD
void LCD_sendData(uint8_t data) {
  LCD_UART_Transmit(&data, 1);
}

// Set cursor position on the LCD !!
void LCD_setCursor(uint8_t row, uint8_t col) {
  LCD_sendCommand(0xFE); // Command to set the cursor position
  LCD_sendCommand(0x80 + (row * 0x40) + col); // Calculate position based on row and column
}

// Scroll LCD content left
void LCD_scroll_left(uint8_t num_chars) {
  for (uint8_t i = 0; i < num_chars; i++) {
    LCD_sendCommand(0xFE); // Command to set the cursor position
    LCD_sendCommand(0x18); // Command to scroll one character to the left
    HAL_Delay(100);
  }
}

// Scroll LCD content right
void LCD_scroll_right(uint8_t num_chars) {
  for (uint8_t i = 0; i < num_chars; i++) {
    LCD_sendCommand(0xFE); // Command to set the cursor position
    LCD_sendCommand(0x1C); // Command to scroll one character to the right
    HAL_Delay(100);
  }
}

// Return cursor to the home position
void LCD_home() {
  LCD_sendCommand(0xFE); // Command to clear the screen
  LCD_sendCommand(0x00);
}

// Enable blinking cursor
void LCD_blinking_cursor_ON() {
  LCD_sendCommand(0xFE); // Command to clear the screen
  LCD_sendCommand(0x0D);
}

// Disable blinking cursor
void LCD_blinking_cursor_OFF() {
  LCD_sendCommand(0xFE); // Command to clear the screen
  LCD_sendCommand(0x0C);
}

// Clear the LCD screen
void LCD_clearScreen(void) {
  LCD_sendCommand(0xFE); // Command to clear the screen
  LCD_sendCommand(0x01);
}

// Move cursor left by num_chars characters
void Move_cursor_left(uint8_t num_chars) {
  for (uint8_t i = 0; i < num_chars; i++) {
    LCD_sendCommand(0xFE); // Command to clear the screen
    LCD_sendCommand(0x10);
    HAL_Delay(100);
  }
}

// Move cursor right by num_chars characters
void Move_cursor_right(uint8_t num_chars) {
  for (uint8_t i = 0; i < num_chars; i++) {
    LCD_sendCommand(0xFE); // Command to clear the screen
    LCD_sendCommand(0x14);
    HAL_Delay(100);
  }
}

// Enable underline cursor
void LCD_underline_cursor_ON() {
  LCD_sendCommand(0xFE); // Command to clear the screen
  LCD_sendCommand(0x0E);
}

// Turn off cursor and blinking
void LCD_Blank() {
  LCD_sendCommand(0xFE); // Command to clear the screen
  LCD_sendCommand(0x08);
}

// Print a string to the LCD
void LCD_print(const char *str) {
  while (*str) {
    LCD_sendData(*str++);
  }
}

// Print an integer to the LCD
void LCD_printInt(int value) {
  char buffer[20];  // Adjust the buffer size based on your needs
  sprintf(buffer, "%d", value);
  LCD_print(buffer);
}

// Print a floating-point number to the LCD with given decimal places
void LCD_printFloat(float value, int decimalPlaces) {
    char buffer[20];
    sprintf(buffer, "%.*f", decimalPlaces, value);
    // code to display the buffer on the LCD4
    LCD_print(buffer);

}

Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?
-
00:00
00:00
Update Required Flash plugin
-
00:00
00:00