Interfacing a GLCD 128×64 ST7920 with an STM32 microcontroller can be a great way to display information and graphics in embedded systems applications. This process requires appropriate software and hardware setup, and our article includes an example code to help with the implementation.
Disclaimer:
Handling electricity carries inherent risks. It’s essential to have the appropriate skills to manage it safely. Proceed at your own risk, as the author disclaims responsibility for any misuse, harm, or errors. All content on this website is unique and copyrighted; please avoid unauthorized copying. While most articles are open-source for your benefit, feel free to use the knowledge provided. If you find our resources helpful, consider purchasing available materials to support our work.
For assistance or guidance, leave a comment below; the author is committed to helping. Some articles may contain affiliate links that support the author with a commission at no additional cost to you. Thank you for your understanding and support.
Table of Contents
Basics:
Interfacing a GLCD 128×64 ST7920 with an STM32 microcontroller can be a bit more complex than a standard 16×2 LCD due to its larger size and graphic capabilities. However, it is still possible to achieve this with the right hardware connections and software programming. In this guide, we will go over the steps required to interface a GLCD 128×64 ST7920 with an STM32 microcontroller, including the pin configuration, initialization, and example code for displaying graphics and text on the GLCD screen.
Interfacing the GLCD 128×64 ST7920 with an STM32 microcontroller
To begin interfacing the GLCD 128×64 ST7920 with an STM32 microcontroller, the following hardware connections will be required:
- Pin 1 (VSS) of the GLCD should be connected to GND
- Pin 2 (VDD) of the GLCD should be connected to +5V
- Pin 3 (Vo) of the GLCD should be connected to a potentiometer or voltage divider to adjust the contrast of the screen
- Pin 4 (RS) of the GLCD should be connected to a GPIO pin on the STM32
- Pin 5 (R/W) of the GLCD should be connected to GND
- Pin 6 (E) of the GLCD should be connected to a GPIO pin on the STM32
- Pins 7-14 (DB0-DB7) of the GLCD should be connected to GPIO pins on the STM32
- Pin 15 (CS1) of the GLCD should be connected to a GPIO pin on the STM32
- Pin 16 (CS2) of the GLCD should be connected to a GPIO pin on the STM32
- Pin 17 (RST) of the GLCD should be connected to a GPIO pin on the STM32
Once the hardware connections are made, the next step is to initialize the GLCD using the ST7920 controller. This involves sending a series of commands to the GLCD to set up the display parameters and configure the graphics modes.
Here is an example code for interfacing the GLCD 128×64 ST7920 with an STM32 microcontroller using the STM32CubeIDE and HAL libraries:
Example Code:
#include "stm32f4xx_hal.h" #include <stdio.h> #include <string.h> #define GLCD_RS_Pin GPIO_PIN_3 #define GLCD_RS_GPIO_Port GPIOA #define GLCD_RW_Pin GPIO_PIN_2 #define GLCD_RW_GPIO_Port GPIOA #define GLCD_E_Pin GPIO_PIN_0 #define GLCD_E_GPIO_Port GPIOB #define GLCD_CS1_Pin GPIO_PIN_1 #define GLCD_CS1_GPIO_Port GPIOB #define GLCD_CS2_Pin GPIO_PIN_2 #define GLCD_CS2_GPIO_Port GPIOB #define GLCD_RST_Pin GPIO_PIN_12 #define GLCD_RST_GPIO_Port GPIOB #define GLCD_DB0_Pin GPIO_PIN_15 #define GLCD_DB0_GPIO_Port GPIOA #define GLCD_DB1_Pin GPIO_PIN_8 #define GLCD_DB1_GPIO_Port GPIOB #define GLCD_DB2_Pin GPIO_PIN_9 #define GLCD_DB2_GPIO_Port GPIOB #define GLCD_DB3_Pin GPIO_PIN_0 #define GLCD_DB3_GPIO_Port GPIOE #define GLCD_DB4_Pin GPIO_PIN_1 #define GLCD_DB4_GPIO_Port GPIOE #define GLCD_DB5_Pin GPIO_PIN_2 #define GLCD_DB5_GPIO_Port GPIOE #define GLCD_DB6_Pin GPIO_PIN_3 #define GLCD_DB6_GPIO_Port GPIOE #define GLCD_DB7_Pin GPIO_PIN_4 #define GLCD_DB7_GPIO_Port GPIOE void GLCD_SendCommand(uint8_t command) { HAL_GPIO_WritePin(GLCD_RS_GPIO_Port, GLCD_RS_Pin, GPIO_PIN_RESET); HAL_GPIO_WritePin(GLCD_RW_GPIO_Port, GLCD_RW_Pin, GPIO_PIN_RESET); HAL_GPIO_WritePin(GLCD_E_GPIO_Port, GLCD_E_Pin, GPIO_PIN_RESET); GPIOE->ODR = command << 8; HAL_GPIO_WritePin(GLCD_E_GPIO_Port, GLCD_E_Pin, GPIO_PIN_SET); HAL_Delay(1); HAL_GPIO_WritePin(GLCD_E_GPIO_Port, GLCD_E_Pin, GPIO_PIN_RESET); } void GLCD_SendData(uint8_t data) { HAL_GPIO_WritePin(GLCD_RS_GPIO_Port, GLCD_RS_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(GLCD_RW_GPIO_Port, GLCD_RW_Pin, GPIO_PIN_RESET); HAL_GPIO_WritePin(GLCD_E_GPIO_Port, GLCD_E_Pin, GPIO_PIN_RESET); GPIOE->ODR = data << 8; HAL_GPIO_WritePin(GLCD_E_GPIO_Port, GLCD_E_Pin, GPIO_PIN_SET); HAL_Delay(1); HAL_GPIO_WritePin(GLCD_E_GPIO_Port, GLCD_E_Pin, GPIO_PIN_RESET); } void GLCD_Init() { HAL_GPIO_WritePin(GLCD_RST_GPIO_Port, GLCD_RST_Pin, GPIO_PIN_SET); HAL_Delay(10); HAL_GPIO_WritePin(GLCD_RST_GPIO_Port, GLCD_RST_Pin, GPIO_PIN_RESET); HAL_Delay(10); HAL_GPIO_WritePin(GLCD_RST_GPIO_Port, GLCD_RST_Pin, GPIO_PIN_SET); HAL_Delay(10); GLCD_SendCommand(0b00111000); // function set GLCD_SendCommand(0b00001100); // display on, cursor off, blink off GLCD_SendCommand(0b00000110); // entry mode set GLCD_SendCommand(0b00000001); // clear display HAL_Delay(10); } void GLCD_SetPage(uint8_t page) { uint8_t cmd = 0b10111000 | page; GLCD_SendCommand(cmd); } void GLCD_SetColumn(uint8_t column) { uint8_t cmd1 = 0b00000000 | (column & 0x0F); uint8_t cmd2 = 0b00010000 | ((column >> 4) & 0x0F); GLCD_SendCommand(cmd1); GLCD_SendCommand(cmd2); } void GLCD_WriteChar(uint8_t ch) { for (int i = 0; i < 5; i++) { GLCD_SendData(font[ch - 32][i]); } } void GLCD_Clear() { for (int i = 0; i < 8; i++) { GLCD_SetPage(i); GLCD_SetColumn(0); for (int j = 0; j < 128; j++) { GLCD_SendData(0); } } } void GLCD_WriteString(uint8_t row, uint8_t col, char* str) { GLCD_SetPage(row); GLCD_SetColumn(col); while (*str) { GLCD_WriteChar(*str++); GLCD_SetColumn(GLCD_Column + 5); } } int main(void) { HAL_Init(); SystemClock_Config(); MX_GPIO_Init(); GLCD_Init(); GLCD_Clear(); GLCD_WriteString(0, 0, "Hello, world!"); while (1) { } }
In this example code, the GLCD initialization sequence and functions for setting the page, column, and writing characters to the screen are implemented. The GLCD_Clear()
and GLCD_WriteString()
functions are also included to clear the screen and write a string of characters to the screen, respectively.
With this code, the GLCD 128×64 ST7920 can be easily interfaced with an STM32 microcontroller and used to display text and graphics.
It is worth noting that this code is specific to the GLCD 128×64 ST7920 and may need to be modified if using a different type of GLCD or microcontroller.
Additionally, this example code assumes that the necessary header files and font data are included in the project. It also assumes that the necessary pin configurations are set up in the STM32’s CubeMX software or in the HAL initialization code.
Conclusion:
Overall, interfacing a GLCD 128×64 ST7920 with an STM32 microcontroller can be a useful way to display information and graphics in embedded systems applications. With the appropriate software and hardware setup, this process can be straightforward and relatively easy to implement.
Read more on:
- How to interface a 16×2 LCD with an STM32
- How to interface ESP8266 with STM32
- How to interface DHT11 with STM32
- STM32 Bluetooth Low Energy & its application
- How to interface the EM18 RFID module with STM32
For Professional Designs or Help:
0 Comments