Google Chat: zj734465502@gmail.com
+86-0755-88291180
sales01@spotpear.com
dragon_manager@163.com
services01@spotpear.com
manager01@spotpear.com
WhatsApp:13246739196
Note: The difference from the traditional SPI protocol is that the data line sent from the slave to the host is hidden because it only needs to be displayed. Please refer to Datasheet Page 66 for the table.
RESX is reset, it is pulled low when the module is powered on, usually set to 1;
CSX is the slave chip select, and the chip will be enabled only when CS is low.
D/CX is the data/command control pin of the chip, when DC = 0, write command, when DC = 1, write data.
SDA is the transmitted data, that is, RGB data;
SCL is the SPI communication clock.
For SPI communication, data is transmitted with timing, that is, the combination of clock phase (CPHA) and clock polarity (CPOL):
The level of CPHA determines whether the serial synchronization clock is collected on the first clock transition edge or the second clock transition edge. When CPHA = 0, data acquisition is performed on the first transition edge;
The level of CPOL determines the idle state level of the serial synchronous clock. CPOL = 0, which is a low level.
As can be seen from the figure, when the first falling edge of SCLK starts to transmit data, 8-bit data is transmitted in one clock cycle, using SPI0, bit-by-bit transmission, high-order first, and low-order last.
When connecting to the Raspberry Pi, you can choose the 8PIN cable to connect according to the following table:
LCD | Raspberry Pi | |
BCM2835 | Board | |
VCC | 3.3V | 3.3V |
GND | GND | GND |
DIN | MOSI | 19 |
CLK | SCLK | 23 |
CS | CE0 | 24 |
DC | 25 | 22 |
RST | 27 | 13 |
BL | 18 | 12 |
The 1.69inch LCD uses the GH1.25 8PIN interface, which can be connected to the Raspberry Pi according to the above table: (Please connect according to the pin definition table. The color of the wiring in the picture is for reference only, and the actual color shall prevail.)
sudo raspi-config Choose Interfacing Options -> SPI -> Yes to enable SPI interface
Reboot Raspberry Pi:
sudo reboot
# Open the Raspberry Pi terminal and run the following command: wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.71.tar.gz tar zxvf bcm2835-1.71.tar.gz cd bcm2835-1.71/ sudo . /configure && sudo make && sudo make check && sudo make install # For more information, please refer to the official website: http://www.airspayce.com/mikem/bcm2835/
# Open the Raspberry Pi terminal and run the following command: sudo apt-get install wiringpi #For Raspberry Pi systems after May 2019 (earlier than that can be executed without), an upgrade may be required: wget https://project-downloads.drogon.net/wiringpi-latest.deb sudo dpkg -i wiringpi-latest.deb gpio -v # Run gpio -v and version 2.52 will appear, if it does not, there was an installation error. # Bullseye branch system using the following command: git clone https://github.com/WiringPi/WiringPi cd WiringPi . /build gpio -v # Run gpio -v and version 2.60 will appear, if it doesn't, there is an installation error.
sudo apt-get install unzip -y sudo wget https://www.waveshare.com/w/upload/f/fc/LCD_Module_code.zip sudo unzip LCD_Module_code.zip -d ./LCD_Module_code cd LCD_Module_code/RaspberryPi/
cd c sudo make clean sudo make -j 8
Test procedures for all screens can be called directly by entering the corresponding size:
sudo ./main 1.69
#python2 sudo apt-get update sudo apt-get install python-pip sudo apt-get install python-pil sudo apt-get install python-numpy sudo pip install RPi.GPIO sudo pip install spidev #python3 sudo apt-get update sudo apt-get install python3-pip sudo apt-get install python3-pil sudo apt-get install python3-numpy sudo pip3 install RPi.GPIO sudo pip3 install spidev
sudo apt-get install unzip -y sudo wget https://www.waveshare.com/w/upload/f/fc/LCD_Module_code.zip sudo unzip LCD_Module_code.zip -d ./LCD_Module_code cd LCD_Module_code/RaspberryPi/
cd python/example ls -l
All test demos for screens can be viewed, sorted by size:
0inch96_LCD_test.py 0.96inch LCD test demo 1inch14_LCD_test.py 1.14inch LCD test demo 1inch28_LCD_test.py 1.28inch LCD test demo 1inch3_LCD_test.py 1.3inch LCD test demo 1inch47_LCD_test.py 1.47inch LCD test demo 1inch54_LCD_test.py 1.54inch LCD test demo 1inch69_LCD_test.py 1.69inch LCD test demo 1inch8_LCD_test.py 1.8inch LCD test demo 1inch9_LCD_test.py 1.9inch LCD test demo 2inch_LCD_test.py 2inch LCD test demo 2inch4_LCD_test.py 2.4inch LCD test demo
Just run the demo corresponding to the screen, the demo supports python2/3.
# python2 sudo python 1inch69_LCD_test.py # python3 sudo python3 1inch69_LCD_test.py
Framebuffer uses a video output device to drive a video display device from a memory buffer containing complete frame data. Simply put, a memory area is used to store the display content, and the display content can be changed by changing the data in the memory.
There is an open source project on github: fbcp-ili9341. Compared with other fbcp projects, this project uses partial refresh and DMA to achieve a speed of up to 60fps.
sudo apt-get install cmake -y cd ~ wget https://www.waveshare.com/w/upload/1/18/Waveshare_fbcp.zip unzip Waveshare_fbcp.zip cd Waveshare_fbcp/ sudo chmod +x ./shell/*
Here we have written several scripts that allow users to quickly use fbcp and run corresponding commands according to their own screen
If you use a script and do not need to modify it, you can ignore the second method below.
Note: The script will replace the corresponding /boot/config.txt and /etc/rc.local and restart, if the user needs, please back up the relevant files in advance.
#0.96inch LCD Module sudo ./shell/waveshare-0inch96 #1.14inch LCD Module sudo ./shell/waveshare-1inch14 #1.3inch LCD Module sudo ./shell/waveshare-1inch3 #1.44inch LCD Module sudo ./shell/waveshare-1inch44 #1.54inch LCD Module sudo ./shell/waveshare-1inch54 #1.8inch LCD Module sudo ./shell/waveshare-1inch8 #2inch LCD Module sudo ./shell/waveshare-2inch #2.4inch LCD Module sudo ./shell/waveshare-2inch4
Raspberry Pi's vc4-kms-v3d will cause fbcp to fail, so we need to close vc4-kms-v3d before installing it in fbcp.
sudo nano /boot/config.txt
Just block the statement corresponding to the picture below.
A reboot is then required.
sudo reboot
mkdir build cd build cmake [options] .. sudo make -j sudo ./fbcp
Replace it by yourself according to the LCD Module you use, above cmake [options] ..
#0.96inch LCD Module sudo cmake -DSPI_BUS_CLOCK_DIVISOR=20 -DWAVESHARE_0INCH96_LCD=ON -DBACKLIGHT_CONTROL=ON -DSTATISTICS=0 .. #1.14inch LCD Module sudo cmake -DSPI_BUS_CLOCK_DIVISOR=20 -DWAVESHARE_1INCH14_LCD=ON -DBACKLIGHT_CONTROL=ON -DSTATISTICS=0 .. #1.3inch LCD Module sudo cmake -DSPI_BUS_CLOCK_DIVISOR=20 -DWAVESHARE_1INCH3_LCD=ON -DBACKLIGHT_CONTROL=ON -DSTATISTICS=0 .. #1.54inch LCD Module sudo cmake -DSPI_BUS_CLOCK_DIVISOR=20 -DWAVESHARE_1INCH54_LCD=ON -DBACKLIGHT_CONTROL=ON -DSTATISTICS=0 .. #1.8inch LCD Module sudo cmake -DSPI_BUS_CLOCK_DIVISOR=20 -DWAVESHARE_1INCH8_LCD=ON -DBACKLIGHT_CONTROL=ON -DSTATISTICS=0 .. #2inch LCD Module sudo cmake -DSPI_BUS_CLOCK_DIVISOR=20 -DWAVESHARE_2INCH_LCD=ON -DBACKLIGHT_CONTROL=ON -DSTATISTICS=0 .. #2.4inch LCD Module sudo cmake -DSPI_BUS_CLOCK_DIVISOR=20 -DWAVESHARE_2INCH4_LCD=ON -DBACKLIGHT_CONTROL=ON -DSTATISTICS=0 ..
sudo cp ~/Waveshare_fbcp/build/fbcp /usr/local/bin/fbcp sudo nano /etc/rc.local
Add fbcp& before exit 0. Note that you must add "&" to run in the background, otherwise the system may not be able to start.
Set the user interface display size in the /boot/config.txt file.
sudo nano /boot/config.txt
Then add the following lines at the end of the config.txt.
hdmi_force_hotplug=1 hdmi_cvt=[options] hdmi_group=2 hdmi_mode=1 hdmi_mode=87 display_rotate=0
Replace the above hdmi_cvt=[options] according to the LCD Module you are using.
#2.4inchinch LCD Module & 2inchinch LCD Module hdmi_cvt=640 480 60 1 0 0 0 #1.8inch LCD Module hdmi_cvt=400 300 60 1 0 0 0 #1.3inch LCD Module & 1.54inch LCD Module hdmi_cvt=300 300 60 1 0 0 0 #1.14inch LCD Module hdmi_cvt=300 170 60 1 0 0 0 #0.96inch LCD Module hdmi_cvt=300 150 60 1 0 0 0
And then reboot the system
sudo reboot
After rebooting the system, the Raspberry Pi OS user interface will be displayed.
The demo we provided is based on STM32F103RBT6 and the connections provided correspond to the pins of the STM32F103RBT6, so if you need to port the demo, please connect the pins according to the actual pins:
LCD | STM32 |
VCC | 3.3V |
GND | GND |
DIN | PA7 |
CLK | PA5 |
CS | PB6 |
DC | PA8 |
RST | PA9 |
BL | PC7 |
Taking the XNUCLEO-F103RB development board developed by our company as an example, the connection is as follows:
#define UBYTE uint8_t #define UWORD uint16_t #define UDOUBLE uint32_t
void DEV_Module_Init(void); void DEV_Module_Exit(void); Note: 1. Here is some GPIO processing before and after using the LCD screen. 2. After the System_Exit(void) function is used, the OLED display will be turned off;
void DEV_Digital_Write(UWORD Pin, UBYTE Value); UBYTE DEV_Digital_Read(UWORD Pin);
void DEV_SPI_WRITE(UBYTE _dat);
For the screen, if you need to draw pictures, display Chinese and English characters, display pictures, etc., you can use the upper application to do, and we provide some basic functions here about some graphics processing in the directory STM32\STM32F103RB\User\GUI_DEV\GUI_Paint.c(.h).
Note: Because of the size of the internal RAM of STM32 and Arduino, the GUI is directly written to the RAM of the LCD.
The character font on which GUI dependent is in the directory STM32\STM32F103RB\User\Fonts
void Paint_NewImage(UWORD Width, UWORD Height, UWORD Rotate, UWORD Color) Parameters: Width: image buffer Width; Height: the Height of the image buffer; Rotate: Indicates the rotation Angle of an image Color: the initial Color of the image;
void Paint_SetClearFuntion(void (*Clear)(UWORD)); parameter: Clear: Pointer to the clear screen function, used to quickly clear the screen to a certain color;
void Paint_SetDisplayFuntion(void (*Display)(UWORD,UWORD,UWORD)); parameter: Display: Pointer to the pixel drawing function, which is used to write data to the specified location in the internal RAM of the LCD;
void Paint_SelectImage(UBYTE *image) Parameters: Image: the name of the image cache, which is actually a pointer to the first address of the image buffer
void Paint_SetRotate(UWORD Rotate) Parameters: Rotate: ROTATE_0, ROTATE_90, ROTATE_180, and ROTATE_270 correspond to 0, 90, 180, and 270 degrees respectively;
void Paint_SetMirroring(UBYTE mirror) Parameters: Mirror: indicates the image mirroring mode. MIRROR_NONE, MIRROR_HORIZONTAL, MIRROR_VERTICAL, MIRROR_ORIGIN correspond to no mirror, horizontal mirror, vertical mirror, and about image center mirror respectively.
void Paint_SetPixel(UWORD Xpoint, UWORD Ypoint, UWORD Color) Parameters: Xpoint: the X position of a point in the image buffer Ypoint: Y position of a point in the image buffer Color: indicates the Color of the dot
void Paint_Clear(UWORD Color) Parameters: Color: fill Color
void Paint_ClearWindows(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color) Parameters: Xstart: the x-starting coordinate of the window Ystart: indicates the Y starting point of the window Xend: the x-end coordinate of the window Yend: indicates the y-end coordinate of the window Color: fill Color
void Paint_DrawPoint(UWORD Xpoint, UWORD Ypoint, UWORD Color, DOT_PIXEL Dot_Pixel, DOT_STYLE Dot_Style) Parameters: Xpoint: indicates the X coordinate of a point Ypoint: indicates the Y coordinate of a point Color: fill Color Dot_Pixel: The size of the dot, providing a default of eight size points typedef enum { DOT_PIXEL_1X1 = 1, // 1 x 1 DOT_PIXEL_2X2 , // 2 X 2 DOT_PIXEL_3X3 , // 3 X 3 DOT_PIXEL_4X4 , // 4 X 4 DOT_PIXEL_5X5 , // 5 X 5 DOT_PIXEL_6X6 , // 6 X 6 DOT_PIXEL_7X7 , // 7 X 7 DOT_PIXEL_8X8 , // 8 X 8 } DOT_PIXEL; Dot_Style: the size of a point that expands from the center of the point or from the bottom left corner of the point to the right and up typedef enum { DOT_FILL_AROUND = 1, DOT_FILL_RIGHTUP, } DOT_STYLE;
void Paint_DrawLine(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color, LINE_STYLE Line_Style , LINE_STYLE Line_Style) Parameters: Xstart: the x-starting coordinate of a line Ystart: indicates the Y starting point of a line Xend: x-terminus of a line Yend: the y-end coordinate of a line Color: fill Color Line_width: The width of the line, which provides a default of eight widths typedef enum { DOT_PIXEL_1X1 = 1, // 1 x 1 DOT_PIXEL_2X2 , // 2 X 2 DOT_PIXEL_3X3 , // 3 X 3 DOT_PIXEL_4X4 , // 4 X 4 DOT_PIXEL_5X5 , // 5 X 5 DOT_PIXEL_6X6 , // 6 X 6 DOT_PIXEL_7X7 , // 7 X 7 DOT_PIXEL_8X8 , // 8 X 8 } DOT_PIXEL; Line_Style: line style. Select whether the lines are joined in a straight or dashed way typedef enum { LINE_STYLE_SOLID = 0, LINE_STYLE_DOTTED, } LINE_STYLE;
void Paint_DrawRectangle(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill) Parameters: Xstart: the starting X coordinate of the rectangle Ystart: indicates the Y starting point of the rectangle Xend: X terminus of the rectangle Yend: specifies the y-end coordinate of the rectangle Color: fill Color Line_width: The width of the four sides of a rectangle. Default eight widths are provided typedef enum { DOT_PIXEL_1X1 = 1, // 1 x 1 DOT_PIXEL_2X2 , // 2 X 2 DOT_PIXEL_3X3 , // 3 X 3 DOT_PIXEL_4X4 , // 4 X 4 DOT_PIXEL_5X5 , // 5 X 5 DOT_PIXEL_6X6 , // 6 X 6 DOT_PIXEL_7X7 , // 7 X 7 DOT_PIXEL_8X8 , // 8 X 8 } DOT_PIXEL; Draw_Fill: Fill, whether to fill the inside of the rectangle typedef enum { DRAW_FILL_EMPTY = 0, DRAW_FILL_FULL, } DRAW_FILL;
void Paint_DrawCircle(UWORD X_Center, UWORD Y_Center, UWORD Radius, UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill) Parameters: X_Center: the x-coordinate of the center of a circle Y_Center: Y coordinate of the center of a circle Radius: indicates the Radius of a circle Color: fill Color Line_width: The width of the arc, with a default of 8 widths typedef enum { DOT_PIXEL_1X1 = 1, // 1 x 1 DOT_PIXEL_2X2 , // 2 X 2 DOT_PIXEL_3X3 , // 3 X 3 DOT_PIXEL_4X4 , // 4 X 4 DOT_PIXEL_5X5 , // 5 X 5 DOT_PIXEL_6X6 , // 6 X 6 DOT_PIXEL_7X7 , // 7 X 7 DOT_PIXEL_8X8 , // 8 X 8 } DOT_PIXEL; Draw_Fill: fill, whether to fill the inside of the circle typedef enum { DRAW_FILL_EMPTY = 0, DRAW_FILL_FULL, } DRAW_FILL;
void Paint_DrawChar(UWORD Xstart, UWORD Ystart, const char Ascii_Char, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background) Parameters: Xstart: the x-coordinate of the left vertex of a character Ystart: the Y coordinate of the font's left vertex Ascii_Char: indicates the Ascii character Font: Ascii visual character library, in the Fonts folder provides the following Fonts: Font8: 5*8 font Font12: 7*12 font Font16: 11*16 font Font20: 14*20 font Font24: 17*24 font Color_Foreground: Font color Color_Background: indicates the background color
void Paint_DrawString_EN(UWORD Xstart, UWORD Ystart, const char * pString, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background) Parameters: Xstart: the x-coordinate of the left vertex of a character Ystart: the Y coordinate of the font's left vertex PString: string, string is a pointer Font: Ascii visual character library, in the Fonts folder provides the following Fonts: Font8: 5*8 font Font12: 7*12 font Font16: 11*16 font Font20: 14*20 font Font24: 17*24 font Color_Foreground: Font color Color_Background: indicates the background color
void Paint_DrawString_CN(UWORD Xstart, UWORD Ystart, const char * pString, cFONT* font, UWORD Color_Foreground, UWORD Color_Background) Parameters: Xstart: the x-coordinate of the left vertex of a character Ystart: the Y coordinate of the font's left vertex PString: string, string is a pointer Font: GB2312 encoding character Font library, in the Fonts folder provides the following Fonts: Font12CN: ASCII font 11*21, Chinese font 16*21 Font24CN: ASCII font24 *41, Chinese font 32*41 Color_Foreground: Font color Color_Background: indicates the background color
void Paint_DrawNum(UWORD Xpoint, UWORD Ypoint, double Nummber, sFONT* Font, UWORD Digit, UWORD Color_Foreground, UWORD Color_Background) Parameters: Xpoint: the x-coordinate of the left vertex of a character Ypoint: the Y coordinate of the left vertex of the font Nummber: indicates the number displayed, which can be a decimal Digit: It's a decimal number Font: Ascii visual character library, in the Fonts folder provides the following Fonts: Font8: 5*8 font Font12: 7*12 font Font16: 11*16 font Font20: 14*20 font Font24: 17*24 font Color_Foreground: Font color Color_Background: indicates the background color
void Paint_DrawTime(UWORD Xstart, UWORD Ystart, PAINT_TIME *pTime, sFONT* Font, UWORD Color_Background, UWORD Color_Foreground) Parameters: Xstart: the x-coordinate of the left vertex of a character Ystart: the Y coordinate of the font's left vertex PTime: display time, here defined a good time structure, as long as the hour, minute and second bits of data to the parameter; Font: Ascii visual character library, in the Fonts folder provides the following Fonts: Font8: 5*8 font Font12: 7*12 font Font16: 11*16 font Font20: 14*20 font Font24: 17*24 font Color_Foreground: Font color Color_Background: indicates the background color
Note: all the demos have been tested on the Arduino uno, you need to make sure the connection is correct if you want to use other Arduino.
LCD | UNO |
VCC | 5V |
GND | GND |
DIN | D11 |
CLK | D13 |
CS | D10 |
DC | D7 |
RST | D8 |
BL | D9 |
The connection diagram is as follows (click to enlarge):
Take Arduino UNO controlling a 1.54-inch LCD as an example, open the Arduino\LCD_1inch54 directory:
Of which:
LCD_1inch54.ino: open with Arduino IDE;
LCD_Driver.cpp(.h): is the driver of the LCD screen;
DEV_Config.cpp(.h): It is the hardware interface definition, which encapsulates the read and write pin levels, SPI transmission data, and pin initialization;
font8.cpp, font12.cpp, font16.cpp, font20.cpp, font24.cpp, font24CN.cpp, fonts.h: fonts for characters of different sizes;
image.cpp(.h): is the image data, which can convert any BMP image into a 16-bit true color image array through Img2Lcd (downloadable in the development data).
The demo is divided into bottom-layer hardware interface, middle-layer LCD screen driver, and upper-layer application.
The hardware interface is defined in the two files DEV_Config.cpp(.h), and functions such as read and write pin level, delay, and SPI transmission are encapsulated.
void DEV_Digital_Write(int pin, int value)
The first parameter is the pin, and the second is the high and low levels.
int DEV_Digital_Read(int pin)
The parameter is the pin, and the return value is the level of the read pin.
DEV_Delay_ms(unsigned int delaytime)
millisecond level delay.
DEV_SPI_WRITE(unsigned char data)
The parameter is char type, occupying 8 bits.
For the screen, if you need to draw pictures, display Chinese and English characters, display pictures, etc., you can use the upper application to do, and we provide some basic functions here about some graphics processing in the directory GUI_Paint.c(.h)
Note: Because of the size of the internal RAM of STM32 and arduino, the GUI is directly written to the RAM of the LCD.
The fonts used by the GUI all depend on the font*.cpp(h) files under the same file
void Paint_NewImage(UWORD Width, UWORD Height, UWORD Rotate, UWORD Color) Parameters: Width: image buffer Width; Height: the Height of the image buffer; Rotate: Indicates the rotation Angle of an image Color: the initial Color of the image;
void Paint_SetClearFuntion(void (*Clear)(UWORD)); parameter: Clear : Pointer to the clear screen function, used to quickly clear the screen to a certain color;
void Paint_SetDisplayFuntion(void (*Display)(UWORD,UWORD,UWORD)); parameter: Display: Pointer to the pixel drawing function, which is used to write data to the specified location in the internal RAM of the LCD;
void Paint_SelectImage(UBYTE *image) Parameters: Image: the name of the image cache, which is actually a pointer to the first address of the image buffer
void Paint_SetRotate(UWORD Rotate) Parameters: Rotate: ROTATE_0, ROTATE_90, ROTATE_180, and ROTATE_270 correspond to 0, 90, 180, and 270 degrees respectively;
void Paint_SetMirroring(UBYTE mirror) Parameters: Mirror: indicates the image mirroring mode. MIRROR_NONE, MIRROR_HORIZONTAL, MIRROR_VERTICAL, MIRROR_ORIGIN correspond to no mirror, horizontal mirror, vertical mirror, and about image center mirror respectively.
void Paint_SetPixel(UWORD Xpoint, UWORD Ypoint, UWORD Color) Parameters: Xpoint: the X position of a point in the image buffer Ypoint: Y position of a point in the image buffer Color: indicates the Color of the dot
void Paint_ClearWindows(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color) Parameters: Xstart: the x-starting coordinate of the window Ystart: indicates the Y starting point of the window Xend: the x-end coordinate of the window Yend: indicates the y-end coordinate of the window Color: fill Color
void Paint_DrawPoint(UWORD Xpoint, UWORD Ypoint, UWORD Color, DOT_PIXEL Dot_Pixel, DOT_STYLE Dot_Style) Parameters: Xpoint: indicates the X coordinate of a point Ypoint: indicates the Y coordinate of a point Color: fill Color Dot_Pixel: The size of the dot, providing a default of eight size points typedef enum { DOT_PIXEL_1X1 = 1, // 1 x 1 DOT_PIXEL_2X2 , // 2 X 2 DOT_PIXEL_3X3 , // 3 X 3 DOT_PIXEL_4X4 , // 4 X 4 DOT_PIXEL_5X5 , // 5 X 5 DOT_PIXEL_6X6 , // 6 X 6 DOT_PIXEL_7X7 , // 7 X 7 DOT_PIXEL_8X8 , // 8 X 8 } DOT_PIXEL; Dot_Style: the size of a point that expands from the center of the point or from the bottom left corner of the point to the right and up typedef enum { DOT_FILL_AROUND = 1, DOT_FILL_RIGHTUP, } DOT_STYLE;
void Paint_DrawLine(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color, LINE_STYLE Line_Style , LINE_STYLE Line_Style) Parameters: Xstart: the x-starting coordinate of a line Ystart: indicates the Y starting point of a line Xend: x-terminus of a line Yend: the y-end coordinate of a line Color: fill Color Line_width: The width of the line, which provides a default of eight widths typedef enum { DOT_PIXEL_1X1 = 1, // 1 x 1 DOT_PIXEL_2X2 , // 2 X 2 DOT_PIXEL_3X3 , // 3 X 3 DOT_PIXEL_4X4 , // 4 X 4 DOT_PIXEL_5X5 , // 5 X 5 DOT_PIXEL_6X6 , // 6 X 6 DOT_PIXEL_7X7 , // 7 X 7 DOT_PIXEL_8X8 , // 8 X 8 } DOT_PIXEL; Line_Style: line style. Select whether the lines are joined in a straight or dashed way typedef enum { LINE_STYLE_SOLID = 0, LINE_STYLE_DOTTED, } LINE_STYLE;
void Paint_DrawRectangle(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill) Parameters: Xstart: the starting X coordinate of the rectangle Ystart: indicates the Y starting point of the rectangle Xend: X terminus of the rectangle Yend: specifies the y-end coordinate of the rectangle Color: fill Color Line_width: The width of the four sides of a rectangle. Default eight widths are provided typedef enum { DOT_PIXEL_1X1 = 1, // 1 x 1 DOT_PIXEL_2X2 , // 2 X 2 DOT_PIXEL_3X3 , // 3 X 3 DOT_PIXEL_4X4 , // 4 X 4 DOT_PIXEL_5X5 , // 5 X 5 DOT_PIXEL_6X6 , // 6 X 6 DOT_PIXEL_7X7 , // 7 X 7 DOT_PIXEL_8X8 , // 8 X 8 } DOT_PIXEL; Draw_Fill: Fill, whether to fill the inside of the rectangle typedef enum { DRAW_FILL_EMPTY = 0, DRAW_FILL_FULL, } DRAW_FILL;
void Paint_DrawCircle(UWORD X_Center, UWORD Y_Center, UWORD Radius, UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill) Parameters: X_Center: the x-coordinate of the center of a circle Y_Center: Y coordinate of the center of a circle Radius: indicates the Radius of a circle Color: fill Color Line_width: The width of the arc, with a default of 8 widths typedef enum { DOT_PIXEL_1X1 = 1, // 1 x 1 DOT_PIXEL_2X2 , // 2 X 2 DOT_PIXEL_3X3 , // 3 X 3 DOT_PIXEL_4X4 , // 4 X 4 DOT_PIXEL_5X5 , // 5 X 5 DOT_PIXEL_6X6 , // 6 X 6 DOT_PIXEL_7X7 , // 7 X 7 DOT_PIXEL_8X8 , // 8 X 8 } DOT_PIXEL; Draw_Fill: fill, whether to fill the inside of the circle typedef enum { DRAW_FILL_EMPTY = 0, DRAW_FILL_FULL, } DRAW_FILL;
void Paint_DrawChar(UWORD Xstart, UWORD Ystart, const char Ascii_Char, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background) Parameters: Xstart: the x-coordinate of the left vertex of a character Ystart: the Y coordinate of the font's left vertex Ascii_Char: indicates the Ascii character Font: Ascii visual character library, in the Fonts folder provides the following Fonts: Font8: 5*8 font Font12: 7*12 font Font16: 11*16 font Font20: 14*20 font Font24: 17*24 font Color_Foreground: Font color Color_Background: indicates the background color
void Paint_DrawString_EN(UWORD Xstart, UWORD Ystart, const char * pString, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background) Parameters: Xstart: the x-coordinate of the left vertex of a character Ystart: the Y coordinate of the font's left vertex PString: string, string is a pointer Font: Ascii visual character library, in the Fonts folder provides the following Fonts: Font8: 5*8 font Font12: 7*12 font Font16: 11*16 font Font20: 14*20 font Font24: 17*24 font Color_Foreground: Font color Color_Background: indicates the background color
void Paint_DrawString_CN(UWORD Xstart, UWORD Ystart, const char * pString, cFONT* font, UWORD Color_Foreground, UWORD Color_Background) Parameters: Xstart: the x-coordinate of the left vertex of a character Ystart: the Y coordinate of the font's left vertex PString: string, string is a pointer Font: GB2312 encoding character Font library, in the Fonts folder provides the following Fonts: Font12CN: ASCII font 11*21, Chinese font 16*21 Font24CN: ASCII font24 *41, Chinese font 32*41 Color_Foreground: Font color Color_Background: indicates the background color
void Paint_DrawNum(UWORD Xpoint, UWORD Ypoint, double Nummber, sFONT* Font, UWORD Digit, UWORD Color_Foreground, UWORD Color_Background) Parameters: Xpoint: the x-coordinate of the left vertex of a character Ypoint: the Y coordinate of the left vertex of the font Nummber: indicates the number displayed, which can be a decimal Digit: It's a decimal number Font: Ascii visual character library, in the Fonts folder provides the following Fonts: Font8: 5*8 font Font12: 7*12 font Font16: 11*16 font Font20: 14*20 font Font24: 17*24 font Color_Foreground: Font color Color_Background: indicates the background color
void Paint_DrawFloatNum(UWORD Xpoint, UWORD Ypoint, double Nummber, UBYTE Decimal_Point, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background); parameter: Xstart: the X coordinate of the left vertex of the character Ystart: Y coordinate of the left vertex of the font Nummber: the displayed number, which is saved in double type here Decimal_Point: Displays the number of digits after the decimal point Font: Ascii code visual character font library, the following fonts are provided in the Fonts folder: Font8: 5*8 font Font12: 7*12 font Font16: 11*16 font Font20: 14*20 font Font24: 17*24 font Color_Foreground: font color Color_Background: background color
void Paint_DrawTime(UWORD Xstart, UWORD Ystart, PAINT_TIME *pTime, sFONT* Font, UWORD Color_Background, UWORD Color_Foreground) Parameters: Xstart: the x-coordinate of the left vertex of a character Ystart: the Y coordinate of the font's left vertex PTime: display time, here defined a good time structure, as long as the hour, minute and second bits of data to the parameter; Font: Ascii visual character library, in the Fonts folder provides the following Fonts: Font8: 5*8 font Font12: 7*12 font Font16: 11*16 font Font20: 14*20 font Font24: 17*24 font Color_Foreground: Font color Color_Background: indicates the background color
void Paint_DrawImage(const unsigned char *image, UWORD xStart, UWORD yStart, UWORD W_Image, UWORD H_Image) parameter: image: image address, pointing to the image information you want to display Xstart: the X coordinate of the left vertex of the character Ystart: Y coordinate of the left vertex of the font W_Image: Image width H_Image: Image height
Take Arduino UNO controlling a 1.54-inch LCD as an example, open the Arduino\LCD_1inch54 directory:
Of which:
LCD_1inch54.ino: open with Arduino IDE;
LCD_Driver.cpp(.h): is the driver of the LCD screen;
DEV_Config.cpp(.h): It is the hardware interface definition, which encapsulates the read and write pin levels, SPI transmission data, and pin initialization;
font8.cpp, font12.cpp, font16.cpp, font20.cpp, font24.cpp, font24CN.cpp, fonts.h: fonts for characters of different sizes;
image.cpp(.h): is the image data, which can convert any BMP image into a 16-bit true color image array through Img2Lcd (downloadable in the development data).
The demo is divided into bottom-layer hardware interface, middle-layer LCD screen driver, and upper-layer application.
The hardware interface is defined in the two files DEV_Config.cpp(.h), and functions such as read and write pin level, delay, and SPI transmission are encapsulated.
void DEV_Digital_Write(int pin, int value)
The first parameter is the pin, and the second is the high and low levels.
int DEV_Digital_Read(int pin)
The parameter is the pin, and the return value is the level of the read pin.
DEV_Delay_ms(unsigned int delaytime)
millisecond level delay.
DEV_SPI_WRITE(unsigned char data)
The parameter is char type, occupying 8 bits.
For the screen, if you need to draw pictures, display Chinese and English characters, display pictures, etc., you can use the upper application to do, and we provide some basic functions here about some graphics processing in the directory GUI_Paint.c(.h)
Note: Because of the size of the internal RAM of STM32 and Arduino, the GUI is directly written to the RAM of the LCD.
The fonts used by the GUI all depend on the font*.cpp(h) files under the same file
void Paint_NewImage(UWORD Width, UWORD Height, UWORD Rotate, UWORD Color) Parameters: Width: image buffer Width; Height: the Height of the image buffer; Rotate: Indicates the rotation Angle of an image Color: the initial Color of the image;
void Paint_SetClearFuntion(void (*Clear)(UWORD)); parameter: Clear: Pointer to the clear screen function used to quickly clear the screen to a certain color;
void Paint_SetDisplayFuntion(void (*Display)(UWORD,UWORD,UWORD)); parameter: Display: Pointer to the pixel drawing function, which is used to write data to the specified location in the internal RAM of the LCD;
void Paint_SelectImage(UBYTE *image) Parameters: Image: the name of the image cache, which is actually a pointer to the first address of the image buffer
void Paint_SetRotate(UWORD Rotate) Parameters: Rotate: ROTATE_0, ROTATE_90, ROTATE_180, and ROTATE_270 correspond to 0, 90, 180, and 270 degrees respectively;
void Paint_SetMirroring(UBYTE mirror) Parameters: Mirror: indicates the image mirroring mode. MIRROR_NONE, MIRROR_HORIZONTAL, MIRROR_VERTICAL, MIRROR_ORIGIN correspond to no mirror, horizontal mirror, vertical mirror, and about image center mirror respectively.
void Paint_SetPixel(UWORD Xpoint, UWORD Ypoint, UWORD Color) Parameters: Xpoint: the X position of a point in the image buffer Ypoint: Y position of a point in the image buffer Color: indicates the Color of the dot
void Paint_ClearWindows(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color) Parameters: Xstart: the x-starting coordinate of the window Ystart: indicates the Y starting point of the window Xend: the x-end coordinate of the window Yend: indicates the y-end coordinate of the window Color: fill Color
void Paint_DrawPoint(UWORD Xpoint, UWORD Ypoint, UWORD Color, DOT_PIXEL Dot_Pixel, DOT_STYLE Dot_Style) Parameters: Xpoint: indicates the X coordinate of a point Ypoint: indicates the Y coordinate of a point Color: fill Color Dot_Pixel: The size of the dot, providing a default of eight size points typedef enum { DOT_PIXEL_1X1 = 1, // 1 x 1 DOT_PIXEL_2X2 , // 2 X 2 DOT_PIXEL_3X3 , // 3 X 3 DOT_PIXEL_4X4 , // 4 X 4 DOT_PIXEL_5X5 , // 5 X 5 DOT_PIXEL_6X6 , // 6 X 6 DOT_PIXEL_7X7 , // 7 X 7 DOT_PIXEL_8X8 , // 8 X 8 } DOT_PIXEL; Dot_Style: the size of a point that expands from the center of the point or from the bottom left corner of the point to the right and up typedef enum { DOT_FILL_AROUND = 1, DOT_FILL_RIGHTUP, } DOT_STYLE;
void Paint_DrawLine(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color, LINE_STYLE Line_Style , LINE_STYLE Line_Style) Parameters: Xstart: the x-starting coordinate of a line Ystart: indicates the Y starting point of a line Xend: x-terminus of a line Yend: the y-end coordinate of a line Color: fill Color Line_width: The width of the line, which provides a default of eight widths typedef enum { DOT_PIXEL_1X1 = 1, // 1 x 1 DOT_PIXEL_2X2 , // 2 X 2 DOT_PIXEL_3X3 , // 3 X 3 DOT_PIXEL_4X4 , // 4 X 4 DOT_PIXEL_5X5 , // 5 X 5 DOT_PIXEL_6X6 , // 6 X 6 DOT_PIXEL_7X7 , // 7 X 7 DOT_PIXEL_8X8 , // 8 X 8 } DOT_PIXEL; Line_Style: line style. Select whether the lines are joined in a straight or dashed way typedef enum { LINE_STYLE_SOLID = 0, LINE_STYLE_DOTTED, } LINE_STYLE;
void Paint_DrawRectangle(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill) Parameters: Xstart: the starting X coordinate of the rectangle Ystart: indicates the Y starting point of the rectangle Xend: X terminus of the rectangle Yend: specifies the y-end coordinate of the rectangle Color: fill Color Line_width: The width of the four sides of a rectangle. Default eight widths are provided typedef enum { DOT_PIXEL_1X1 = 1, // 1 x 1 DOT_PIXEL_2X2 , // 2 X 2 DOT_PIXEL_3X3 , // 3 X 3 DOT_PIXEL_4X4 , // 4 X 4 DOT_PIXEL_5X5 , // 5 X 5 DOT_PIXEL_6X6 , // 6 X 6 DOT_PIXEL_7X7 , // 7 X 7 DOT_PIXEL_8X8 , // 8 X 8 } DOT_PIXEL; Draw_Fill: Fill, whether to fill the inside of the rectangle typedef enum { DRAW_FILL_EMPTY = 0, DRAW_FILL_FULL, } DRAW_FILL;
void Paint_DrawCircle(UWORD X_Center, UWORD Y_Center, UWORD Radius, UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill) Parameters: X_Center: the x-coordinate of the center of a circle Y_Center: Y coordinate of the center of a circle Radius: indicates the Radius of a circle Color: fill Color Line_width: The width of the arc, with a default of 8 widths typedef enum { DOT_PIXEL_1X1 = 1, // 1 x 1 DOT_PIXEL_2X2 , // 2 X 2 DOT_PIXEL_3X3 , // 3 X 3 DOT_PIXEL_4X4 , // 4 X 4 DOT_PIXEL_5X5 , // 5 X 5 DOT_PIXEL_6X6 , // 6 X 6 DOT_PIXEL_7X7 , // 7 X 7 DOT_PIXEL_8X8 , // 8 X 8 } DOT_PIXEL; Draw_Fill: fill, whether to fill the inside of the circle typedef enum { DRAW_FILL_EMPTY = 0, DRAW_FILL_FULL, } DRAW_FILL;
void Paint_DrawChar(UWORD Xstart, UWORD Ystart, const char Ascii_Char, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background) Parameters: Xstart: the x-coordinate of the left vertex of a character Ystart: the Y coordinate of the font's left vertex Ascii_Char: indicates the Ascii character Font: Ascii visual character library, in the Fonts folder provides the following Fonts: Font8: 5*8 font Font12: 7*12 font Font16: 11*16 font Font20: 14*20 font Font24: 17*24 font Color_Foreground: Font color Color_Background: indicates the background color
void Paint_DrawString_EN(UWORD Xstart, UWORD Ystart, const char * pString, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background) Parameters: Xstart: the x-coordinate of the left vertex of a character Ystart: the Y coordinate of the font's left vertex PString: string, string is a pointer Font: Ascii visual character library, in the Fonts folder provides the following Fonts: Font8: 5*8 font Font12: 7*12 font Font16: 11*16 font Font20: 14*20 font Font24: 17*24 font Color_Foreground: Font color Color_Background: indicates the background color
void Paint_DrawString_CN(UWORD Xstart, UWORD Ystart, const char * pString, cFONT* font, UWORD Color_Foreground, UWORD Color_Background) Parameters: Xstart: the x-coordinate of the left vertex of a character Ystart: the Y coordinate of the font's left vertex PString: string, string is a pointer Font: GB2312 encoding character Font library, in the Fonts folder provides the following Fonts: Font12CN: ASCII font 11*21, Chinese font 16*21 Font24CN: ASCII font24 *41, Chinese font 32*41 Color_Foreground: Font color Color_Background: indicates the background color
void Paint_DrawNum(UWORD Xpoint, UWORD Ypoint, double Nummber, sFONT* Font, UWORD Digit, UWORD Color_Foreground, UWORD Color_Background) Parameters: Xpoint: the x-coordinate of the left vertex of a character Ypoint: the Y coordinate of the left vertex of the font Nummber: indicates the number displayed, which can be a decimal Digit: It's a decimal number Font: Ascii visual character library, in the Fonts folder provides the following Fonts: Font8: 5*8 font Font12: 7*12 font Font16: 11*16 font Font20: 14*20 font Font24: 17*24 font Color_Foreground: Font color Color_Background: indicates the background color
void Paint_DrawFloatNum(UWORD Xpoint, UWORD Ypoint, double Nummber, UBYTE Decimal_Point, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background); parameter: Xstart: the X coordinate of the left vertex of the character Ystart: Y coordinate of the left vertex of the font Nummber: the displayed number, which is saved in double type here Decimal_Point: Displays the number of digits after the decimal point Font: Ascii code visual character font library, the following fonts are provided in the Fonts folder: Font8: 5*8 font Font12: 7*12 font Font16: 11*16 font Font20: 14*20 font Font24: 17*24 font Color_Foreground: font color Color_Background: background color
void Paint_DrawTime(UWORD Xstart, UWORD Ystart, PAINT_TIME *pTime, sFONT* Font, UWORD Color_Background, UWORD Color_Foreground) Parameters: Xstart: the x-coordinate of the left vertex of a character Ystart: the Y coordinate of the font's left vertex PTime: display time, here defined as a good time structure, as long as the hour, minute and second bits of data to the parameter; Font: Ascii visual character library, in the Fonts folder, provides the following Fonts: Font8: 5*8 font Font12: 7*12 font Font16: 11*16 font Font20: 14*20 font Font24: 17*24 font Color_Foreground: Font color Color_Background: indicates the background color
void Paint_DrawImage(const unsigned char *image, UWORD xStart, UWORD yStart, UWORD W_Image, UWORD H_Image) parameter: image: image address, pointing to the image information you want to display Xstart: the X coordinate of the left vertex of the character Ystart: Y coordinate of the left vertex of the font W_Image: Image width H_Image: Image height