您的位置 首页 编程

TFT液晶屏C51操控

最近事情比较忙,但是最近好像习惯了在自己博客上发些资料,可以以后自己参考下,也可以供别人参考。上次玩了2.8寸的TFT液晶,这几天有点时…

最近工作比较忙,可是最近如同习惯了在自己博客上发些材料,能够今后自己参阅下,也能够供他人参阅。前次玩了2.8寸的TFT液晶,这几天有点时刻了,用51操控了下2.4寸的TFT液晶,驱动是相同的。写了下程序,放网上。

/*功用描绘:TFT(ILI9325)液晶测验程序 */
/*作者:ClimberWin */
/*编写时刻:2010.3.8 */
/*功用:TFT液晶显现图片和打印字符 */
/*STC89C58RD 接外部晶振11.0592 MHZ */
/**************************************************/

#include
#include”ILI9325.H”
main()
{
uchar i;
LCD_INIT(); //TFT初始化
LCD_picture_diplay();
LCD_write_english_string(20,20,”TFT C51 Test

OK”,GREEN,BLACK);
LCD_write_english_string(20,40,”ClimberWin

2010.3.8″,GREEN,BLACK);

for(i=0;i<10;i++)
{
LCD_caitiao_diplay(100,RED);
LCD_caitiao_diplay(120,GREEN);
LCD_caitiao_diplay(140,BLUE);
LCD_caitiao_diplay(160,YELLOW);
LCD_caitiao_diplay(180,WHITE);
LCD_caitiao_diplay(200,MAGENTA);
LCD_caitiao_diplay(220,CYAN);

LCD_caitiao_diplay(100,CYAN);
LCD_caitiao_diplay(120,RED);
LCD_caitiao_diplay(140,GREEN);
LCD_caitiao_diplay(160,BLUE);
LCD_caitiao_diplay(180,YELLOW);
LCD_caitiao_diplay(200,WHITE);
LCD_caitiao_diplay(220,MAGENTA);
}
while(1);

}

///////////////////////////////////////////////头文件界说//////////////////////////////////////////////////

#ifndef_ILI9325_H_
#define_ILI9325_H_

#include
#include”picture.h”
#include”english_16x8.h”

#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long

#defineBLACK0x0000 //黑
#defineBLUE0x001F //蓝
#defineRED 0xF800 //红
#defineGREEN 0x07E0 //绿
#define CYAN0x07FF //青
#define MAGENTA 0xF81F //洋红
#define YELLOW0xFFE0 //黄
#define WHITE0xFFFF //白

#define LCD_DATA_PORT P0 //界说数据口 D8-D15
sbit LCD_RS = P2^0; //数据/指令切换
sbit LCD_RST = P2^7; //复位
sbit LCD_WR = P2^1; //写操控
sbit LCD_RD =P2^2; //读操控
sbit LCD_CS=P2^5;
void delayms(uint count);
void LCD_Write_REG(uint lcd_reg); //8位数据接口发送16位寄存器地址
void LCD_Write_DATA(uint lcd_data);//8位数据接口发送16位数据
void LCD_Write_REG_DATA( uint lcd_reg,lcd_data); //设置寄存器和数据
void LCD_Add_Set(uint x1,uint y1,uint x2,uint y2);//设置坐标
void LCD_INIT(void);//液晶初始化
void LCD_picture_diplay(void);//显现图片
void LCD_write_english(unsigned char data1,unsigned int color,unsigned int xcolor);//写字符
void LCD_write_english_string(unsigned int x,unsigned int y,unsigned char *s,unsigned int color,unsigned int xcolor);//英文字符串显现
void Lcd_SetBox(unsigned int xStart,unsigned int yStart,unsigned int xLong,unsigned int yLong);
void LCD_SetCursor(unsigned int Xpos, unsigned int Ypos);
void LCD_Clear(unsigned int Color);
void LCD_caitiao_diplay(uchar x,uint color);//画彩条 20点宽 320点长

