CW32饭盒派开发板有提供三种屏幕的显示接口,分别是J3、J4、J5,支持IIC,SPI的通讯方式。由于武汉芯源官方提供了1.77寸TFT屏,因此使用这个屏就可展开GUI的项目开发。开箱贴中也展示了板子默认的出厂程序是通过调节电位器,进而控制AD采样的电压值,并显示在TFT屏上。屏的接口原理图如下:
屏的实物图背面如下图:
部分代码展示如下:
#include "main.h"
#include "LCD_calculate.h"
#include "Lcd_Driver.h"
void GPIO_Configuration(void);
void RCC_Configuration(void);
void Delay(__IO uint32_t nCount)
{
while (nCount != 0)
{
nCount--;
}
}
int main()
{
uint8_t gnum;
uint8_t snum;
RCC_Configuration();
GPIO_Configuration();
Lcd_Init();
Lcd_Clear(GRAY0);
Gui_DrawFont_GBK16(10,5,BLACK,GRAY0,"HELLO CW32F030");
Gui_DrawFont_GBK16(4,25,RED,GRAY0,"TIME:2023-06-03");
Gui_DrawFont_Num32(10,45,BLUE,GRAY1,1);
Gui_DrawFont_Num32(45,45,BLUE,GRAY1,2);
Gui_DrawFont_Num32(10,80,BLUE,GRAY1,3);
Gui_DrawFont_Num32(45,80,BLUE,GRAY1,4);
while(1)
{
gnum++;
if(gnum >9){gnum = 0;snum++;}
if(snum >5){snum = 0;}
Gui_DrawFont_Num32(63,120,BLUE,GRAY1,snum);
Gui_DrawFont_Num32(93,120,BLUE,GRAY1,gnum);
if(gnum % 2 == 0)Gui_DrawFont_Num32(80,45,BLUE,GRAY0,11);
else{Lcd_Clear_1(WHITE);}
Delay(0x3FFFFF);
}
}
void RCC_Configuration(void)
{
RCC_HSI_Enable(RCC_HSIOSC_DIV6);
RCC_HCLKPRS_Config(RCC_HCLK_DIV1);
RCC_PCLKPRS_Config(RCC_PCLK_DIV1);
RCC_PLL_Enable(RCC_PLLSOURCE_HSI, 8000000, 8);
__RCC_FLASH_CLK_ENABLE();
FLASH_SetLatency(FLASH_Latency_3);
RCC_SysClk_Switch(RCC_SYSCLKSRC_PLL);
RCC_SystemCoreClockUpdate(64000000);
}
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
__RCC_GPIOA_CLK_ENABLE();
GPIO_InitStruct.IT = GPIO_IT_NONE;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pins = GPIO_PIN_7;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_Init(CW_GPIOA, &GPIO_InitStruct);
PB00_SETLOW();
}
void Gui_DrawFont_GBK16(unsigned int x, unsigned int y, unsigned int fc, unsigned int bc, char *s)
{
unsigned char i,j;
unsigned short k,x0;
x0=x;
while(*s)
{
if((*s) < 128)
{
k=*s;
if (k==13)
{
x=x0;
y+=16;
}
else
{
if (k>32) k-=32; else k=0;
for(i=0;i<16;i++)
for(j=0;j<8;j++)
{
if(asc16[k*16+i]&(0x80>>j)) Gui_DrawPoint(x+j,y+i,fc);
else
{
if (fc!=bc) Gui_DrawPoint(x+j,y+i,bc);
}
}
x+=8;
}
s++;
}
else
{
for (k=0;k<hz16_num;k++)
{
if ((hz16[k].Index[0]==*(s))&&(hz16[k].Index[1]==*(s+1)))
{
for(i=0;i<16;i++)
{
for(j=0;j<8;j++)
{
if(hz16[k].Msk[i*2]&(0x80>>j)) Gui_DrawPoint(x+j,y+i,fc);
else {
if (fc!=bc) Gui_DrawPoint(x+j,y+i,bc);
}
}
for(j=0;j<8;j++)
{
if(hz16[k].Msk[i*2+1]&(0x80>>j)) Gui_DrawPoint(x+j+8,y+i,fc);
else
{
if (fc!=bc) Gui_DrawPoint(x+j+8,y+i,bc);
}
}
}
}
}
s+=2;x+=16;
}
}
}
void Gui_DrawFont_GBK24(unsigned int x, unsigned int y, unsigned int fc, unsigned int bc, unsigned char *s)
{
unsigned char i,j;
unsigned short k;
while(*s)
{
if( *s < 0x80 )
{
k=*s;
if (k>32) k-=32; else k=0;
for(i=0;i<16;i++)
for(j=0;j<8;j++)
{
if(asc16[k*16+i]&(0x80>>j))
Gui_DrawPoint(x+j,y+i,fc);
else
{
if (fc!=bc) Gui_DrawPoint(x+j,y+i,bc);
}
}
s++;x+=8;
}
else
{
for (k=0;k<hz24_num;k++)
{
if ((hz24[k].Index[0]==*(s))&&(hz24[k].Index[1]==*(s+1)))
{
for(i=0;i<24;i++)
{
for(j=0;j<8;j++)
{
if(hz24[k].Msk[i*3]&(0x80>>j))
Gui_DrawPoint(x+j,y+i,fc);
else
{
if (fc!=bc) Gui_DrawPoint(x+j,y+i,bc);
}
}
for(j=0;j<8;j++)
{
if(hz24[k].Msk[i*3+1]&(0x80>>j)) Gui_DrawPoint(x+j+8,y+i,fc);
else {
if (fc!=bc) Gui_DrawPoint(x+j+8,y+i,bc);
}
}
for(j=0;j<8;j++)
{
if(hz24[k].Msk[i*3+2]&(0x80>>j))
Gui_DrawPoint(x+j+16,y+i,fc);
else
{
if (fc!=bc) Gui_DrawPoint(x+j+16,y+i,bc);
}
}
}
}
}
s+=2;x+=24;
}
}
}
void Gui_DrawFont_Num32(unsigned int x, unsigned int y, unsigned int fc, unsigned int bc, unsigned int num)
{
unsigned char i,j,k,c;
for(i=0;i<32;i++)
{
for(j=0;j<4;j++)
{
c=*(sz32+num*32*4+i*4+j);
for (k=0;k<8;k++)
{
if(c&(0x80>>k)) Gui_DrawPoint(x+j*8+k,y+i,fc);
else {
if (fc!=bc) Gui_DrawPoint(x+j*8+k,y+i,bc);
}
}
}
}
}
编译完成后,下载到开发板后,TFT屏显示的图样如下:
当然啦,例程只是检测一下刷屏的效果,呈现的效果见底下视频。