#include "myinclude.h"
#include "tft.h"
void LCD_HardWareInit() //硬件配置
{
SysCtlPeriEnable(TFTL_PERIPH);
GPIOPinTypeOut(TFTL_PORT,TFTL_PINS);
SysCtlPeriEnable(TFTH_PERIPH);
GPIOPinTypeOut(TFTH_PORT,TFTH_PINS);
SysCtlPeriEnable(TFTCTRL_PERIPH);
GPIOPinTypeOut(TFTCTRL_PORT,( TFTCS | TFTWR | TFTRS | TFTRST ) );
GPIOPinTypeIn(TFTCTRL_PORT,TFTRD );
GPIOPinWrite(TFTCTRL_PORT, TFTRST, 0X00);//复位液晶屏
DelayMs(100);
GPIOPinWrite(TFTCTRL_PORT, TFTRST, 0Xff);
DelayMs(100);
}
void LCD_WriteCmd(INT16U cmd)
{
GPIOPinWrite(TFTCTRL_PORT, TFTRS, 0X00);//RS为低表示命令
GPIOPinWrite(TFTCTRL_PORT, TFTCS, 0X00);//CS为低表示片选
GPIOPinWrite(TFTH_PORT, TFTH_PINS, (cmd >> 8) );//先送高字节
GPIOPinWrite(TFTL_PORT, TFTL_PINS, (cmd & 0X00FF) );//后送低字节
GPIOPinWrite(TFTCTRL_PORT, TFTWR, 0X00);//WR为低表示写操作
// DelayMs(1);
GPIOPinWrite(TFTCTRL_PORT, TFTWR, 0XFF);//WR为1
GPIOPinWrite(TFTCTRL_PORT, TFTCS, 0XFF);//CS为1
}
void LCD_WriteDat(INT16U dat)
{
GPIOPinWrite(TFTCTRL_PORT, TFTRS, 0Xff);//RS为高电平表示数据
GPIOPinWrite(TFTCTRL_PORT, TFTCS, 0X00);//CS为低表示片选
GPIOPinWrite(TFTH_PORT, TFTH_PINS, (dat >> 8) );//先送高字节
GPIOPinWrite(TFTL_PORT, TFTL_PINS, (dat & 0X00FF) );//后送低字节
GPIOPinWrite(TFTCTRL_PORT, TFTWR, 0X00);//WR为低表示写操作
// DelayMs(1);
GPIOPinWrite(TFTCTRL_PORT, TFTWR, 0XFF);//WR为1
GPIOPinWrite(TFTCTRL_PORT, TFTCS, 0XFF);//CS为1
}
//========================================================================
//液晶屏显示窗口设置,默认全屏设置
//========================================================================
void LCD_BlockSet(INT16U startx, INT16U starty, INT16U endx, INT16U endy)
{
LCD_WriteCmd(0x0002); LCD_WriteDat(startx >> 8); //column address start register
LCD_WriteCmd(0x0003); LCD_WriteDat(startx);
LCD_WriteCmd(0x0004); LCD_WriteDat(endx >> 8);
LCD_WriteCmd(0x0005); LCD_WriteDat(endx);
LCD_WriteCmd(0x0006); LCD_WriteDat(starty >> 8);
LCD_WriteCmd(0x0007); LCD_WriteDat(starty);
LCD_WriteCmd(0x0008); LCD_WriteDat(endy >> 8);
LCD_WriteCmd(0x0009); LCD_WriteDat(endy);
/* LCD_WriteCmd(0x0050); LCD_WriteDat(startx);
LCD_WriteCmd(0x0051); LCD_WriteDat(endx);
LCD_WriteCmd(0x0052); LCD_WriteDat(starty);
LCD_WriteCmd(0x0053); LCD_WriteDat(endy); */
LCD_WriteCmd(0x0020); LCD_WriteDat(startx);
LCD_WriteCmd(0x0021); LCD_WriteDat(starty);
LCD_WriteCmd(0x0022);
}
//========================================================================
//全屏填充函数(满屏显示一个颜色)
//========================================================================
void LCD_FillSCR(INT16U color)
{
INT16U i,j;
LCD_BlockSet(0, 0, LCD_PIXEL_XSIZE-1, LCD_PIXEL_YSIZE-1);
for(i=0; i<LCD_PIXEL_YSIZE; i++)
{
for(j=0; j<LCD_PIXEL_XSIZE; j++)
{
LCD_SendDat(color);
}
}
}
//========================================================================
//全屏显示8色条纹
//========================================================================
void LCD_DispBar(void)
{
INT16U i ,j;
LCD_BlockSet(0, 0, LCD_PIXEL_XSIZE-1, LCD_PIXEL_YSIZE-1); //设置全屏
for (i=0; i<LCD_PIXEL_YSIZE/8; i++)
{
for(j=0; j<LCD_PIXEL_XSIZE; j++)
{
LCD_SendDat(WHITE);
}
}
for(i=0; i<LCD_PIXEL_YSIZE/8; i++)
{
for(j=0; j<LCD_PIXEL_XSIZE; j++)
{
LCD_SendDat(BLACK);
}
}
for(i=0;i<LCD_PIXEL_YSIZE/8;i++)
{
for(j=0;j<LCD_PIXEL_XSIZE;j++)
{
LCD_SendDat(R);
}
}
for(i=0; i<LCD_PIXEL_YSIZE/8;i++)
{
for(j = 0;j<LCD_PIXEL_XSIZE;j++)
{
LCD_SendDat(G);
}
}
for(i = 0; i<LCD_PIXEL_YSIZE/8;i++)
{
for(j=0;j<LCD_PIXEL_XSIZE;j++)
{
LCD_SendDat(B);
}
}
for(i=0; i<LCD_PIXEL_YSIZE/8;i++)
{
for(j=0;j<LCD_PIXEL_XSIZE;j++)
{
LCD_SendDat(CYAN);
}
}
for(i=0; i<LCD_PIXEL_YSIZE/8;i++)
{
for(j=0;j<LCD_PIXEL_XSIZE;j++)
{
LCD_SendDat(MAGENTA);
}
}
for(i=0; i<(LCD_PIXEL_YSIZE-((INT8U)(LCD_PIXEL_YSIZE/8))*7);i++)
{
for(j=0;j<LCD_PIXEL_XSIZE;j++)
{
LCD_SendDat(YELLOW);
}
}
}
//========================================================================
//局部填充颜色
//起始位置(x0,y0),宽度width,高度high,颜色color,未进行参数过虑
//========================================================================
void LCD_RectangleFill(INT16U x0, INT16U y0, INT16U width, INT16U high, INT16U color)
{
INT16U i,j;
LCD_BlockSet(x0, y0, x0+width-1, y0+high-1);
for(i=0; i<width; i++)
{
for(j=0; j<high; j++)
{
LCD_SendDat(color);
}
}
}
void LCD_Init(void)
{
LCD_HardWareInit(); //硬件配置
//执行初始化代码,根据具体驱动芯片作修改
//?′DD3?ê??ˉ′ú??£??ù?Y??ì??y?ˉD???×÷DT??
LCD_WriteCmd(0x0046);LCD_WriteDat(0x00A4);
LCD_WriteCmd(0x0047);LCD_WriteDat(0x0053);
LCD_WriteCmd(0x0048);LCD_WriteDat(0x0000);
LCD_WriteCmd(0x0049);LCD_WriteDat(0x0044);
LCD_WriteCmd(0x004A);LCD_WriteDat(0x0004);
LCD_WriteCmd(0x004B);LCD_WriteDat(0x0067);
LCD_WriteCmd(0x004C);LCD_WriteDat(0x0033);
LCD_WriteCmd(0x004D);LCD_WriteDat(0x0077);
LCD_WriteCmd(0x004E);LCD_WriteDat(0x0012);
LCD_WriteCmd(0x004F);LCD_WriteDat(0x004C);
LCD_WriteCmd(0x0050);LCD_WriteDat(0x0046);
LCD_WriteCmd(0x0051);LCD_WriteDat(0x0044);
//240x320 window setting
LCD_WriteCmd(0x0002);LCD_WriteDat(0x0000); // Column address start2
LCD_WriteCmd(0x0003);LCD_WriteDat(0x0000); // Column address start1
LCD_WriteCmd(0x0004);LCD_WriteDat(0x0000); // Column address end2
LCD_WriteCmd(0x0005);LCD_WriteDat(0x00EF); // Column address end1
LCD_WriteCmd(0x0006);LCD_WriteDat(0x0000); // Row address start2
LCD_WriteCmd(0x0007);LCD_WriteDat(0x0000); // Row address start1
LCD_WriteCmd(0x0008);LCD_WriteDat(0x0001); // Row address end2
LCD_WriteCmd(0x0009);LCD_WriteDat(0x003F); // Row address end1
// Display Setting
LCD_WriteCmd(0x0001);LCD_WriteDat(0x0006); // IDMON=0, INVON=1, NORON=1, PTLON=0
LCD_WriteCmd(0x0016);LCD_WriteDat(0x00C8); // MY=0, MX=0, MV=0, ML=1, BGR=0, TEON=0
LCD_WriteCmd(0x0023);LCD_WriteDat(0x0095); // N_DC=1001 0101
LCD_WriteCmd(0x0024);LCD_WriteDat(0x0095); // PI_DC=1001 0101
LCD_WriteCmd(0x0025);LCD_WriteDat(0x00FF); // I_DC=1111 1111
LCD_WriteCmd(0x0027);LCD_WriteDat(0x0002); // N_BP=0000 0010
LCD_WriteCmd(0x0028);LCD_WriteDat(0x0002); // N_FP=0000 0010
LCD_WriteCmd(0x0029);LCD_WriteDat(0x0002); // PI_BP=0000 0010
LCD_WriteCmd(0x002A);LCD_WriteDat(0x0002); // PI_FP=0000 0010
LCD_WriteCmd(0x002C);LCD_WriteDat(0x0002); // I_BP=0000 0010
LCD_WriteCmd(0x002D);LCD_WriteDat(0x0002); // I_FP=0000 0010
LCD_WriteCmd(0x003A);LCD_WriteDat(0x0001); // N_RTN=0000, N_NW=001
LCD_WriteCmd(0x003B);LCD_WriteDat(0x0001); // PI_RTN=0000, PI_NW=001
LCD_WriteCmd(0x003C);LCD_WriteDat(0x00F0); // I_RTN=1111, I_NW=000
LCD_WriteCmd(0x003D);LCD_WriteDat(0x0000); // DIV=00
DelayMs(20);
LCD_WriteCmd(0x0035);LCD_WriteDat(0x0038); // EQS=38h
LCD_WriteCmd(0x0036);LCD_WriteDat(0x0078); // EQP=78h
LCD_WriteCmd(0x003E);LCD_WriteDat(0x0038); // SON=38h
LCD_WriteCmd(0x0040);LCD_WriteDat(0x000F); // GDON=0Fh
LCD_WriteCmd(0x0041);LCD_WriteDat(0x00F0); // GDOFF
// Power Supply Setting
LCD_WriteCmd(0x0019);LCD_WriteDat(0x0049); // CADJ=0100, CUADJ=100(FR:60Hz),, OSD_EN=1
LCD_WriteCmd(0x0093);LCD_WriteDat(0x000F); // RADJ=1111, 100%
DelayMs(10);
LCD_WriteCmd(0x0020);LCD_WriteDat(0x0040); // BT=0100
LCD_WriteCmd(0x001D);LCD_WriteDat(0x0007); // VC1=111
LCD_WriteCmd(0x001E);LCD_WriteDat(0x0000); // VC3=000
LCD_WriteCmd(0x001F);LCD_WriteDat(0x0004); // VRH=0100
// VCOM Setting for CMO 3.2?± Panel
LCD_WriteCmd(0x0044);LCD_WriteDat(0x004D); // VCM=100 1101
LCD_WriteCmd(0x0045);LCD_WriteDat(0x0011); // VDV=1 0001
DelayMs(10);
LCD_WriteCmd(0x001C);LCD_WriteDat(0x0004); // AP=100
DelayMs(20);
LCD_WriteCmd(0x0043);LCD_WriteDat(0x0080); //set VCOMG=1