tft彩屏驱动程序.docx

上传人:b****4 文档编号:3998987 上传时间:2022-11-27 格式:DOCX 页数:11 大小:16.09KB
下载 相关 举报
tft彩屏驱动程序.docx_第1页
第1页 / 共11页
tft彩屏驱动程序.docx_第2页
第2页 / 共11页
tft彩屏驱动程序.docx_第3页
第3页 / 共11页
tft彩屏驱动程序.docx_第4页
第4页 / 共11页
tft彩屏驱动程序.docx_第5页
第5页 / 共11页
点击查看更多>>
下载资源
资源描述

tft彩屏驱动程序.docx

《tft彩屏驱动程序.docx》由会员分享,可在线阅读,更多相关《tft彩屏驱动程序.docx(11页珍藏版)》请在冰豆网上搜索。

tft彩屏驱动程序.docx

tft彩屏驱动程序

/*----------------------------------------------------------------

320x240彩屏液晶驱动程序

----------------------------------------------------------------*/

#include"R61505.h"

#include"reg52.h"

/*----------------------------------------------------------------

全局变量

----------------------------------------------------------------*/

#defineWINDOW_XADDR_START0x0050//HorizontalStartAddressSet

#defineWINDOW_XADDR_END0x0051//HorizontalEndAddressSet

#defineWINDOW_YADDR_START0x0052//VerticalStartAddressSet

#defineWINDOW_YADDR_END0x0053//VerticalEndAddressSet

#defineGRAM_XADDR0x0020//GRAMHorizontalAddressSet

#defineGRAM_YADDR0x0021//GRAMVerticalAddressSet

#defineGRAMWR0x0022//memorywrite

#defineDataPortP0//数据口使用DataPort

/*----------------------------------------------------------------

定义TFT硬件控制端口

----------------------------------------------------------------*/

sbitCS=P2^2;//片选

sbitRES=P2^1;//复位

sbitRS=P2^5;//数据/命令选择

sbitRW=P2^4;//写数据/命令

//================

/*----------------------------------------------------------------

清屏函数

输入参数:

bColor清屏所使用的背景色

----------------------------------------------------------------*/

voidCLR_Screen(unsignedintbColor)

{

unsignedinti,j;

LCD_SetPos(0,240,0,320);//320x240

for(i=0;i<320;i++)

{

for(j=0;j<240;j++)

Write_Data_U16(bColor);

}

}

/*----------------------------------------------------------------

显示英文字符

输入参数:

x横坐标

y纵坐标

c需要显示的字符

fColor字符颜色

bColor字符背景颜色

----------------------------------------------------------------*/

#include"8X16.h"

voidLCD_PutChar8x16(unsignedshortx,unsignedshorty,charc,unsignedintfColor,unsignedintbColor)

{

unsignedinti,j;

LCD_SetPos(x,x+8-1,y,y+16-1);

for(i=0;i<16;i++){

unsignedcharm=Font8x16[c*16+i];

for(j=0;j<8;j++){

if((m&0x80)==0x80){

Write_Data_U16(fColor);

}

else{

Write_Data_U16(bColor);

}

m<<=1;

}

}

}

/*----------------------------------------------------------------

显示英文字符

输入参数:

x横坐标

y纵坐标

c需要显示的字符

fColor字符颜色

bColor字符背景颜色

----------------------------------------------------------------*/

voidLCD_PutChar(unsignedshortx,unsignedshorty,charc,unsignedintfColor,unsignedintbColor){

LCD_PutChar8x16(x,y,c,fColor,bColor);

}

/*----------------------------------------------------------------

显示汉字

输入参数:

x横坐标

y纵坐标

c需要显示的汉字码

fColor字符颜色

bColor字符背景颜色

----------------------------------------------------------------*/

#include"GB1616.h"//16*16汉字字模

