[Xiaohua HC32F448 Review] + TFT screen display driver
[Copy link]
Although OLED screens can meet certain display needs, TFT screens are essential for image display, etc.
In order to save the trouble of wiring, the display interface on the development board can be used, as shown in Figure 1.
Figure 1 Display interface
The connection relationship between the TFT screen and the development board is:
BLK:PB10
SCK:PA12
DSI:PC4
D/C:PE12
RST:PE14
CS: PC7
The pins for outputting high and low levels are defined as:
#define LCD_CS_High() GPIO_SetPins(GPIO_PORT_C, GPIO_PIN_07) //CS
#define LCD_CS_Low() GPIO_ResetPins(GPIO_PORT_C, GPIO_PIN_07)
#define LCD_REST_High() GPIO_SetPins(GPIO_PORT_E, GPIO_PIN_14) //RES
#define LCD_REST_Low() GPIO_ResetPins(GPIO_PORT_E, GPIO_PIN_14)
#define LCD_DC_High() GPIO_SetPins(GPIO_PORT_E, GPIO_PIN_12) //DC
#define LCD_DC_Low() GPIO_ResetPins(GPIO_PORT_E, GPIO_PIN_12)
#define LCD_SDI_High() GPIO_SetPins(GPIO_PORT_C, GPIO_PIN_04) //DIN
#define LCD_SDI_Low() GPIO_ResetPins(GPIO_PORT_C, GPIO_PIN_04)
#define LCD_SCK_High() GPIO_SetPins(GPIO_PORT_A, GPIO_PIN_12) //CLK
#define LCD_SCK_Low() GPIO_ResetPins(GPIO_PORT_A, GPIO_PIN_12)
#define LCD_LED_High() GPIO_SetPins(GPIO_PORT_B, GPIO_PIN_10) //BLK
The function for configuring the pins used by the TFT screen is:
void Init_TFT (void)
{
stc_gpio_init_tstcGpioInit;
(void)GPIO_StructInit(&stcGpioInit);
stcGpioInit.u16PinState = PIN_STAT_RST;
stcGpioInit.u16PinDir = PIN_DIR_OUT;
(void)GPIO_Init(GPIO_PORT_A, GPIO_PIN_12, &stcGpioInit);
(void)GPIO_Init(GPIO_PORT_B, GPIO_PIN_10, &stcGpioInit);
(void)GPIO_Init(GPIO_PORT_C, GPIO_PIN_04, &stcGpioInit);
(void)GPIO_Init(GPIO_PORT_C, GPIO_PIN_07, &stcGpioInit);
(void)GPIO_Init(GPIO_PORT_E, GPIO_PIN_12, &stcGpioInit);
(void)GPIO_Init(GPIO_PORT_E, GPIO_PIN_14, &stcGpioInit);
}
The function to send byte data in simulated SPI mode is:
void LCD_Writ_Bus(unsigned char com)
{
unsigned char uci;
for(uci=0;uci<8;uci++)
{
if(com & 0x80)
{
LCD_SDI_High();
}
else
{
LCD_SDI_Low();
}
com = com << 1;
LCD_SCK_Low();
LCD_SCK_High();
}
}
The function to erase the screen with a specified color is:
void LCD_Clear(unsigned int Color)
{
char VH,VL;
unsigned int i,j;
VH=Color>>8;
VL=Color;
Address_set(0,0,LCD_W-1,LCD_H-1);
for(i=0;i<LCD_W;i++)
{
for (j=0;j<LCD_H;j++)
{
LCD_WR_DATA8(VH);
LCD_WR_DATA8(VL);
}
}
}
The function that implements string display is:
void LCD_ShowString(unsigned int x,unsigned int y,const char *p)
{
while(*p!='\0')
{
if(x>LCD_W-16){x=0;y+=16;}
if(y>LCD_H-16){y=x=0;}
LCD_ShowChar(x,y,*p,0);
x+=8;
p++;
}
}
The function that realizes icon display is:
void show_tb(unsigned int x,unsigned int y,unsigned int n) //200*200
{
unsigned int i,j,k;
unsigned int da;
k=0;
for(i=0;i<50;i++)
{
for(j=0;j<50;j++)
{
if(n==0) da=gImage_tb[k*2];
...
da=da<<8;
if(n==0) da|=gImage_tb[k*2+1];
...
POINT_COLOR=da;
LCD_DrawPoint(x-j,y+i);
k++;
}
}
}
The main program to implement the display test is:
int32_t main(void)
{
LL_PERIPH_WE(LL_PERIPH_GPIO);
LED_Init();
Init_TFT();
tft_Init();
BACK_COLOR=RED;
POINT_COLOR=WHITE;
LCD_Clear(RED);
LCD_ShowString(80,10,"HC32F448");
LCD_ShowString(80,40,"2.2' TFT");
LCD_DrawLine(0,60, 239, 60);
LCD_DrawLine(0,290, 239, 290);
LCD_ShowString(80,295,"jinglixixi");
show_tb(50,5,0);
LL_PERIPH_WP(LL_PERIPH_GPIO);
for (;;) {
LED_G_TOGGLE();
DDL_DelayMS(DLY_MS);
}
}
After the program is compiled and downloaded, the test results are shown in Figure 2, indicating that the function is correct.
Figure 2 Display effect
|