ST7789-TFT screen driver and introduction
2025-01-22
Not long ago we received user feedback issues, repeated feedback on a variety of different models of the screen driver does not get up from 0 start writing code to spend a lot of time, there are also many first-time learners to drive the screen code writing experience is too little and other issues, for which we decided to publish in the form of an article to the CSDN to share the corresponding some of the experience as well as the collection of well-organised information in the hope that it can help the user to more simple learning or We hope to help users to learn more easily or quickly port the code for project development.
We will continue to share the screen driver cases about ST7789, GC9A01, ST7735, ILI9341 and other driver ICs.
Or the same old need to sort out the code can be left in the comments section or private mailbox!
About ST7789
The market using ST7789 driver IC screen is not rare, I have the honour to have used the screen in a 1.3-inch and a 1.54-inch screen driver chip for the ST7789, the two resolutions are 240x240, the online collection plus their own writing and transplantation collated stm32f10x, stm32f407, arduino, stc89c516, ESP32 and other microcontroller code, you need to sort out the code can be left in the comment area or private mailbo.

Comprehensive understanding and observation of some of the parameters of the screen after the start of the drive.
Hardware interface using the 2.54mm pitch of the row of pins interface, which uses DuPont cable for connection, need to design to their own PCB height is also just matching the above copper columns to do the positioning of the use.
ST7789 Parameter
Supply Voltage 3.3~5.5V
Driver IC ST7789
Resolution 240x240
Size 1.3 / 1.54 inch
Driver Interface 4-wire SPI
Producers in the screen design added 3.3V regulator chip and level shifter chip, making this original 3.3V power supply bare screen can be compatible with 5V and 3.3V microcontroller, which also means that arduino and 51 microcontroller users can also drive this screen, although the 51 microcontroller performance is very general, but better than can not drive the good.
Finally, after understanding the function of each pin, you can start to drive it.
Pin Name Pin Function
VCC Power positive, 3.3 - 5V, needs to match communication level
GND Power negative, ground
CS Chip select, low enable
RST Reset, Low Enable
DC Data/command select, low command, high data
SDA SPI data input port
SCL SPI Clock Signal Input Port
BLK Backlight, Suspend Enable Ground Off, Default Pull-Up to 3.3V
stm32 driver
Pin wiring
Code first according to the following table to connect the wires to burn the program and then the key parts of the code porting instructions
stm32f10x ST7789
3V3 VIN
GND GND
CS PB6
RST PA6
DC PA7
SDA PA4
SCL PA5
BLK PB7
Code Migration
Copying Files
Copy the lcd, lcd_init C and h files into your own project, these four files contain the screen initialisation and drive the code to draw dotted lines to display text images.
In addition, there are two files image.h and lcdfont.h, these two files are stored in the display image array and display text array.
copied to their own projects will report errors after compilation, because of the lack of pbdata.h in the milliseconds delay function, you can copy the original project in the ms delay function can also be used to write their own, the name of the same can be the following
Other microcontroller drivers
Code written using other microcontrollers displays the same effect as the STM32 one above, it is all one picture, the microcontroller with insufficient space just displays a smaller picture.
51 Microcontroller
The 51 microcontroller program is ported from the STM32, so it is the same to use, the only difference is that the 51 microcontroller has little space to display a big picture, and the speed is also slower.
Arduino/ESP32
arduino and ESP32 code is also transplanted from the original STM32, but because the compiler is different to do more modifications, the overall function interface and stm32 is the same and did not modify, due to data compatibility is not the same as in the call of the Chinese character display functions such as the need to do the type of data conversion, as shown in the following Chinese character display function call