饭盒派开发板配置了TFT接口及相应的显示屏,其接口如图1所示。
图1 TFT显示屏接口
针对显示屏所连接的引脚,其引脚配置的函数为:
void LCD_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
__RCC_GPIOB_CLK_ENABLE();
__RCC_GPIOA_CLK_ENABLE();
GPIO_InitStruct.IT = GPIO_IT_NONE;
GPIO_InitStruct.Mode= GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Speed= GPIO_SPEED_HIGH;
GPIO_InitStruct.Pins= GPIO_PIN_4| GPIO_PIN_5| GPIO_PIN_6| GPIO_PIN_7;
GPIO_Init(CW_GPIOB, &GPIO_InitStruct);
GPIO_InitStruct.Pins= GPIO_PIN_15;
GPIO_Init(CW_GPIOA, &GPIO_InitStruct);
}
以GPIO口模拟SPI方式字节数据的函数为:
void SPI_WriteData(unsigned char Data)
{
unsigned char i=0;
for(i=8;i>0;i--)
{
if(Data&0x80)
LCD_SDA_SET;
else LCD_SDA_CLR;
LCD_SCL_CLR;
LCD_SCL_SET;
Data<<=1;
}
}
用于满屏色彩彩色的函数为:
void Color_Test(void)
{
unsigned int i=1;
Lcd_Clear(GRAY0);
Gui_DrawFont_GBK16(20,10,BLUE,GRAY0,"Color
Test");
Delay(0xFFFF);
Delay(0xFFFF);
while(i
{
Lcd_Clear(WHITE);
Delay(0xFFFF);
Delay(0xFFFF);
Lcd_Clear(BLACK);
Delay(0xFFFF);
Delay(0xFFFF);
Lcd_Clear(RED);
Delay(0xFFFF);
Delay(0xFFFF);
Lcd_Clear(GREEN);
Delay(0xFFFF);
Delay(0xFFFF);
Lcd_Clear(BLUE);
Delay(0xFFFF);
Delay(0xFFFF);
}
}
由于在色彩刷新过程中其速度很快,因此在色彩切换时应添加必要的演示。
实现色彩测试和文本信息显示的主程序为:
int32_t main(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
RCC_HSI_Enable(RCC_HSIOSC_DIV6);
__RCC_GPIOA_CLK_ENABLE();
GPIO_InitStruct.IT = GPIO_IT_NONE;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pins = LED_GPIO_PINS;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_Init(LED_GPIO_PORT, &GPIO_InitStruct);
__RCC_GPIOC_CLK_ENABLE();
GPIO_InitStruct.IT= GPIO_IT_NONE;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pins = GPIO_PIN_13;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
Lcd_Init();
Color_Test();
Delay(0xFFFF);
Delay(0xFFFF);
Redraw_Mainmenu();
Delay(0xFFFF);
Delay(0xFFFF);
Lcd_Clear(GRAY0);Gui_DrawFont_GBK16(15,5,BLACK,GRAY0,"HELLOworld");
Gui_DrawFont_GBK16(15,25,RED,GRAY0,"LCD OK DISPLAY"); Delay(0xFFFF);
Delay(0xFFFF);
Num_Test();
showimage(gImage_tb);
while(1);
}
经程序的编译与下载,其显示效果如图2所示。
图2 显示效果
为实现图像的显示功能,为其配置的显示函数为:
void showimage(const unsigned char *p)
{
int i,j,k;
unsigned char picH,picL;
Lcd_Clear(RED);
for(k=0;k<3;k++)
{
for(j=0;j<2;j++)
{
Lcd_SetRegion(50*j+2,50*k,50*j+49,50*k+49);
for(i=0;i<50*50;i++)
{
picL=*(p+i*2+1);
picH=*(p+i*2);
LCD_WriteData_16Bit(picH<<8|picL);
}
}
}
}
该显示函数的功能是对一幅50*50像素点的图片进行显示,并构成一个3行2列的图片阵列,其显示效果如图3所示。
图3 显示图像
为进行汉字的显示及按键的绘制,其测试函数为:
void Redraw_Mainmenu(void)
{
Lcd_Clear(GRAY0);
Gui_DrawFont_GBK16(15,5,BLUE,GRAY0,"实验平台");
DisplayButtonUp(85,27,125,45);
DisplayButtonUp(85,49,125,67);
Delay(0xFFFF);
Delay(0xFFFF);
}
该函数的显示效果如图4所示:
图4 显示汉字与按键
为了能在编程过程中直接以显示的内容来编写显示语句,它是通过索引表来进行转换处理的,其结构定义为:
struct typ FNT_GB162
{
unsigned char Index[2];
char Msk[32];
};
所用的字库结构为:
//宋体字5号
#define
hz16_num 100
const
struct typFNT_GB162 hz16[] = {
#if
USE_ONCHIP_FLASH_FONT
...
"实",0x02,0x00,0x01,0x00,0x7F,0xFE,0x40,0x02,0x88,0x84,0x04,0x80,0x04,0x80,0x10,0x80,0x08,0x80,0x08,0x80,0xFF,0xFE,0x01,0x40,0x02,0x20,0x04,0x10,0x18,0x08,0x60,0x04,/ "实",2 /
"验",0x00,0x20,0xF8,0x20,0x08,0x50,0x48,0x50,0x48,0x88,0x49,0x04,0x4A,0xFA,0x7C,0x00,0x04,0x44,0x04,0x24,0x1D,0x24,0xE4,0xA8,0x44,0x88,0x04,0x10,0x2B,0xFE,0x10,0x00,/ *"
验",3* /
"平",0x00,0x00,0x7F,0xFC,0x01,0x00,0x01,0x00,0x11,0x10,0x09,0x10,0x09,0x20,0x01,0x00,0xFF,0xFE,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,/ *"
平",4* /
"台",0x02,0x00,0x02,0x00,0x04,0x00,0x08,0x20,0x10,0x10,0x20,0x08,0x7F,0xFC,0x20,0x04,0x00,0x00,0x1F,0xF0,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1F,0xF0,0x10,0x10,/ *"
台",5* /
...
#endif
0x00,
};
在需要显示自己的内容时,需使用相应的软件来提取相应的字模来完善该字库,其提取界面如图5所示,采用的格式如图6所示。
图5 提取工具
图6 提取格式