这个2.8"TFT显示屏支持2种界面的接口: 18Bit RGB接口和4线SPI接口。
采用SPI接口的时候,仅仅最少需要4个I/O即可!任何MCU都可以点亮它!
TFT28图纸.pdf
(148.88 KB)
实拍图.rar
(201.35 KB)
以下是测试程序:
//============================================ 程序功能: 点亮 2.8" TFT 显示屏
//----- TFT 控制器: HX8347-G (最新IC版本)
//----- 硬件连接方式:4根数据线+电源线(+3.3V,GND)
//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------
#include <c8051f340.h> // SFR declarations
#include <intrins.h> //--- _nop_() Used
//===============================
sbit nRES = P3^0; //--- 复位信号
sbit nCS = P3^1; //--- 片选信号
sbit SCK = P3^2; //--- 时钟信号
sbit SDO = P3^3; //--- 输出信号
sbit SDI = P3^4; //--- 输入信号(可不用)
#define START_BYTE 0x70
#define SET_INDEX 0x00
#define READ_STATUS 0x01
#define WRITE_REG 0x02
#define READ_REG 0x03
/*******************************************************************************/
#define CLR_SPI_CLK do { SCK = 0; ndelay();}while(0)
#define SET_SPI_CLK do { SCK = 1; ndelay();}while(0)
#define CLR_SPI_MOSI do { SDO = 0; ndelay();}while(0)
#define SET_SPI_MOSI do { SDO = 1; ndelay();}while(0)
/*******************************************************************************/
#define SPI_Enable do { SCK = 1; ndelay(); nCS = 0; ndelay();}while(0);
#define SPI_Disable do { SCK = 1; ndelay(); nCS = 1; ndelay();}while(0);
/************************************* 延时子程序 *********************/
void ndelay(void);
void mdelay(unsigned int msec);
/************************************* TFT驱动子程序 *******************/
void SPISend(unsigned char spi_bValue);
void SPISend16(unsigned int spi_bValue);
void WriteCOM(unsigned char mNULL,unsigned char cmd);
void WriteDAT(unsigned char mNULL,unsigned char dat);
void Show_RGB(void);
/-----------------------------------------------------------------------------
// main() Routine
//-----------------------------------------------------------------------------
void main (void)
{
//........
Init_LCD(); //--- 初始化LCD
Show_RGB(); //---显示RGB三色带
while(1);
}
void Show_RGB(void)
{
unsigned int k;
WriteCOM(0x00,0x22); //Start GRAM write
SPI_Enable
SPISend(START_BYTE | WRITE_REG);
//============================= Red
for(k=0;k<19200;k++)
{
SPISend16(0xF800);
}
//============================= Green
for(k=0;k<19200;k++)
{
SPISend16(0x001F);
}
//============================= Blue
for(k=0;k<19200;k++)
{
SPISend16(0x0FE0);
}
//============================= White
for(k=0;k<19200;k++)
{
SPISend16(0xFFFF);
}
SPI_Disable
}
//----------------------- 初始化2.8" TFT 显示屏
void Init_LCD(void)
{
nRES = 0;
mdelay(250); //--- Delay 250ms
nRES = 1;
mdelay(250); //--- Delay 250ms
//=============================
//Driving ability Setting
WriteCOM(0x00,0xEA);WriteDAT(0x00,0x00); //PTBA[15:8]
WriteCOM(0x00,0xEB);WriteDAT(0x00,0x20); //PTBA[7:0]
WriteCOM(0x00,0xEC);WriteDAT(0x00,0x3C); //STBA[15:8]
WriteCOM(0x00,0xED);WriteDAT(0x00,0xC4); //STBA[7:0]
WriteCOM(0x00,0xE8);WriteDAT(0x00,0x48); //OPON[7:0]
WriteCOM(0x00,0xE9);WriteDAT(0x00,0x38); //OPON1[7:0]
WriteCOM(0x00,0xF1);WriteDAT(0x00,0x01); //OTPS1B
WriteCOM(0x00,0xF2);WriteDAT(0x00,0x08); //GEN
//Gamma 2.2 Setting
WriteCOM(0x00,0x40);WriteDAT(0x00,0x01); //
WriteCOM(0x00,0x41);WriteDAT(0x00,0x07); //
WriteCOM(0x00,0x42);WriteDAT(0x00,0x09); //
WriteCOM(0x00,0x43);WriteDAT(0x00,0x19); //
WriteCOM(0x00,0x44);WriteDAT(0x00,0x14); //
WriteCOM(0x00,0x45);WriteDAT(0x00,0x0B); //
WriteCOM(0x00,0x46);WriteDAT(0x00,0x18); //
WriteCOM(0x00,0x47);WriteDAT(0x00,0x61); //
WriteCOM(0x00,0x48);WriteDAT(0x00,0x00); //
WriteCOM(0x00,0x49);WriteDAT(0x00,0x10); //
WriteCOM(0x00,0x4A);WriteDAT(0x00,0x15); //
WriteCOM(0x00,0x4B);WriteDAT(0x00,0x15); //
WriteCOM(0x00,0x4C);WriteDAT(0x00,0x10); //
WriteCOM(0x00,0x50);WriteDAT(0x00,0x19); //
WriteCOM(0x00,0x51);WriteDAT(0x00,0x24); //
WriteCOM(0x00,0x52);WriteDAT(0x00,0x21); //
WriteCOM(0x00,0x53);WriteDAT(0x00,0x29); //
WriteCOM(0x00,0x54);WriteDAT(0x00,0x38); //
WriteCOM(0x00,0x55);WriteDAT(0x00,0x3E); //
WriteCOM(0x00,0x56);WriteDAT(0x00,0x10); //
WriteCOM(0x00,0x57);WriteDAT(0x00,0x5A); //
WriteCOM(0x00,0x58);WriteDAT(0x00,0x09); //
WriteCOM(0x00,0x59);WriteDAT(0x00,0x04); //
WriteCOM(0x00,0x5A);WriteDAT(0x00,0x02); //
WriteCOM(0x00,0x5B);WriteDAT(0x00,0x04); //
WriteCOM(0x00,0x5C);WriteDAT(0x00,0x1D); //
WriteCOM(0x00,0x5D);WriteDAT(0x00,0xCC); //
WriteCOM(0x00,0x1B);WriteDAT(0x00,0x16); //VRH=4.65V
WriteCOM(0x00,0x1A);WriteDAT(0x00,0x01); //BT (VGH~15V);WriteDAT(0x00,VGL~-10V);WriteDAT(0x00,DDVDH~5V)
WriteCOM(0x00,0x23);WriteDAT(0x00,0x70); //VMH(VCOM High voltage ~4.2V)
WriteCOM(0x00,0x24);WriteDAT(0x00,0x93); //VML(VCOM Low voltage -1.2V)
//****VCOM offset**///
WriteCOM(0x00,0x23);WriteDAT(0x00,0x59); //for Flicker adjust //can reload from OTP
//Power on Setting
WriteCOM(0x00,0x18);WriteDAT(0x00,0x3A); //I/P_RADJ);WriteDAT(0x00,N/P_RADJ);WriteDAT(0x00, Normal mode 90Hz
WriteCOM(0x00,0x19);WriteDAT(0x00,0x01); //OSC_EN='1');WriteDAT(0x00, start Osc
WriteCOM(0x00,0x01);WriteDAT(0x00,0x00); //DP_STB='0');WriteDAT(0x00, out deep sleep
WriteCOM(0x00,0x1F);WriteDAT(0x00,0x8A);// GAS=1);WriteDAT(0x00, VOMG=00);WriteDAT(0x00, PON=0);WriteDAT(0x00, DK=1);WriteDAT(0x00, XDK=0);WriteDAT(0x00, DVDH_TRI=1);WriteDAT(0x00, STB=0
mdelay(100);
WriteCOM(0x00,0x1F);WriteDAT(0x00,0x82);// GAS=1);WriteDAT(0x00, VOMG=00);WriteDAT(0x00, PON=0);WriteDAT(0x00, DK=0);WriteDAT(0x00, XDK=0);WriteDAT(0x00, DVDH_TRI=1);WriteDAT(0x00, STB=0
mdelay(100);
WriteCOM(0x00,0x1F);WriteDAT(0x00,0x92);// GAS=1);WriteDAT(0x00, VOMG=00);WriteDAT(0x00, PON=1);WriteDAT(0x00, DK=0);WriteDAT(0x00, XDK=0);WriteDAT(0x00, DVDH_TRI=1);WriteDAT(0x00, STB=0
mdelay(100);
WriteCOM(0x00,0x1F);WriteDAT(0x00,0xD2);// GAS=1);WriteDAT(0x00, VOMG=10);WriteDAT(0x00, PON=1);WriteDAT(0x00, DK=0);WriteDAT(0x00, XDK=0);WriteDAT(0x00, DDVDH_TRI=1);WriteDAT(0x00, STB=0
mdelay(100);
//262k/65k color selection
WriteCOM(0x00,0x17);WriteDAT(0x00,0x05); //default 0x06 262k color // 0x05 65k color
//SET PANEL
WriteCOM(0x00,0x36);WriteDAT(0x00,0x09); //SS_P);WriteDAT(0x00, GS_P);WriteDAT(0x00,REV_P);WriteDAT(0x00,BGR_P
//Display ON Setting
WriteCOM(0x00,0x28);WriteDAT(0x00,0x38); //GON=1);WriteDAT(0x00, DTE=1);WriteDAT(0x00, D=1000
mdelay(100);
WriteCOM(0x00,0x28);WriteDAT(0x00,0x3F); //GON=1);WriteDAT(0x00, DTE=1);WriteDAT(0x00, D=1100
//Set GRAM Area
WriteCOM(0x00,0x02);WriteDAT(0x00,0x00);
WriteCOM(0x00,0x03);WriteDAT(0x00,0x00); //Column Start
WriteCOM(0x00,0x04);WriteDAT(0x00,0x00);
WriteCOM(0x00,0x05);WriteDAT(0x00,0xEF); //Column End
WriteCOM(0x00,0x06);WriteDAT(0x00,0x00);
WriteCOM(0x00,0x07);WriteDAT(0x00,0x00); //Row Start
WriteCOM(0x00,0x08);WriteDAT(0x00,0x01);
WriteCOM(0x00,0x09);WriteDAT(0x00,0x3F); //Row End
WriteCOM(0x00,0x31);WriteDAT(0x00,0x01); // System Interface(SPI)
}
void WriteCOM(unsigned char mNULL,unsigned char cmd)
{
mNULL++;
SPI_Enable
SPISend(START_BYTE | SET_INDEX); // for register index
SPISend(cmd);
SPI_Disable
}
void WriteDAT(unsigned char mNULL,unsigned char dat)
{
mNULL++;
SPI_Enable
SPISend(START_BYTE | WRITE_REG);
SPISend(dat);
SPI_Disable
}
void mdelay(unsigned int msec)
{
while(msec--)
{
ndelay();
}
}
/*******************************************************************************/
void SPISend(unsigned char spi_bValue)
{
unsigned char i;
for(i=0; i<8; i++)
{
CLR_SPI_CLK;
if (spi_bValue & 0x80)
{
SET_SPI_MOSI;
}
else
{
CLR_SPI_MOSI;
}
SET_SPI_CLK;
spi_bValue <<= 1;
}
}
void SPISend16(unsigned int spi_bValue)
{
unsigned char i;
for(i=0; i<16; i++)
{
CLR_SPI_CLK;
if (spi_bValue & 0x8000)
{
SET_SPI_MOSI;
}
else
{
CLR_SPI_MOSI;
}
SET_SPI_CLK;
spi_bValue <<= 1;
}
}
|