最近工作比较忙,可是最近如同习惯了在自己博客上发些材料,能够今后自己参阅下,也能够供他人参阅。前次玩了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_DA
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_DA
void LCD_Write_REG_DA
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 da
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;i
}
void LCD_Write_REG( uint lcd_reg) //8位数据接口发送16位寄存器地址
{
LCD_RS=0;
LCD_CS =0;
LCD_DA
LCD_WR=0;
LCD_WR=1;
LCD_DA
LCD_WR=0;
LCD_WR=1;
LCD_CS =1;
}
void LCD_Write_DA
{
LCD_RS=1;
LCD_CS =0;
LCD_DA
LCD_WR=0;
LCD_WR=1;
LCD_DA
LCD_WR=0;
LCD_WR=1;
LCD_CS =1;
}
void LCD_Write_REG_DA
{
LCD_Write_REG(lcd_reg);
LCD_Write_DA
}
void LCD_Add_Set(uint x1,uint y1,uint x2,uint y2)
{
LCD_Write_REG_DA
LCD_Write_REG_DA
LCD_Write_REG_DA
LCD_Write_REG_DA
LCD_Write_REG_DA
LCD_Write_REG_DA
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_DA
//LCD_Write_REG(0x0001); LCD_Write_DA
LCD_Write_REG(0x0001); LCD_Write_DA
LCD_Write_REG(0x0002); LCD_Write_DA
//LCD_Write_REG(0x0003); LCD_Write_DA
LCD_Write_REG(0x0003); LCD_Write_DA
LCD_Write_REG(0x0004); LCD_Write_DA
LCD_Write_REG(0x0008); LCD_Write_DA
LCD_Write_REG(0x0009); LCD_Write_DA
LCD_Write_REG(0x000A); LCD_Write_DA
LCD_Write_REG(0x000C); LCD_Write_DA
LCD_Write_REG(0x000D); LCD_Write_DA
LCD_Write_REG(0x000F); LCD_Write_DA
//*************Power On sequence ****************//
//LCD_Write_REG(0x0010); LCD_Write_DA
LCD_Write_REG(0x0010); LCD_Write_DA
LCD_Write_REG(0x0011); LCD_Write_DA
LCD_Write_REG(0x0012); LCD_Write_DA
LCD_Write_REG(0x0013); LCD_Write_DA
LCD_Write_REG(0x0007); LCD_Write_DA
delayms(200); // Dis-charge capacitor power voltage
//LCD_Write_REG(0x0010); LCD_Write_DA
LCD_Write_REG(0x0010); LCD_Write_DA
LCD_Write_REG(0x0011); LCD_Write_DA
delayms(50); // Delay 50ms
LCD_Write_REG(0x0012); LCD_Write_DA
delayms(50); // Delay 50ms
//LCD_Write_REG(0x0013); LCD_Write_DA
LCD_Write_REG(0x0013); LCD_Write_DA
//LCD_Write_REG(0x0029); LCD_Write_DA
//LCD_Write_REG(0x002B); LCD_Write_DA
LCD_Write_REG(0x0029); LCD_Write_DA
LCD_Write_REG(0x002B); LCD_Write_DA
delayms(50); // Delay 50ms
LCD_Write_REG(0x0020); LCD_Write_DA
//LCD_Write_REG(0x0021); LCD_Write_DA
LCD_Write_REG(0x0021); LCD_Write_DA
// ———– Adjust the Gamma Curve ———-//
LCD_Write_REG(0x0030); LCD_Write_DA
LCD_Write_REG(0x0031); LCD_Write_DA
//LCD_Write_REG(0x0032); LCD_Write_DA
LCD_Write_REG(0x0032); LCD_Write_DA
//LCD_Write_REG(0x0035); LCD_Write_DA
LCD_Write_REG(0x0035); LCD_Write_DA
LCD_Write_REG(0x0036); LCD_Write_DA
LCD_Write_REG(0x0037); LCD_Write_DA
//LCD_Write_REG(0x0038); LCD_Write_DA
//LCD_Write_REG(0x0039); LCD_Write_DA
//LCD_Write_REG(0x003C); LCD_Write_DA
//LCD_Write_REG(0x003D); LCD_Write_DA
LCD_Write_REG(0x0038); LCD_Write_DA
LCD_Write_REG(0x0039); LCD_Write_DA
LCD_Write_REG(0x003C); LCD_Write_DA
LCD_Write_REG(0x003D); LCD_Write_DA
//—————— Set GRAM area —————//
LCD_Write_REG(0x0050); LCD_Write_DA
LCD_Write_REG(0x0051); LCD_Write_DA
LCD_Write_REG(0x0052); LCD_Write_DA
LCD_Write_REG(0x0053); LCD_Write_DA
//LCD_Write_REG(0x0060); LCD_Write_DA
LCD_Write_REG(0x0060); LCD_Write_DA
LCD_Write_REG(0x0061); LCD_Write_DA
LCD_Write_REG(0x006A); LCD_Write_DA
//————– Partial Display Control ———//
LCD_Write_REG(0x0080); LCD_Write_DA
LCD_Write_REG(0x0081); LCD_Write_DA
LCD_Write_REG(0x0082); LCD_Write_DA
LCD_Write_REG(0x0083); LCD_Write_DA
LCD_Write_REG(0x0084); LCD_Write_DA
LCD_Write_REG(0x0085); LCD_Write_DA
//————– Panel Control ——————-//
LCD_Write_REG(0x0090); LCD_Write_DA
LCD_Write_REG(0x0092); LCD_Write_DA
//增加
LCD_Write_REG(0x0093); LCD_Write_DA
LCD_Write_REG(0x0095); LCD_Write_DA
LCD_Write_REG(0x0097); LCD_Write_DA
LCD_Write_REG(0x0098); LCD_Write_DA
//LCD_Write_REG(0x0007); LCD_Write_DA
LCD_Write_REG(0x0007); LCD_Write_DA
LCD_Clear(0);//设置底色为黑
}
/**********************************************
函数名:Lcd全屏擦除函数
功用:将Lcd整屏擦为指定色彩
进口参数:color 指定Lcd全屏色彩 RGB(5-6-5)
返回值:无
***********************************************/
void LCD_Clear(unsigned int Color)
{
unsigned long index = 0;
LCD_Write_REG_DA
LCD_Write_REG_DA
LCD_Write_REG_DA
LCD_Write_REG_DA
LCD_Write_REG_DA
LCD_Write_REG_DA
LCD_Write_REG(0x0022);
LCD_RD=1;
LCD_RS=1;
LCD_CS=0;
for(index = 0; index < 76800; index++)
{
LCD_WR=0;
LCD_DA
LCD_WR=1;
LCD_WR=0;
LCD_DA
LCD_WR=1;
}
LCD_CS=1;
}
////////////////////////////////////////////////////
void LCD_write_english(unsigned char da
{
unsigned char avl,i,n;
LCD_Write_REG(0x0022);
for (i=0;i<16;i++)
{
avl=english[da
for (n=0;n<8;n++)
{
if(avl&0x80) LCD_Write_DA
else LCD_Write_DA
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_DA
LCD_Write_REG_DA
LCD_Write_REG_DA
LCD_Write_REG_DA
}
/*************************************************
函数名:Lcd光标起点定位函数
功用:指定320240液晶上的一点作为写数据的开始点
进口参数:x 坐标 0~239
y 坐标 0~319
返回值:无
*************************************************/
void LCD_SetCursor(unsigned int Xpos, unsigned int Ypos)
{
// CLR_RS;
LCD_Write_REG_DA
LCD_Write_REG_DA
}
////////////////显现图片///////////////////////////
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_DA
}
}
////////////////显现彩条///////////////////////////
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_DA
}
}
#endif