1Module Source>>>
Product Physical Display:

Data Download Link:https://pan.baidu.com/s/1lSjp7ISiKhkaXwqJsEOu2g
Data Extraction Code:8888
2Specifications>>>
The following information can be found in the manufacturer’s screen specification document.

Operating Voltage:3.3V
Operating Current:20mA
Module Size:44(H) x 36(V) x 2.8(D) MM
Pixel Pitch:0.135(H) x 0.135(V)
Driver Chip:GC9A01
Communication Protocol:SPI
3Porting Process>>>
Our goal is to port the routine to the Lichuang CW32F030C8T6 development board. Follow the steps below to complete the porting.
- Import the source code into the project;
- Make rough modifications based on compilation errors;
- Modify pin configurations;
- Modify timing configurations;
- Porting verification.
3.1View Data
Open the manufacturer’s data routine (routine download can be found in the Baidu Cloud link). The specific path can be found in the routine path.
3.2Porting to ProjectCopy the 【LCD】 folder from the manufacturer’s data path into your own project. Your project must have a millisecond-level delay function. (The project can refer to the entry manual project template)
Open your project and import the .c and .h files that we just copied.

Change sys.h in the lcd_init.h file to board.h, and also change sys.h in the lcd.h file to board.h.
(Expand the project directory of lcd.c and lcd_init.c on the left, and you will find lcd_init.h and lcd.h)

Comment out delay.h in the lcd_init.c file, and also comment out delay.h in the lcd.c file.

Define three macros, u32, u16, and u8 in both lcd_init.h and lcd.h files.
#ifndef u8#define u8 uint8_t#endif#ifndef u16#define u16 uint16_t#endif#ifndef u32#define u32 uint32_t#endif

After recompiling, only the LCD pin initialization content reports an error, and next we need to select the pins.
3.3Pin SelectionThis screen requires the setting of 8 interfaces.
The module is a slave of the SPI communication protocol, SCL is the SPI signal line (SCK), SDA is the SPI output line (MOSI), and CS is the SPI chip select line (NSS).
If the MCU’s GPIO pins are insufficient, you can leave two pin interfaces of the screen unconnected to the MCU’s GPIO.
- Connect RES to the MCU’s reset pin, so that when the MCU resets, the screen also resets;
- BLK can be connected to 3.3V or left floating, at the cost of not being able to control the backlight brightness.
Next, we will explain software SPI porting and hardware SPI porting.
3.4Software SPI Porting
The current manufacturer’s source code uses a software SPI interface, and the SPI timing part has been completed by the manufacturer, so we only need to configure the pins and delays accordingly. Please connect the screen pins as per your requirements. The selected pins are shown in the table below.