voidPutGB1616(unsignedshortx,unsignedshorty,unsignedcharc[2],unsignedintfColor,unsignedintbColor){

unsignedinti,j,k;

LCD_SetPos(x,x+16-1,y,y+16-1);

for(k=0;k<64;k++){//64标示自建汉字库中的个数,循环查询内码

if((codeGB_16[k].Index[0]==c[0])&&(codeGB_16[k].Index[1]==c[1])){

for(i=0;i<32;i++){

unsignedshortm=codeGB_16[k].Msk[i];

for(j=0;j<8;j++){

if((m&0x80)==0x80){

Write_Data_U16(fColor);

}

else{

Write_Data_U16(bColor);

}

m<<=1;

}

}

}

}

}

/*----------------------------------------------------------------

显示字符串

可以中英文同时显示

输入参数:

x横坐标

y纵坐标

*s需要显示的字符串

fColor字符颜色

bColor字符背景颜色

----------------------------------------------------------------*/

voidLCD_PutString(unsignedshortx,unsignedshorty,unsignedchar*s,unsignedintfColor,unsignedintbColor){

unsignedcharl=0;

while(*s){

if(*s<0x80)

{

LCD_PutChar(x+l*8,y,*s,fColor,bColor);

s++;l++;

}

else

{

PutGB1616(x+l*8,y,(unsignedchar*)s,fColor,bColor);

s+=2;l+=2;

}

}

}

/*----------------------------------------------------------------

显示RGB颜色

输入参数:

x0,y0起始坐标

x1,y1结束坐标

Color背景颜色

----------------------------------------------------------------*/

voidShow_RGB(unsignedintx0,unsignedintx1,unsignedinty0,unsignedinty1,unsignedintColor)

{

unsignedinti,j;

LCD_SetPos(x0,x1,y0,y1);

for(i=y0;i<=y1;i++)

{

for(j=x0;j<=x1;j++)

Write_Data_U16(Color);

}

}

/*----------------------------------------------------------------

写命令、写数据

输入参数:

x需要输入的命令16位

y需要输入的数据16位

----------------------------------------------------------------*/

voidWrite_Cmd_Data(unsignedcharx,unsignedinty)

{

unsignedcharm,n;

m=y>>8;

n=y;

Write_Cmd(0x00,x);

Write_Data(m,n);

}

/*----------------------------------------------------------------

写16位数据

----------------------------------------------------------------*/

voidWrite_Data_U16(unsignedinty)

{

unsignedcharm,n;

m=y>>8;

n=y;

Write_Data(m,n);

}

/*----------------------------------------------------------------

写命令

----------------------------------------------------------------*/

voidWrite_Cmd(unsignedcharDH,unsignedcharDL)

{

CS=0;

RS=0;

DataPort=DH;

RW=0;

RW=1;

DataPort=DL;

RW=0;

RW=1;

CS=1;

}

/*----------------------------------------------------------------

写数据双8位

----------------------------------------------------------------*/

voidWrite_Data(unsignedcharDH,unsignedcharDL)

{

CS=0;

RS=1;

DataPort=DH;

RW=0;

RW=1;

DataPort=DL;

RW=0;

RW=1;

CS=1;

}

/*----------------------------------------------------------------

延时函数

----------------------------------------------------------------*/

voiddelayms(unsignedintcount)

{

inti,j;

for(i=0;i

{

for(j=0;j<260;j++);

}

}

 

/*----------------------------------------------------------------

液晶初始化

----------------------------------------------------------------*/

voidR61505_Initial(void)

{

Write_Cmd_Data(0x0000,0x0000);

Write_Cmd_Data(0x0000,0x0000);

Write_Cmd_Data(0x0000,0x0000);

Write_Cmd_Data(0x0000,0x0000);

Write_Cmd_Data(0x0010,0x0600);//SLP=0,

delayms(30);

Write_Cmd_Data(0x0007,0x0000);

Write_Cmd_Data(0x0012,0x011A);

Write_Cmd_Data(0x00A4,0x0001);

Write_Cmd_Data(0x0008,0x020E);//FP,BP

Write_Cmd_Data(0x000A,0x0008);

Write_Cmd_Data(0x000D,0x0008);

Write_Cmd_Data(0x0030,0x0707);

Write_Cmd_Data(0x0031,0x0007);

Write_Cmd_Data(0x0032,0x0603);

Write_Cmd_Data(0x0033,0x0700);

Write_Cmd_Data(0x0034,0x0202);

Write_Cmd_Data(0x0035,0x0002);

Write_Cmd_Data(0x0036,0x1E00);

Write_Cmd_Data(0x0037,0x0707);

Write_Cmd_Data(0x0038,0x0000);

Write_Cmd_Data(0x0039,0x0000);

Write_Cmd_Data(0x003A,0x0707);

Write_Cmd_Data(0x003B,0x0000);

Write_Cmd_Data(0x003C,0x0007);

Write_Cmd_Data(0x003D,0x0000);

delayms(30);

Write_Cmd_Data(0x0011,0x0007);

Write_Cmd_Data(0x0060,0x2700);

Write_Cmd_Data(0x0090,0x0016);//DIVI,RTNI

Write_Cmd_Data(0x0017,0x0001);

Write_Cmd_Data(0x0019,0x0000);//TBT[1:

0]

delayms(30);

Write_Cmd_Data(0x0010,0x16B0);

Write_Cmd_Data(0x0012,0x011A);

delayms(30);

Write_Cmd_Data(0x0013,0x1800);//VDV[4:

0]