void delayms(uint count)
{
unsigned int i,j;
for(i=0;ifor(j=0;j<120;j++);
}

void LCD_Write_REG( uint lcd_reg) //8位数据接口发送16位寄存器地址
{
LCD_RS=0;
LCD_CS =0;
LCD_DATA_PORT=lcd_reg>>8;
LCD_WR=0;
LCD_WR=1;
LCD_DATA_PORT=lcd_reg&0XFF;
LCD_WR=0;
LCD_WR=1;
LCD_CS =1;
}

void LCD_Write_DATA(uint lcd_data)//8位数据接口发送16位数据
{
LCD_RS=1;
LCD_CS =0;
LCD_DATA_PORT=lcd_data>>8;
LCD_WR=0;
LCD_WR=1;
LCD_DATA_PORT=lcd_data&0XFF;
LCD_WR=0;
LCD_WR=1;
LCD_CS =1;
}

void LCD_Write_REG_DATA( uint lcd_reg,lcd_data)
{
LCD_Write_REG(lcd_reg);
LCD_Write_DATA(lcd_data);
}

void LCD_Add_Set(uint x1,uint y1,uint x2,uint y2)
{
LCD_Write_REG_DATA(0x0020,x1); //设置X坐标方位
LCD_Write_REG_DATA(0x0021,y1); //设置Y坐标方位
LCD_Write_REG_DATA(0x0050,x1); //开端X
LCD_Write_REG_DATA(0x0052,y1);//开端Y
LCD_Write_REG_DATA(0x0051,x2); //完毕X
LCD_Write_REG_DATA(0x0053,y2); //完毕Y
LCD_Write_REG(0x0022);
}

///////////液晶初始化程序////////////////////
void LCD_INIT(void)
{

LCD_RST=1;
delayms(5);
LCD_RST=0;
delayms(10);
LCD_RST=1;
delayms(20);
//************* Start Initial Sequence **********//
LCD_Write_REG(0x00E5); LCD_Write_DATA(0x78F0); // set SRAM internal timing

//LCD_Write_REG(0x0001); LCD_Write_DATA(0x0100); // set SS and SM bit
LCD_Write_REG(0x0001); LCD_Write_DATA(0x0000); // set SS and SM bit //镜像 摄像头使用的时分要用到

LCD_Write_REG(0x0002); LCD_Write_DATA(0x0700); // set 1 line inversion

//LCD_Write_REG(0x0003); LCD_Write_DATA(0x1030); // set GRAM write direction and BGR=1. 影响显现形式nnnnnnn
LCD_Write_REG(0x0003); LCD_Write_DATA(0x1018); // set GRAM write direction and BGR=1.

LCD_Write_REG(0x0004); LCD_Write_DATA(0x0000); // LCD_RSTize register
LCD_Write_REG(0x0008); LCD_Write_DATA(0x0207); // set the back porch and front porch
LCD_Write_REG(0x0009); LCD_Write_DATA(0x0000); // set non-display area refLCD_RSTh cycle ISC[3:0]
LCD_Write_REG(0x000A); LCD_Write_DATA(0x0000); // FMARK function
LCD_Write_REG(0x000C); LCD_Write_DATA(0x0000); // RGB interface setting
LCD_Write_REG(0x000D); LCD_Write_DATA(0x0000); // Frame marker Position
LCD_Write_REG(0x000F); LCD_Write_DATA(0x0000); // RGB interface polarity
//*************Power On sequence ****************//
//LCD_Write_REG(0x0010); LCD_Write_DATA(0x0000); // SAP, BT[3:0], AP, DSTB, SLP, STB
LCD_Write_REG(0x0010); LCD_Write_DATA(0x0080); // SAP, BT[3:0], AP, DSTB, SLP, STB nnnnnnnnnnn

LCD_Write_REG(0x0011); LCD_Write_DATA(0x0007); // DC1[2:0], DC0[2:0], VC[2:0]
LCD_Write_REG(0x0012); LCD_Write_DATA(0x0000); // VREG1OUT voltage
LCD_Write_REG(0x0013); LCD_Write_DATA(0x0000); // VDV[4:0] for VCOM amplitude
LCD_Write_REG(0x0007); LCD_Write_DATA(0x0001);
delayms(200); // Dis-charge capacitor power voltage

//LCD_Write_REG(0x0010); LCD_Write_DATA(0x1090); // 1490//SAP, BT[3:0], AP, DSTB, SLP, STB //对屏闪有点影响
LCD_Write_REG(0x0010); LCD_Write_DATA(0x1590); // 1490//SAP, BT[3:0], AP, DSTB, SLP, STB nnnnnnnnnn

LCD_Write_REG(0x0011); LCD_Write_DATA(0x0227); // DC1[2:0], DC0[2:0], VC[2:0]
delayms(50); // Delay 50ms
LCD_Write_REG(0x0012); LCD_Write_DATA(0x001F); //001C// Internal reference voltage= Vci;
delayms(50); // Delay 50ms
//LCD_Write_REG(0x0013); LCD_Write_DATA(0x1500); //0x1000//1400 Set VDV[4:0] for VCOM amplitude 1LCD_RS0
LCD_Write_REG(0x0013); LCD_Write_DATA(0x1000); //0x1000//1400 Set VDV[4:0] for VCOM amplitude 1LCD_RS0 nnnnnnnnnnn

//LCD_Write_REG(0x0029); LCD_Write_DATA(0x0027); //0x0012 //001a Set VCM[5:0] for VCOMH //0x0025 0034
//LCD_Write_REG(0x002B); LCD_Write_DATA(0x000D); // Set Frame Rate 000C
LCD_Write_REG(0x0029); LCD_Write_DATA(0x0015); //0x0012 //001a Set VCM[5:0] for VCOMH //0x0025 0034 nnnnnnnnnnn
LCD_Write_REG(0x002B); LCD_Write_DATA(0x000c); // Set Frame Rate 000C nnnnnnnnnnn

delayms(50); // Delay 50ms
LCD_Write_REG(0x0020); LCD_Write_DATA(0x0000); // GRAM horizontal AddLCD_RSTs

//LCD_Write_REG(0x0021); LCD_Write_DATA(0x0000); // GRAM Vertical AddLCD_RSTs
LCD_Write_REG(0x0021); LCD_Write_DATA(0x013f); // GRAM Vertical AddLCD_RSTs nnnnnnnnnnnnnn

// ———– Adjust the Gamma Curve ———-//
LCD_Write_REG(0x0030); LCD_Write_DATA(0x0000);
LCD_Write_REG(0x0031); LCD_Write_DATA(0x0707);

//LCD_Write_REG(0x0032); LCD_Write_DATA(0x0307);
LCD_Write_REG(0x0032); LCD_Write_DATA(0x0505); // nnnnnnnnnnn

//LCD_Write_REG(0x0035); LCD_Write_DATA(0x0200);
LCD_Write_REG(0x0035); LCD_Write_DATA(0x0107); // nnnnnnnnnnn

LCD_Write_REG(0x0036); LCD_Write_DATA(0x0008);//0207
LCD_Write_REG(0x0037); LCD_Write_DATA(0x0004);//0306

//LCD_Write_REG(0x0038); LCD_Write_DATA(0x0000);//0102
//LCD_Write_REG(0x0039); LCD_Write_DATA(0x0707);//0707
//LCD_Write_REG(0x003C); LCD_Write_DATA(0x0002);//0702
//LCD_Write_REG(0x003D); LCD_Write_DATA(0x1D04);//1604
LCD_Write_REG(0x0038); LCD_Write_DATA(0x0202);//0102 nnnnnnnnnn
LCD_Write_REG(0x0039); LCD_Write_DATA(0x0106);//0707 nnnnnnnnnnn
LCD_Write_REG(0x003C); LCD_Write_DATA(0x0202);//0702 nnnnnnnnnnnn
LCD_Write_REG(0x003D); LCD_Write_DATA(0x0408);//1604 nnnnnnnnnnnnn

//—————— Set GRAM area —————//
LCD_Write_REG(0x0050); LCD_Write_DATA(0x0000); // Horizontal GRAM Start AddLCD_RSTs
LCD_Write_REG(0x0051); LCD_Write_DATA(0x00EF); // Horizontal GRAM End AddLCD_RSTs
LCD_Write_REG(0x0052); LCD_Write_DATA(0x0000); // Vertical GRAM Start AddLCD_RSTs
LCD_Write_REG(0x0053); LCD_Write_DATA(0x013F); // Vertical GRAM Start AddLCD_RSTs

//LCD_Write_REG(0x0060); LCD_Write_DATA(0xA700); // Gate Scan Line //影响扫描方位
LCD_Write_REG(0x0060); LCD_Write_DATA(0x2700); // Gate Scan Line nnnnnnnnnnnnn

LCD_Write_REG(0x0061); LCD_Write_DATA(0x0001); // NDL,VLE, REV
LCD_Write_REG(0x006A); LCD_Write_DATA(0x0000); // set scrolling line
//————– Partial Display Control ———//
LCD_Write_REG(0x0080); LCD_Write_DATA(0x0000);
LCD_Write_REG(0x0081); LCD_Write_DATA(0x0000);
LCD_Write_REG(0x0082); LCD_Write_DATA(0x0000);
LCD_Write_REG(0x0083); LCD_Write_DATA(0x0000);
LCD_Write_REG(0x0084); LCD_Write_DATA(0x0000);
LCD_Write_REG(0x0085); LCD_Write_DATA(0x0000);
//————– Panel Control ——————-//
LCD_Write_REG(0x0090); LCD_Write_DATA(0x0010);
LCD_Write_REG(0x0092); LCD_Write_DATA(0x0600);
//增加
LCD_Write_REG(0x0093); LCD_Write_DATA(0x0003);
LCD_Write_REG(0x0095); LCD_Write_DATA(0x0110);
LCD_Write_REG(0x0097); LCD_Write_DATA(0x0000);
LCD_Write_REG(0x0098); LCD_Write_DATA(0x0000);

//LCD_Write_REG(0x0007); LCD_Write_DATA(0x0133); // 262K color and display ON
LCD_Write_REG(0x0007); LCD_Write_DATA(0x0173); // 262K color and display ON nnnnnnnnnn
LCD_Clear(0);//设置底色为黑
}

/**********************************************
函数名:Lcd全屏擦除函数
功用:将Lcd整屏擦为指定色彩
进口参数:color 指定Lcd全屏色彩 RGB(5-6-5)
返回值:无
***********************************************/
void LCD_Clear(unsigned int Color)
{
unsigned long index = 0;

LCD_Write_REG_DATA(0x0020,0x0000);//GRAM水平开始方位
LCD_Write_REG_DATA(0x0021,00000);

LCD_Write_REG_DATA(0x0050,0x00);//水平 GRAM开始方位
LCD_Write_REG_DATA(0x0051,239);//水平GRAM停止方位
LCD_Write_REG_DATA(0x0052,0x00);//笔直GRAM开始方位
LCD_Write_REG_DATA(0x0053,319);//笔直GRAM停止方位
LCD_Write_REG(0x0022);

LCD_RD=1;
LCD_RS=1;
LCD_CS=0;
for(index = 0; index < 76800; index++)
{

LCD_WR=0;
LCD_DATA_PORT=Color>>8;
LCD_WR=1;
LCD_WR=0;
LCD_DATA_PORT=Color&0XFF;
LCD_WR=1;

}
LCD_CS=1;
}

////////////////////////////////////////////////////
void LCD_write_english(unsigned char data1,unsigned int color,unsigned int xcolor)//写字符
{

unsigned char avl,i,n;
LCD_Write_REG(0x0022);
for (i=0;i<16;i++)
{
avl=english[data1-32][i];
for (n=0;n<8;n++)
{
if(avl&0x80) LCD_Write_DATA(color);
else LCD_Write_DATA(xcolor);

avl<<=1;
}
}
}
void LCD_write_english_string(unsigned int x,unsigned int y,unsigned char *s,unsigned int color,unsigned int xcolor)//英文字符串显现
{
unsigned int k=0;
while (*s)
{
Lcd_SetBox(y,x+k,15,8);
LCD_write_english( *s,color,xcolor);
k=k+8;
s++;

}

}

void Lcd_SetBox(unsigned int xStart,unsigned int yStart,unsigned int xLong,unsigned int yLong)
{

LCD_SetCursor(xStart,312-yStart+yLong-1);

LCD_Write_REG_DATA(0x0050,xStart);//水平 GRAM开始方位
LCD_Write_REG_DATA(0x0051,xStart+xLong-1);//水平GRAM停止方位
LCD_Write_REG_DATA(0x0052,312-yStart);//笔直GRAM开始方位
LCD_Write_REG_DATA(0x0053,312-yStart+yLong-1);//笔直GRAM停止方位
}

/*************************************************
函数名:Lcd光标起点定位函数
功用:指定320240液晶上的一点作为写数据的开始点
进口参数:x 坐标 0~239
y 坐标 0~319
返回值:无
*************************************************/
void LCD_SetCursor(unsigned int Xpos, unsigned int Ypos)
{
// CLR_RS;
LCD_Write_REG_DATA(0x20, Xpos);
LCD_Write_REG_DATA(0x21, Ypos);
}
////////////////显现图片///////////////////////////
void LCD_picture_diplay(void)
{
uint i,x1,y1,x2,y2;
uint temp1,temp2,temp;
x1=0;
y1=0;
x2=100;
y2=99;
LCD_Add_Set(x1,y1,x2,y2);

for (i=0;i<20000;i=i+2)
{
temp2=gImage[i];
temp1=gImage[i+1];
temp=(temp1*256)+temp2;
LCD_Write_DATA(temp);
}
}
////////////////显现彩条///////////////////////////
void LCD_caitiao_diplay(uchar x,uint color)
{
uint i,x1,y1,x2,y2;
x1=x;
y1=0;
x2=x+20;
y2=319;
LCD_Add_Set(x1,y1,x2,y2);

for (i=0;i<320*20;i++)
{
LCD_Write_DATA(color);
}
}

#endif

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/fangan/biancheng/267220.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部