请教TFT屏,ILI9325驱动的问题
这个是STC12c5a60S2单片机驱动的,picture.h、chinese.h、char.h里都是要显示的字符,问题出现在屏幕显示的都是花点,不然就是全白,是什么问题?#include <reg52.h>#include"LCD_driver.h"
#include"picture.h"
#include"chinese.h"
#include"char.h"
uint colors[]=
{
0xf800,0x07e0,0x001f,0xffe0,0x0000,0x07ff,0xf81f,0xffff//颜色数据
};
void LCD_Init(void)
{
LCD_REST=1;
delayms(5);
LCD_REST=0;
delayms(5);
LCD_REST=1;
delayms(5);
LCD_CS =0;//打开片选使能
//************* Start Initial Sequence **********//
LCD_Write_COM(0x00,0xE5); LCD_Write_DATA(0x78,0xF0); // set SRAM internal timing 设置静态存储器内部定时
LCD_Write_COM(0x00,0x01); LCD_Write_DATA(0x01,0x00); // set SS and SM bit
LCD_Write_COM(0x00,0x02); LCD_Write_DATA(0x07,0x00); // set 1 line inversion 倒转
LCD_Write_COM(0x00,0x03); LCD_Write_DATA(0x10,0x30); // set GRAM write direction and BGR=1.
LCD_Write_COM(0x00,0x04); LCD_Write_DATA(0x00,0x00); // Resize register
LCD_Write_COM(0x00,0x08); LCD_Write_DATA(0x02,0x07); // set the back porch and front porch
LCD_Write_COM(0x00,0x09); LCD_Write_DATA(0x00,0x00); // set non-display area refresh cycle ISC
LCD_Write_COM(0x00,0x0A); LCD_Write_DATA(0x00,0x00); // FMARK function
LCD_Write_COM(0x00,0x0C); LCD_Write_DATA(0x00,0x00); // RGB interface setting
LCD_Write_COM(0x00,0x0D); LCD_Write_DATA(0x00,0x00); // Frame marker Position
LCD_Write_COM(0x00,0x0F); LCD_Write_DATA(0x00,0x00); // RGB interface polarity
//*************Power On sequence ****************//
LCD_Write_COM(0x00,0x10); LCD_Write_DATA(0x00,0x00); // SAP, BT, AP, DSTB, SLP, STB
LCD_Write_COM(0x00,0x11); LCD_Write_DATA(0x00,0x07); // DC1, DC0, VC
LCD_Write_COM(0x00,0x12); LCD_Write_DATA(0x00,0x00); // VREG1OUT voltage
LCD_Write_COM(0x00,0x13); LCD_Write_DATA(0x00,0x00); // VDV for VCOM amplitude
LCD_Write_COM(0x00,0x07); LCD_Write_DATA(0x00,0x01);
delayms(50); // Dis-charge capacitor power voltage
LCD_Write_COM(0x00,0x10); LCD_Write_DATA(0x10,0x90); // 1490//SAP, BT, AP, DSTB, SLP, STB
LCD_Write_COM(0x00,0x11); LCD_Write_DATA(0x02,0x27); // DC1, DC0, VC
delayms(50); // Delay 50ms
LCD_Write_COM(0x00,0x12); LCD_Write_DATA(0x00,0x1F); //001C// Internal reference voltage= Vci;
delayms(50); // Delay 50ms
LCD_Write_COM(0x00,0x13); LCD_Write_DATA(0x15,0x00); //0x1000//1400 Set VDV for VCOM amplitude1A00
LCD_Write_COM(0x00,0x29); LCD_Write_DATA(0x00,0x27); //0x0012 //001aSet VCM for VCOMH//0x00250034
LCD_Write_COM(0x00,0x2B); LCD_Write_DATA(0x00,0x0D); // Set Frame Rate 000C
delayms(50); // Delay 50ms
LCD_Write_COM(0x00,0x20); LCD_Write_DATA(0x00,0x00); // GRAM horizontal Address
LCD_Write_COM(0x00,0x21); LCD_Write_DATA(0x00,0x00); // GRAM Vertical Address
// ----------- Adjust the Gamma Curve ----------//
LCD_Write_COM(0x00,0x30); LCD_Write_DATA(0x00,0x00);
LCD_Write_COM(0x00,0x31); LCD_Write_DATA(0x07,0x07);
LCD_Write_COM(0x00,0x32); LCD_Write_DATA(0x03,0x07);
LCD_Write_COM(0x00,0x35); LCD_Write_DATA(0x02,0x00);
LCD_Write_COM(0x00,0x36); LCD_Write_DATA(0x00,0x08);//0207
LCD_Write_COM(0x00,0x37); LCD_Write_DATA(0x00,0x04);//0306
LCD_Write_COM(0x00,0x38); LCD_Write_DATA(0x00,0x00);//0102
LCD_Write_COM(0x00,0x39); LCD_Write_DATA(0x07,0x07);//0707
LCD_Write_COM(0x00,0x3C); LCD_Write_DATA(0x00,0x02);//0702
LCD_Write_COM(0x00,0x3D); LCD_Write_DATA(0x1D,0x04);//1604
//------------------ Set GRAM area ---------------//
LCD_Write_COM(0x00,0x50); LCD_Write_DATA(0x00,0x00); // Horizontal GRAM Start Address
LCD_Write_COM(0x00,0x51); LCD_Write_DATA(0x00,0xEF); // Horizontal GRAM End Address
LCD_Write_COM(0x00,0x52); LCD_Write_DATA(0x00,0x00); // Vertical GRAM Start Address
LCD_Write_COM(0x00,0x53); LCD_Write_DATA(0x01,0x3F); // Vertical GRAM Start Address
LCD_Write_COM(0x00,0x60); LCD_Write_DATA(0xA7,0x00); // Gate Scan Line
LCD_Write_COM(0x00,0x61); LCD_Write_DATA(0x00,0x01); // NDL,VLE, REV
LCD_Write_COM(0x00,0x6A); LCD_Write_DATA(0x00,0x00); // set scrolling line
//-------------- Partial Display Control ---------//
LCD_Write_COM(0x00,0x80); LCD_Write_DATA(0x00,0x00);
LCD_Write_COM(0x00,0x81); LCD_Write_DATA(0x00,0x00);
LCD_Write_COM(0x00,0x82); LCD_Write_DATA(0x00,0x00);
LCD_Write_COM(0x00,0x83); LCD_Write_DATA(0x00,0x00);
LCD_Write_COM(0x00,0x84); LCD_Write_DATA(0x00,0x00);
LCD_Write_COM(0x00,0x85); LCD_Write_DATA(0x00,0x00);
//-------------- Panel Control -------------------//
LCD_Write_COM(0x00,0x90); LCD_Write_DATA(0x00,0x10);
LCD_Write_COM(0x00,0x92); LCD_Write_DATA(0x06,0x00);
LCD_Write_COM(0x00,0x07); LCD_Write_DATA(0x01,0x33); // 262K color and display ON
LCD_CS =1;//关闭片选使能
}
void delayms(int count)// /* X1ms */
{
int i,j;
for(i=0;i<count;i++)
for(j=0;j<100;j++);
}
#ifdefBus_16 //条件编译-16位数据模式
void LCD_Writ_Bus(char VH,char VL) //并行数据写入函数
{
LCD_DataPortH=VH; //高位P1口
LCD_DataPortL=VL; //低位P0口
LCD_WR=0;
LCD_WR=1;
}
#else //条件编译-8位数据模式
void LCD_Writ_Bus(char VH,char VL) //并行数据写入函数
{
LCD_DataPortH=VH;//八位模式都用P0口送数据
LCD_WR=0;
LCD_WR=1;
LCD_DataPortH=VL; //八位模式都用P0口送数据
LCD_WR=0;
LCD_WR=1;
}
#endif
void LCD_Write_COM(char VH,char VL) //发送命令
{
LCD_RS=0;
LCD_Writ_Bus(VH,VL);
}
void LCD_Write_DATA(char VH,char VL) //发送数据
{
LCD_RS=1;
LCD_Writ_Bus(VH,VL);
}
void Pant(char VH,char VL)
{
int i,j;
LCD_CS =0;//打开片选使能
Address_set(0,0,239,319);
for(i=0;i<320;i++)
{
for (j=0;j<240;j++)
{
LCD_Write_DATA(VH,VL);
}
}
LCD_CS =1;//关闭片选使能
}
void Address_set(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2)
{
LCD_Write_COM(0x00,0x20);LCD_Write_DATA(x1>>8,x1); //设置X坐标位置
LCD_Write_COM(0x00,0x21);LCD_Write_DATA(y1>>8,y1); //设置Y坐标位置
LCD_Write_COM(0x00,0x50);LCD_Write_DATA(x1>>8,x1); //开始X
LCD_Write_COM(0x00,0x52);LCD_Write_DATA(y1>>8,y1); //开始Y
LCD_Write_COM(0x00,0x51);LCD_Write_DATA(x2>>8,x2); //结束X
LCD_Write_COM(0x00,0x53);LCD_Write_DATA(y2>>8,y2); //结束Y
LCD_Write_COM(0x00,0x22);
}
/**********************************************************
写汉字子函数
**********************************************************/
void ChineseChar(uint x,uint y,int size,uint For_color,uint Bk_color ,char c)
{
int e=0,i,j;
inted;
uintncols;
uintnrows;
uintnbytes;
uchar *pfont;
uchar *pchar;
uchar *fonttable[]={(uchar *)hz16,(uchar *)hz24 , (uchar *)hz32};
pfont=(uchar *)fonttable;
if(size==0)
{
ncols =16-1;
nrows =16-1;
nbytes =32; //(16*16)/8
}
else
if(size==1)
{
ncols =24-1;
nrows =24-1;
nbytes =72;//(24*24)/8
}
else
if(size==2)
{
ncols =32-1;
nrows =32-1;
nbytes =132; //(32*32)/8
}
pchar=pfont + (nbytes*(c-1));
Address_set(x,y, x+nrows,y+ncols);
for(i=0;i<nbytes;i++)
{
ed=*pchar++;
if(size==0)
{
if(i%2==0)
e=8;
else
e=4;
}
else
e=8;
for(j=0;j<e;j++)
{// unsigned char temp;
if((ed>>j)&0x01)
{
//temp = For_color&0x00ff
LCD_Write_DATA(For_color>>8 , For_color);//textcolor
}
else
{
LCD_Write_DATA( Bk_color>>8 ,Bk_color);//backcolor
}
}
}
}
/*********************************************************/
/**********************************************************
字符显示子函数
**********************************************************/
void LCD_ShowChar(uint x,uint y,uint For_color,uint Bk_color, char ch)
{
uchar temp , Bytes;
uchar pos,t;
uintCHAR_W,CHAR_H;
//CHAR_W = 8; //8*16
//CHAR_H = 16;
CHAR_W = 16; //16*24
CHAR_H = 24;
if(x>(LCD_SIZE_X-CHAR_W)||y>(LCD_SIZE_Y-CHAR_H))
return;
Address_set(x, y, x+CHAR_W-1, y+CHAR_H-1);
ch = ch-32; //按照ASCII编码顺序的到相应字母的编码
Bytes = (CHAR_W*CHAR_H)/8;
for(pos=0;pos<Bytes;pos++)//CHAR_H (CHAR_W*CHAR_H)/8
{
// temp= Font8x16;
//temp= Font16x24;
temp= Font16x24;
for(t=0;t<8;t++) //CHAR_W
{
if(temp&0x80)
LCD_Write_DATA(For_color>>8 , For_color);//textcolor
else
LCD_Write_DATA(Bk_color>>8 , Bk_color );//backcolor
temp<<=1;
}
}
}
/**********************************************************
显示字符串子函数
x,y:起点坐标
*p:字符串起始地址
**********************************************************/
void LCD_ShowString(uint x,uint y,uint For_color,uint Bk_color,char *p)
{
while(*p!='\0')
{
LCD_ShowChar(x,y,For_color,Bk_color,*p);
// x+=8;
x+=16;
p++;
}
}main()
{
//int i,j,k;
LCD_Init(); //TFT初始化
// Pant(0xff,0xff); //TFT清屏
//Pant(0xf8,0x00); //红色
//Pant(0X07,0xE0); //绿色
Pant(0x00,0x1f); //蓝色
LCD_CS =0;//打开片选使能
ChineseChar(14+46,10,2,colors,colors,1);
ChineseChar(46+46,10,2,colors,colors,2);
ChineseChar(78+46,10,2,colors,colors,3);
ChineseChar(110+46,10,2,colors,colors,4);
LCD_ShowString(12,60,colors,colors,"-");
ChineseChar(20,60,1,colors,colors,1); //带
ChineseChar(44,60,1,colors,colors,2); //您
ChineseChar(68,60,1,colors,colors,3); //进
ChineseChar(92,60,1,colors,colors,4); //入
ChineseChar(116,60,1,colors,colors,5); //单
ChineseChar(140,60,1,colors,colors,6); //片
ChineseChar(164,60,1,colors,colors,7); //机
ChineseChar(188,60,1,colors,colors,8); //世
ChineseChar(212,60,1,colors,colors,9); //界
LCD_ShowString(0,90,colors,colors,"WWW.PRECHIN.com");
ChineseChar(0,120,1,colors,colors,10);
ChineseChar(24,120,1,colors,colors,11);
ChineseChar(48,120,1,colors,colors,12);
ChineseChar(72,120,1,colors,colors,13);
ChineseChar(96,120,1,colors,colors,14);
ChineseChar(120,120,1,colors,colors,15);
LCD_ShowString(0,150,colors,colors,"www.PRECHIN.net");
LCD_ShowString(12,180,colors,colors,"TELL:");
LCD_ShowString(12,210,colors,colors,"0755-61190227");
LCD_ShowString(0,240,colors,colors,"abcdefJhiJKLMNOP");
LCD_ShowString(0,265,colors,colors,"pqrstuvwxyz!@#$");
LCD_ShowString(0,290,colors,colors,"<>CDEF^&*()/,[]");
LCD_CS =1;//关闭片选使能
while(1){}
}
页:
[1]