Write_Cmd_Data(0x002A,0x000E);//VCMSEL,VCM2[4:

0]

Write_Cmd_Data(0x0029,0x000E);//VCM1[4:

0]

delayms(30);

Write_Cmd_Data(0x0012,0x013A);//VCOMR[0],VREG1R,PSON,PON,VRH[3:

0]

delayms(100);

Write_Cmd_Data(0x0050,0x0000);

Write_Cmd_Data(0x0051,0x00EF);

Write_Cmd_Data(0x0052,0x0000);

Write_Cmd_Data(0x0053,0x013F);

Write_Cmd_Data(0x0020,0x0000);

Write_Cmd_Data(0x0021,0x0000);

Write_Cmd_Data(0x0061,0x0001);

Write_Cmd_Data(0x006A,0x0000);

Write_Cmd_Data(0x0080,0x0000);

Write_Cmd_Data(0x0081,0x0000);

Write_Cmd_Data(0x0082,0x0000);

Write_Cmd_Data(0x0083,0x0000);

Write_Cmd_Data(0x0084,0x0000);

Write_Cmd_Data(0x0085,0x0000);

Write_Cmd_Data(0x0092,0x0300);

Write_Cmd_Data(0x0093,0x0005);

Write_Cmd_Data(0x0095,0x0000);

Write_Cmd_Data(0x0097,0x0000);

Write_Cmd_Data(0x0098,0x0000);

Write_Cmd_Data(0x0001,0x0100);

Write_Cmd_Data(0x0002,0x0700);

Write_Cmd_Data(0x0003,0x1030);

Write_Cmd_Data(0x0004,0x0000);

Write_Cmd_Data(0x000C,0x0000);

Write_Cmd_Data(0x000F,0x0000);

delayms(30);

Write_Cmd_Data(0x0007,0x0001);

Write_Cmd_Data(0x0007,0x0021);

delayms(30);

Write_Cmd_Data(0x0010,0x16B0);//Writefinaluser’ssettingvaluestoBTbits

Write_Cmd_Data(0x0011,0x0007);//Writefinaluser’ssettingvaluestoVCbits

delayms(30);

Write_Cmd_Data(0x0007,0x0061);

delayms(30);

Write_Cmd_Data(0x0007,0x0173);

delayms(30);

}

/*----------------------------------------------------------------

设置坐标

----------------------------------------------------------------*/

staticvoidLCD_SetPos(unsignedintx0,unsignedintx1,unsignedinty0,unsignedinty1)

{

Write_Cmd_Data(WINDOW_XADDR_START,x0);

Write_Cmd_Data(WINDOW_XADDR_END,x1);

Write_Cmd_Data(WINDOW_YADDR_START,y0);

Write_Cmd_Data(WINDOW_YADDR_END,y1);

Write_Cmd_Data(GRAM_XADDR,x0);

Write_Cmd_Data(GRAM_YADDR,y0);

Write_Cmd(0x00,0x22);//LCD_WriteCMD(GRAMWR);

}

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 解决方案 > 解决方案

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1