void TFT_Init(void)
{
u16 DeviceCode;
Set_RST;
Delayms(5);
Clr_RST;
Delayms(5);
Set_RST;
Set_CS;
Set_RD;
Set_WR;
Delayms(5);
DeviceCode = TFT_ReadReg(0x0000); // 讀ID,以確認(rèn)驅(qū)動IC為ILI9325
send_data(DeviceCode>>8);
send_data(DeviceCode&0xFF);
Delayms(50);
Clr_CS;// 打開片選使能
//
TFT_Write_com(0x00E5); TFT_Write_dat(0x78F0);// set SRAM internal timing 雖然手冊上沒有介紹這個時鐘的設(shè)置,但實際上這個并不很重要,即使不加上去,也可以把屏驅(qū)起來,只是圖像是否會清晰就有待驗證了
//TFT_Write_com(0x00E3); TFT_Write_dat(0x3008);// set SRAM internal timing
//TFT_Write_com(0x00E7); TFT_Write_dat(0x0012);// set SRAM internal timing
//TFT_Write_com(0x00EF); TFT_Write_dat(0x1231);// set SRAM internal timing
//TFT_Write_com(0x0000); TFT_Write_dat(0x0001);// start OcillationILI9325不需要這一句
TFT_Write_com(0x0001); TFT_Write_dat(0x0100);// set SS and SM bit (S720 -> S1)
TFT_Write_com(0x0002); TFT_Write_dat(0x0700);// set 1 line inversion
TFT_Write_com(0x0003); TFT_Write_dat(0x1030);// set GRAM write direction and BGR=1.、、65K
TFT_Write_com(0x0004); TFT_Write_dat(0x0000);// Resize register
TFT_Write_com(0x0008); TFT_Write_dat(0x0207);// set the back porch and front porch
TFT_Write_com(0x0009); TFT_Write_dat(0x0000);// set non-display area refresh cycle ISC[3:0]
TFT_Write_com(0x000A); TFT_Write_dat(0x0000);// FMARK function
TFT_Write_com(0x000C); TFT_Write_dat(0x0000);// RGB interface setting
TFT_Write_com(0x000D); TFT_Write_dat(0x0000);// Frame marker Position
TFT_Write_com(0x000F); TFT_Write_dat(0x0000);// RGB interface polarity
//
TFT_Write_com(0x0010); TFT_Write_dat(0x0000);// SAP, BT[3:0], AP, DSTB, SLP, STB
TFT_Write_com(0x0011); TFT_Write_dat(0x0007);// DC1[2:0], DC0[2:0], VC[2:0]
TFT_Write_com(0x0012); TFT_Write_dat(0x0000);// VREG1OUT voltage
TFT_Write_com(0x0013); TFT_Write_dat(0x0000);// VDV[4:0] for VCOM amplitude
TFT_Write_com(0x0007); TFT_Write_dat(0x0001);
Delayms(50); // Dis-charge capacitor power voltage
TFT_Write_com(0x0010); TFT_Write_dat(0x1090);// SAP, BT[3:0], AP, DSTB, SLP, STB
TFT_Write_com(0x0011); TFT_Write_dat(0x0227);// DC1[2:0], DC0[2:0], VC[2:0]
Delayms(50);
TFT_Write_com(0x0012); TFT_Write_dat(0x001F);//001C// Internal reference voltage= Vci;
Delayms(50);
TFT_Write_com(0x0013); TFT_Write_dat(0x1500);//Set VDV[4:0] for VCOM amplitude
TFT_Write_com(0x0029); TFT_Write_dat(0x0027);//Set VCM[5:0] for VCOMH 電壓
TFT_Write_com(0x002B); TFT_Write_dat(0x000D);// Set Frame Rate 000C 幀頻
Delayms(50);
TFT_Write_com(0x0020); TFT_Write_dat(0x0000);// GRAM horizontal Address
TFT_Write_com(0x0021); TFT_Write_dat(0x0000);// GRAM Vertical Address
// ----------- Adjust the Gamma Curve ----------//
TFT_Write_com(0x0030); TFT_Write_dat(0x0000);
TFT_Write_com(0x0031); TFT_Write_dat(0x0707);
TFT_Write_com(0x0032); TFT_Write_dat(0x0307);
TFT_Write_com(0x0035); TFT_Write_dat(0x0200);
TFT_Write_com(0x0036); TFT_Write_dat(0x0008);
TFT_Write_com(0x0037); TFT_Write_dat(0x0004);
TFT_Write_com(0x0038); TFT_Write_dat(0x0000);
TFT_Write_com(0x0039); TFT_Write_dat(0x0707);
TFT_Write_com(0x003C); TFT_Write_dat(0x0002);
TFT_Write_com(0x003D); TFT_Write_dat(0x1D04);
//------------------ Set GRAM area ---------------//
TFT_Write_com(0x0050); TFT_Write_dat(0x0000);// Horizontal GRAM Start Address
TFT_Write_com(0x0051); TFT_Write_dat(0x00EF);// Horizontal GRAM End Address
TFT_Write_com(0x0052); TFT_Write_dat(0x0000);// Vertical GRAM Start Address
TFT_Write_com(0x0053); TFT_Write_dat(0x013F);// Vertical GRAM Start Address
TFT_Write_com(0x0060); TFT_Write_dat(0xA700);// Gate Scan Line
TFT_Write_com(0x0061); TFT_Write_dat(0x0001);// NDL,VLE, REV
TFT_Write_com(0x006A); TFT_Write_dat(0x0000);// set scrolling line
//-------------- Partial Display Control ---------//
TFT_Write_com(0x0080); TFT_Write_dat(0x0000);
TFT_Write_com(0x0081); TFT_Write_dat(0x0000);
TFT_Write_com(0x0082); TFT_Write_dat(0x0000);
TFT_Write_com(0x0083); TFT_Write_dat(0x0000);
TFT_Write_com(0x0084); TFT_Write_dat(0x0000);
TFT_Write_com(0x0085); TFT_Write_dat(0x0000);
//-------------- Panel Control -------------------//
TFT_Write_com(0x0090); TFT_Write_dat(0x0010);
TFT_Write_com(0x0092); TFT_Write_dat(0x0600);
TFT_Write_com(0x0007); TFT_Write_dat(0x0133);// 262K color and display ON 開顯示
Set_CS;//關(guān)閉片選使能
}本文引用地址:http://m.butianyuan.cn/article/201611/320970.htm
void TFT_SetAddr(u16 x1, u16 y1, u16 x2, u16 y2)
{
TFT_Write_com(0x0020);TFT_Write_dat(x1);//設(shè)置X坐標(biāo)位置
TFT_Write_com(0x0021);TFT_Write_dat(y1); //設(shè)置Y坐標(biāo)位置
TFT_Write_com(0x0050);TFT_Write_dat(x1);//開始X
TFT_Write_com(0x0051);TFT_Write_dat(x2);//結(jié)束X
TFT_Write_com(0x0052);TFT_Write_dat(y1);//開始Y
TFT_Write_com(0x0053);TFT_Write_dat(y2);//結(jié)束Y
TFT_Write_com(0x0022);
}
void TFT_Pant(u16 Color)
{
u32 i, j;
Clr_CS;
TFT_SetAddr(0,0,240,320);
for(i=0; i<320; i++)
{
for (j=0; j<240; j++)
TFT_Write_dat(Color);
}
Set_CS;
}
評論