/********************************************************
工作模式:8080
*********************************************************/
#include "R61505V.H"
/****************************************************************************
写8位命令
****************************************************************************/
void WriteComm(uchar i)
{
TFT_WR = 1; //初始化WR
TFT_CS = 0; //打开片选
TFT_RD = 1; //选择写
TFT_RS = 0; //选择发送命令
TFT_DATAPORT = i;
TFT_WR = 0; //写入时序
TFT_WR = 1;
TFT_CS = 1; //关闭片选
}
/****************************************************************************
写16位命令
****************************************************************************/
void TFT_WriteCmd(uint cmd)
{
uchar cmdH, cmdL;
cmdH = cmd >> 8;
cmdL = cmd & 0x00FF;
WriteComm(cmdH);
WriteComm(cmdL);
}
/****************************************************************************
写8位数据
****************************************************************************/
void WriteData(uchar dat)
{
TFT_WR = 1; //初始化WR
TFT_CS = 0; //打开片选
TFT_RD = 1; //选择写
TFT_RS = 1; //选择发送数据
TFT_DATAPORT = dat;
TFT_WR = 0; //写入时序
TFT_WR = 1;
TFT_CS = 1; //关闭片选
}
/****************************************************************************
写16位数据
****************************************************************************/
void TFT_WriteData(uint dat)
{
uchar datH, datL;
datH = dat >> 8;
datL = dat & 0xFF;
WriteData(datH);
WriteData(datL);
}
/****************************************************************************
*函数名:TFT_WriteCmdData
*输 入:cmd:命令
* :dat:数据
*输 出:
*功 能:写命令, 写数据。
****************************************************************************/
void TFT_WriteCmdData(uint cmd, uint dat)
{
WriteComm(cmd);
TFT_WriteData(dat);
}
void delay500(void)
{
uint i;
for(i=500; i>0; i--)
;
}
/****************************************************************************
*函数名:TFT_Init
*输 入:
*输 出:
*功 能:初始化TFT。
****************************************************************************/
void TFT_Init(void)
{
TFT_RST = 1;
delay500();
TFT_RST = 0;
delay500();
TFT_RST = 1;
delay500();
TFT_WriteCmdData(0x0007,0x0000);
delay500();
TFT_WriteCmdData(0x0012,0x011C);//0x011A why need to set several times?
TFT_WriteCmdData(0x00A4,0x0001);//NVM
TFT_WriteCmdData(0x0008,0x000F);
TFT_WriteCmdData(0x000A,0x0008);
TFT_WriteCmdData(0x000D,0x0008);
//伽马校正
TFT_WriteCmdData(0x0030,0x0707);
TFT_WriteCmdData(0x0031,0x0007); //0x0707
TFT_WriteCmdData(0x0032,0x0603);
TFT_WriteCmdData(0x0033,0x0700);
TFT_WriteCmdData(0x0034,0x0202);
TFT_WriteCmdData(0x0035,0x0002); //?0x0606
TFT_WriteCmdData(0x0036,0x1F0F);
TFT_WriteCmdData(0x0037,0x0707); //0x0f0f 0x0105
TFT_WriteCmdData(0x0038,0x0000);
TFT_WriteCmdData(0x0039,0x0000);
TFT_WriteCmdData(0x003A,0x0707);
TFT_WriteCmdData(0x003B,0x0000); //0x0303
TFT_WriteCmdData(0x003C,0x0007); //?0x0707
TFT_WriteCmdData(0x003D,0x0000); //0x1313//0x1f08
delay500();
TFT_WriteCmdData(0x0007,0x0001);
TFT_WriteCmdData(0x0017,0x0001);//开启电源
delay500();
//电源配置
TFT_WriteCmdData(0x0010,0x17A0);
TFT_WriteCmdData(0x0011,0x0217);//reference voltage VC[2:0] Vciout = 1.00*Vcivl
TFT_WriteCmdData(0x0012,0x011E);//0x011c //Vreg1out = Vcilvl*1.80 is it the same as Vgama1out ?
TFT_WriteCmdData(0x0013,0x0F00);//VDV[4:0]-->VCOM Amplitude VcomL = VcomH - Vcom Ampl
TFT_WriteCmdData(0x002A,0x0000);
TFT_WriteCmdData(0x0029,0x000A);//0x0001F Vcomh = VCM1[4:0]*Vreg1out gate source voltage??
TFT_WriteCmdData(0x0012,0x013E);// 0x013C power supply on
//Coordinates Control//
TFT_WriteCmdData(0x0050,0x0000);//0x0e00
TFT_WriteCmdData(0x0051,0x00EF);
TFT_WriteCmdData(0x0052,0x0000);
TFT_WriteCmdData(0x0053,0x013F);
//Pannel Image Control//
TFT_WriteCmdData(0x0060,0x2700);
TFT_WriteCmdData(0x0061,0x0001);
TFT_WriteCmdData(0x006A,0x0000);
TFT_WriteCmdData(0x0080,0x0000);
//Partial Image Control//
TFT_WriteCmdData(0x0081,0x0000);
TFT_WriteCmdData(0x0082,0x0000);
TFT_WriteCmdData(0x0083,0x0000);
TFT_WriteCmdData(0x0084,0x0000);
TFT_WriteCmdData(0x0085,0x0000);
//Panel Interface Control//
TFT_WriteCmdData(0x0090,0x0013);//0x0010 frenqucy
TFT_WriteCmdData(0x0092,0x0300);
TFT_WriteCmdData(0x0093,0x0005);
TFT_WriteCmdData(0x0095,0x0000);
TFT_WriteCmdData(0x0097,0x0000);
TFT_WriteCmdData(0x0098,0x0000);
TFT_WriteCmdData(0x0001,0x0100);
TFT_WriteCmdData(0x0002,0x0700);
TFT_WriteCmdData(0x0003,0x1038);//扫描方向 上->下 左->右
TFT_WriteCmdData(0x0004,0x0000);
TFT_WriteCmdData(0x000C,0x0000);
TFT_WriteCmdData(0x000F,0x0000);
TFT_WriteCmdData(0x0020,0x0000);
TFT_WriteCmdData(0x0021,0x0000);
TFT_WriteCmdData(0x0007,0x0021);
delay500();
TFT_WriteCmdData(0x0007,0x0061);
delay500();
TFT_WriteCmdData(0x0007,0x0173);
delay500();
// LCD_Display_Dir(0); //默认为竖屏
// LCD_LED=1; //点亮背光
// LCD_Clear(WHITE);
}
/****************************************************************************
*函数名:TFT_SetWindow
*输 入:xStart:起始X坐标
* :yStart:起始Y坐标
* :xEnd:结束X坐标
* :yEnd:结束Y坐标
*输 出:
*功 能:设置要操作的窗口。
****************************************************************************/
void TFT_SetWindow(uint xStart, uint yStart, uint xEnd, uint yEnd)
{
WriteComm(0x2A);//P94 set_column_address: 2Ah
TFT_WriteData(xStart);
TFT_WriteData(xEnd);
// WriteData(xStart>>8);
// WriteData(xStart&0xff);
// WriteData(xEnd>>8);
// WriteData(xEnd&0xff);
WriteComm(0x2b);//P96 set_page_address: 2Bh
TFT_WriteData(yStart);
TFT_WriteData(yEnd);
// WriteData(yStart>>8);
// WriteData(yStart&0xff);
// WriteData(yEnd>>8);
// WriteData(yEnd&0xff);
TFT_WriteCmd(0x2c); //P98 write_memory_start: 2Ch
}
/****************************************************************************
*函数名:TFT_WriteColorData
*输 入:16位颜色数据
*输 出:
*功 能:同写入16位数据一样
****************************************************************************/
void TFT_WriteColorData(uint color)
{
TFT_CS = 0;
TFT_RS = 1;
TFT_RD = 1;
TFT_DATAPORT = color >>8;//写高八位
TFT_WR = 0; //写入时序
TFT_WR = 1;
TFT_DATAPORT = color;
TFT_WR = 0; //写入时序
TFT_WR = 1;
TFT_CS = 1;
}
/****************************************************************************
*函数名:GUI_Clearcreen
*输 入:backColor:清屏颜色
*输 出:
*功 能:清屏并涂上颜色。
****************************************************************************/
void TFT_ClearScreen(uint color)
{
uint i, j;
TFT_SetWindow(0, 0, TFT_XMAX, TFT_YMAX); //作用区域
for(i=0; i < TFT_YMAX+1 ; i++)
{
for (j=0; j < TFT_XMAX+1; j++) //逐点写入
{
TFT_WriteColorData(color);
}
}
}
|