Start_DSC28034PNT湖人开发板上配有TFT彩屏接口,见图1所示。
图1 所用接口
所用该接口可为它配置一个2.2寸的TFT显示屏来完成显示任务,其显示分辨率为240*320像素点,该显示屏是以SPI方式进行工作,其接口如图2所示。
图2 显示屏接口
该显示屏与开发板的引脚连接关系为:
CS ---GPIO10
RST--- GPIO9
DC --- GPIO8
SDA--- GPIO16
SCL--- GPIO18
BL --- GPIO7
显示屏所用引脚的配置函数为:
void Init_TFT(void)
{
EALLOW;
GpioCtrlRegs.GPAMUX1.bit.GPIO8 = 0;
GpioCtrlRegs.GPADIR.bit.GPIO8 = 1;
GpioCtrlRegs.GPAMUX1.bit.GPIO9 = 0;
GpioCtrlRegs.GPADIR.bit.GPIO9 = 1;
GpioCtrlRegs.GPAMUX1.bit.GPIO10 = 0;
GpioCtrlRegs.GPADIR.bit.GPIO10 = 1;
GpioCtrlRegs.GPAMUX1.bit.GPIO7 = 0;
GpioCtrlRegs.GPADIR.bit.GPIO7= 1;
GpioCtrlRegs.GPAMUX2.bit.GPIO18 = 0;
GpioCtrlRegs.GPADIR.bit.GPIO18 = 1;
GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 0;
GpioCtrlRegs.GPADIR.bit.GPIO16 = 1;
EDIS;
}
所用引脚输出高低电平的语句定义为:
//CLK
#define
LCD_SCK_High()
GpioDataRegs.GPASET.bit.GPIO18= 1
#define
LCD_SCK_Low()
GpioDataRegs.GPACLEAR.bit.GPIO18 = 1
//DIN
#define
LCD_SDI_High()
GpioDataRegs.GPASET.bit.GPIO16= 1
#define
LCD_SDI_Low() GpioDataRegs.GPACLEAR.bit.GPIO16
= 1
//RES
#define
LCD_REST_High()
GpioDataRegs.GPASET.bit.GPIO9= 1
#define
LCD_REST_Low()
GpioDataRegs.GPACLEAR.bit.GPIO9 = 1
//DC
#define
LCD_DC_High()
GpioDataRegs.GPASET.bit.GPIO8= 1
#define
LCD_DC_Low() GpioDataRegs.GPACLEAR.bit.GPIO8
= 1
//CS
#define
LCD_CS_High()
GpioDataRegs.GPASET.bit.GPIO10= 1
#define
LCD_CS_Low()
GpioDataRegs.GPACLEAR.bit.GPIO10 = 1
//BLK
#define
LCD_LED_High()
GpioDataRegs.GPASET.bit.GPIO7= 1
#define
LCD_LED_Low() GpioDataRegs.GPACLEAR.bit.GPIO7
= 1
在GPIO口模拟SPI通讯的方式下,其发送字节数据的函数为:
void LCD_Writ_Bus(unsigned char com)
{
unsigned char i;
for(i=0; i<8; i++)
{
if(com & 0x80)
{
LCD_SDI_High();
}
else
{
LCD_SDI_Low();
}
com = com << 1;
delay_1us(2);
LCD_SCK_Low();
delay_1us(2);
LCD_SCK_High();
delay_1us(2);
}
}
实现指定色彩清屏的功能函数为:
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);
}
}
}
实现字符显示的函数为:
void LCD_ShowChar(unsigned int x,unsigned int y,char num,char mode)
{
char temp;
char pos,t;
unsigned int x0=x;
unsigned int colortemp=POINT_COLOR;
if(x>LCD_W-16||y>LCD_H-16)return;
num=num-' ';
Address_set(x,y,x+8-1,y+16-1);
if(!mode)
{
for(pos=0;pos<16;pos++)
{
temp=asc2_1608[(unsigned int)num*16+pos];
for(t=0;t<8;t++)
{
if(temp&0x01)POINT_COLOR=colortemp;
else POINT_COLOR=BACK_COLOR;
LCD_WR_DATA(POINT_COLOR);
temp>>=1;
x++;
}
x=x0;
y++;
}
} else
{
for(pos=0;pos<16;pos++)
{
temp=asc2_1608[(unsigned int)num*16+pos];
for(t=0;t<8;t++)
{
if(temp&0x01)LCD_DrawPoint(x+t,y+pos);
temp>>=1;
}
}
}
POINT_COLOR=colortemp;
}
实现字符串显示的函数为:
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++;
}
}
用于显示图标的显示函数为:
void show_tb(unsigned int x,unsigned int y,unsigned int n)
{
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++;
}
}
}
实现显示测试的主程序为:
int main(void)
{
InitSysCtrl();
Init_TFT();
tft_Init();
BACK_COLOR=YELLOW;
POINT_COLOR=RED;
LCD_Clear(YELLOW);
LCD_ShowString(80,30,"DSC28034 TEST");
show_tb(60,20,0);
while(1);
return 0;
}
经程序的编译与下载,其显示效果如图2所示。
图3 显示效果