Define the LCD port pin porting in lcd_init.h
//-----------------LCD Port Porting----------------#define LCD_GPIO_RCC_ENABLE() __RCC_GPIOC_CLK_ENABLE()#define LCD_GPIO_PORT CW_GPIOA#define LCD_CLK_PIN GPIO_PIN_5#define LCD_SDA_PIN GPIO_PIN_7#define LCD_RES_PIN GPIO_PIN_3#define LCD_DC_PIN GPIO_PIN_2#define LCD_CS_PIN GPIO_PIN_4#define LCD_BLK_PIN GPIO_PIN_1
After selecting the pins, enter the project and start writing the screen pin initialization code.
Change the **void LCD_GPIO_Init(void)** in the lcd_init.c source code to the following code.
void LCD_GPIO_Init(void){ GPIO_InitTypeDef GPIO_InitStruct; // GPIO initialization structure LCD_GPIO_RCC_ENABLE(); // Enable GPIO clock GPIO_InitStruct.Pins = LCD_CLK_PIN| // GPIO pins LCD_SDA_PIN| LCD_RES_PIN| LCD_DC_PIN| LCD_CS_PIN| LCD_BLK_PIN; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; // Push-pull output GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; // High output speed GPIO_Init(LCD_GPIO_PORT, &GPIO_InitStruct); // Initialize}
Change the LCD port definition macros in lcd_init.h to the right image.
//-----------------LCD Port Definition----------------#define LCD_SCLK_Clr() GPIO_WritePin(LCD_GPIO_PORT,LCD_CLK_PIN,GPIO_Pin_RESET)//SCL=SCLK#define LCD_SCLK_Set() GPIO_WritePin(LCD_GPIO_PORT,LCD_CLK_PIN,GPIO_Pin_SET)#define LCD_MOSI_Clr() GPIO_WritePin(LCD_GPIO_PORT,LCD_SDA_PIN,GPIO_Pin_RESET)//SDA=MOSI#define LCD_MOSI_Set() GPIO_WritePin(LCD_GPIO_PORT,LCD_SDA_PIN,GPIO_Pin_SET)#define LCD_RES_Clr() GPIO_WritePin(LCD_GPIO_PORT,LCD_RES_PIN,GPIO_Pin_RESET)//RES#define LCD_RES_Set() GPIO_WritePin(LCD_GPIO_PORT,LCD_RES_PIN,GPIO_Pin_SET)#define LCD_DC_Clr() GPIO_WritePin(LCD_GPIO_PORT,LCD_DC_PIN,GPIO_Pin_RESET)//DC#define LCD_DC_Set() GPIO_WritePin(LCD_GPIO_PORT,LCD_DC_PIN,GPIO_Pin_SET)#define LCD_CS_Clr() GPIO_WritePin(LCD_GPIO_PORT,LCD_CS_PIN,GPIO_Pin_RESET)//CS#define LCD_CS_Set() GPIO_WritePin(LCD_GPIO_PORT,LCD_CS_PIN,GPIO_Pin_SET)#define LCD_BLK_Clr() GPIO_WritePin(LCD_GPIO_PORT,LCD_BLK_PIN,GPIO_Pin_RESET)//BLK#define LCD_BLK_Set() GPIO_WritePin(LCD_GPIO_PORT,LCD_BLK_PIN,GPIO_Pin_SET)
Source Port Definition
Modified Port Definition
At this point, the software SPI has been ported, please proceed to section 4 for porting verification.
3.5Hardware SPI Porting
Compared to software SPI, hardware SPI relies on the hardware SPI controller, where all clock edge sampling, clock generation, and timing control are completed by hardware. This reduces CPU usage and increases operating speed. Software SPI controls IO output high and low levels through code, simulating SPI timing, which is slower and less reliable.
To use hardware SPI to drive the screen, you need to confirm whether the pins used have SPI peripheral functionality. This can be checked through the data manual.
The data manual and user manual are available in the Baidu Cloud data, see the entry manual for the link.
The current use is a hardware SPI interface, and we only need to control the screen without needing to read data from it, so we use a 3-wire SPI, only using the clock line SCK, master output slave input line MOSI, and software-controlled chip select line NSS. The NSS is controlled by software, so other than the SCL(SCK)/SDA(MOSI) pins that need to use hardware SPI function pins, other pins can use other GPIOs on the development board.Here we choose to use the SPI multiplexing function of PA5/PA7. Other corresponding screen pins should be connected as per your requirements. The selected pins are shown in the hardware SPI wiring table.
Pins with SPI Functionality
Hardware SPI Wiring
Define the LCD port pin porting in lcd_init.h
//-----------------OLED Port Porting Definition----------------#define OLED_RCC_GPIO_ENABLE() __RCC_GPIOA_CLK_ENABLE()#define OLED_RCC_SPI1_ENABLE() __RCC_SPI1_CLK_ENABLE()//GPIO AF#define SPI1_AF_SCK() PA05_AFx_SPI1SCK()#define SPI1_AF_MOSI() PA07_AFx_SPI1MOSI()#define BSP_SPI1 CW_SPI1#define OLED_GPIO_PORT CW_GPIOA#define OLED_SCL_PIN GPIO_PIN_5#define OLED_MOSI_PIN GPIO_PIN_7#define OLED_RES_PIN GPIO_PIN_3#define OLED_DC_PIN GPIO_PIN_2#define OLED_CS_PIN GPIO_PIN_4
After selecting the pins, enter the project and start writing the screen pin initialization code.
The pin initialization configuration is shown in the following code.
void LCD_GPIO_Init(void){ GPIO_InitTypeDef GPIO_InitStruct; // GPIO initialization structure LCD_GPIO_RCC_ENABLE(); // Enable GPIO clock LCD_SPI1_RCC_ENABLE(); // Enable SPI1 clock SPI1_AF_SCK(); SPI1_AF_MOSI(); GPIO_InitStruct.Pins = LCD_CLK_PIN| // GPIO pins LCD_SDA_PIN| LCD_RES_PIN| LCD_DC_PIN| LCD_CS_PIN| LCD_BLK_PIN; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; // Push-pull output GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; // High output speed GPIO_Init(LCD_GPIO_PORT, &GPIO_InitStruct); // Initialize SPI_InitTypeDef SPI_InitStructure; // SPI initialization structure SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; // Full duplex SPI_InitStructure.SPI_Mode = SPI_Mode_Master; // Master mode SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; // Frame data length is 8 bits SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; // Clock idle level is high SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; // Sample on the second edge SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; // Chip select signal controlled by SSI register SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8; // Baud rate is 8 times the PCLK SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; // Most significant bit MSB sent first SPI_InitStructure.SPI_Speed = SPI_Speed_Low; // Low-speed SPI SPI_Init(BSP_SPI1, &SPI_InitStructure); // Initialize SPI_Cmd(BSP_SPI1, ENABLE); // Enable SPI1}
Modify the LCD port definition macros in lcd_init.h.
//-----------------LCD Port Definition----------------#define LCD_SCLK_Clr() GPIO_WritePin(LCD_GPIO_PORT,LCD_CLK_PIN,GPIO_Pin_RESET)//SCL=SCLK#define LCD_SCLK_Set() GPIO_WritePin(LCD_GPIO_PORT,LCD_CLK_PIN,GPIO_Pin_SET)#define LCD_MOSI_Clr() GPIO_WritePin(LCD_GPIO_PORT,LCD_SDA_PIN,GPIO_Pin_RESET)//SDA=MOSI#define LCD_MOSI_Set() GPIO_WritePin(LCD_GPIO_PORT,LCD_SDA_PIN,GPIO_Pin_SET)#define LCD_RES_Clr() GPIO_WritePin(LCD_GPIO_PORT,LCD_RES_PIN,GPIO_Pin_RESET)//RES#define LCD_RES_Set() GPIO_WritePin(LCD_GPIO_PORT,LCD_RES_PIN,GPIO_Pin_SET)#define LCD_DC_Clr() GPIO_WritePin(LCD_GPIO_PORT,LCD_DC_PIN,GPIO_Pin_RESET)//DC#define LCD_DC_Set() GPIO_WritePin(LCD_GPIO_PORT,LCD_DC_PIN,GPIO_Pin_SET)#define LCD_CS_Clr() GPIO_WritePin(LCD_GPIO_PORT,LCD_CS_PIN,GPIO_Pin_RESET)//CS#define LCD_CS_Set() GPIO_WritePin(LCD_GPIO_PORT,LCD_CS_PIN,GPIO_Pin_SET)#define LCD_BLK_Clr() GPIO_WritePin(LCD_GPIO_PORT,LCD_BLK_PIN,GPIO_Pin_RESET)//BLK#define LCD_BLK_Set() GPIO_WritePin(LCD_GPIO_PORT,LCD_BLK_PIN,GPIO_Pin_SET)
Initialization is complete, and we also need to modify the data sending part. The source code uses software SPI, and the timing is completed by the manufacturer. We need to modify it for hardware SPI.
In the lcd_init.c file, change the source code’s void LCD_Writ_Bus(u8 dat) function to the following.

/****************************************************************************** Function Description: LCD serial data write function Input Data: dat Data to be written serially Return Value: None******************************************************************************/void LCD_Writ_Bus(u8 dat){ LCD_CS_Clr(); while (SPI_GetFlagStatus(BSP_SPI1, SPI_FLAG_TXE) == RESET); SPI_SendData(BSP_SPI1, dat); // Send data while (SPI_GetFlagStatus(BSP_SPI1, SPI_FLAG_RXNE) == RESET); uint16_t temp = SPI_ReceiveData(BSP_SPI1); // Return data LCD_CS_Set();}
At this point, the hardware SPI has been ported, please proceed to section 4 for porting verification.
/* * Change Logs: * Date Author Notes * 2024-06-19 LCKFB-LP first version */#include "board.h"#include "stdio.h"#include "bsp_uart.h"#include "lcd.h"#include "lcd_init.h"int32_t main(void){ board_init(); // Development board initialization uart1_init(115200); // Serial port 1 baud rate 115200 LCD_Init();//Screen initialization LCD_Fill(0,0,LCD_W,LCD_H,BLACK);//Clear the entire screen to black float t = 0; while(1) { LCD_ShowString(60,16*4,(uint8_t *)"LCD_W:",WHITE,BLACK,16,0); LCD_ShowIntNum(120,16*4,LCD_W,3,WHITE,BLACK,16); LCD_ShowString(60,16*5,(uint8_t *)"LCD_H:",WHITE,BLACK,16,0); LCD_ShowIntNum(120,16*5,LCD_H,3,WHITE,BLACK,16); LCD_ShowString(76,16*6,(uint8_t *)"Num:",WHITE,BLACK,16,0); LCD_ShowFloatNum1(120,16*6,t,4,WHITE,BLACK,16); t+=0.11; delay_ms(1000); }}
Power-on effect:

Successful Porting Example Code:
Link:https://pan.baidu.com/s/1daAztzxZVJ6O3bLovIRiTA?pwd=LCKF
Extraction Code: LCKF
ENDPrevious ReviewsREVIEW
[Product Application] CW32 Electric Tool Product Open Source
[Product Solution] Low-Cost Electric Tool Solution Based on CW32L010
[Product Application] Smart Power Bank Based on CW32 (Open Source Solution)
[Product Application] CW-W88 Pump General Control Board Design Scheme (Open Source)
[Product Application] Controller Product Scheme Based on CW32 Angle Grinder
[Product Solution] Low-Voltage Brushless Fan Sensorless Controller Based on CW32F030C8
[Product Solution] Brushless DC Hollow Cup Motor Sensor Control Drive Scheme Based on CW32
[Product Solution] Brushless DC Hollow Cup Motor Sensorless Square Wave Control Drive Scheme Based on CW32
[Product Solution] Digital Voltage and Current Meter Product Scheme Based on CW32F003E4P7
[Product Solution] Low-Cost Industrial Instrument Based on CW32L010
CW32 Ecological Community (WX) Group
Scan to Join QQ GroupGroup 4| 478586307
Get data and“Developer Support Program”First-hand information
