HAL library 15- HD44780 for STM32Fxxx
HD44780 LCDs are still very popular devices in embedded project so I think you can’t without simple library for them. I’ve port my old library to HAL based libraries for these LCDs.
Library
Features
- 4-bits operation mode
- Minimum GPIOs used (6)
- Supports different LCD sizes
- Supports up to 8 custom characters
- Enable/disable cursor blinking
- Show/hide cursor
- Shift content in ram left/right
- Connection pins to board are user selectable
- Automatically jumps to new line when you reach max X on LCD
- Strings with \n, \r or \n\r
- With \n in string LCD jumps to lower line, but X position stays the same
- With \r in string LCD jumps to the beginning of the line
- With \n\r in string LCD jumps to the beginning of a new line
Dependencies
- HAL
- STM32Fxxx HAL
- defines.h
- TM GPIO
- TM DELAY
Default pinout
LCD | STM32Fxxx | DESCRIPTION |
---|---|---|
GND | GND | Ground |
VCC | +5V | Power supply for LCD |
V0 | Potentiometer | Contrast voltage. Connect to potentiometer |
RS | PB2 | Register select, can be overwritten in your project’s defines.h file |
RW | GND | Read/write |
E | PB7 | Enable pin, can be overwritten in your project’s defines.h file |
D0 | Data 0 – doesn’t care | |
D1 | Data 1 – doesn’t care | |
D2 | Data 2 – doesn’t care | |
D3 | Data 3 – doesn’t  care | |
D4 | PC12 | Data 4, can be overwritten in your project’s defines.h file |
D5 | PC13 | Data 5, can be overwritten in your project’s defines.h file |
D6 | PB12 | Data 6, can be overwritten in your project’s defines.h file |
D7 | PB13 | Data 7, can be overwritten in your project’s defines.h file |
A | +3V3 | Backlight positive power |
K | GND | Ground for backlight |
Custom settings
In case, you need to change any pin for your end project, you can open defines.h file and edit settings you need from library.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
/* 4 bit mode */ /* Control pins, can be overwritten */ /* RS - Register select pin */ #ifndef HD44780_RS_PIN #define HD44780_RS_PORT GPIOB #define HD44780_RS_PIN GPIO_PIN_2 #endif /* E - Enable pin */ #ifndef HD44780_E_PIN #define HD44780_E_PORT GPIOB #define HD44780_E_PIN GPIO_PIN_7 #endif /* Data pins */ /* D4 - Data 4 pin */ #ifndef HD44780_D4_PIN #define HD44780_D4_PORT GPIOC #define HD44780_D4_PIN GPIO_PIN_12 #endif /* D5 - Data 5 pin */ #ifndef HD44780_D5_PIN #define HD44780_D5_PORT GPIOC #define HD44780_D5_PIN GPIO_PIN_13 #endif /* D6 - Data 6 pin */ #ifndef HD44780_D6_PIN #define HD44780_D6_PORT GPIOB #define HD44780_D6_PIN GPIO_PIN_12 #endif /* D7 - Data 7 pin */ #ifndef HD44780_D7_PIN #define HD44780_D7_PORT GPIOB #define HD44780_D7_PIN GPIO_PIN_13 #endif |
Functions and enumerations
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
sor * @param None * @retval None */ void TM_HD44780_CursorOff(void); /** * @brief Scrolls display to the left * @param None * @retval None */ void TM_HD44780_ScrollLeft(void); /** * @brief Scrolls display to the right * @param None * @retval None */ void TM_HD44780_ScrollRight(void); /** * @brief Creates custom character * @param location: Location where to save character on LCD. LCD supports up to 8 custom characters, so locations are 0 - 7 * @param *data: Pointer to 8-bytes of data for one character * @retval None */ void TM_HD44780_CreateChar(uint8_t location, uint8_t* data); /** * @brief Puts custom created character on LCD * @param x: X location where character will be shown * @param y: Y location where character will be shown * @param location: Location on LCD where character is stored, 0 - 7 * @retval None */ void TM_HD44780_PutCustom(uint8_t x, uint8_t y, uint8_t location); /** * @} */ |
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
/** * Keil project example for HD44780 LCD * * Before you start, select your target, on the right of the "Load" button * * @author Tilen Majerle * @email tilen@majerle.eu * @website http://stm32f4-discovery.net * @ide Keil uVision 5 * @conf PLL parameters are set in "Options for Target" -> "C/C++" -> "Defines" * @packs STM32F4xx/STM32F7xx Keil packs are requred with HAL driver support * @stdperiph STM32F4xx/STM32F7xx HAL drivers required */ /* Include core modules */ #include "stm32fxxx_hal.h" /* Include my libraries here */ #include "defines.h" #include "tm_stm32_disco.h" #include "tm_stm32_delay.h" #include "tm_stm32_hd44780.h" /* Rectangle for custom character */ /* xxx means doesn't care, lower 5 bits are important for LCD */ uint8_t customChar[] = { 0x1F, /* xxx 11111 */ 0x11, /* xxx 10001 */ 0x11, /* xxx 10001 */ 0x11, /* xxx 10001 */ 0x11, /* xxx 10001 */ 0x11, /* xxx 10001 */ 0x11, /* xxx 10001 */ 0x1F /* xxx 11111 */ }; int main(void) { /* Init system clock for maximum system speed */ TM_RCC_InitSystem(); /* Init HAL layer */ HAL_Init(); /* Initialize system */ SystemInit(); /* Initialize LCD 20 cols x 4 rows */ TM_HD44780_Init(20, 4); /* Save custom character on location 0 in LCD */ TM_HD44780_CreateChar(0, customChar); /* Put string to LCD */ TM_HD44780_Puts(0, 0, "STM32F4/7-Disco/Eval"); TM_HD44780_Puts(2, 1, "20x4 HD44780 LCD"); TM_HD44780_Puts(0, 2, "stm32f4-\n\r discovery.com"); /* Wait a little */ Delayms(3000); /* Clear LCD */ TM_HD44780_Clear(); /* Show cursor */ TM_HD44780_CursorOn(); /* Write new text */ TM_HD44780_Puts(6, 2, "CLEARED!"); /* Wait a little */ Delayms(1000); /* Enable cursor blinking */ TM_HD44780_BlinkOn(); /* Show custom character at x = 1, y = 2 from RAM location 0 */ TM_HD44780_PutCustom(1, 2, 0); while (1) { /* Do nothing */ } } |
Project is available on Github, download all libraries below.
STM32 libraries based on STM32Fxxx HAL drivers.
Recent comments