新聞中心

TFT液晶屏C51控制

作者: 時(shí)間:2016-11-18 來源:網(wǎng)絡(luò) 收藏
最近事情比較忙,但是最近好像習(xí)慣了在自己博客上發(fā)些資料,可以以后自己參考下,也可以供別人參考。上次玩了2.8寸的TFT液晶,這幾天有點(diǎn)時(shí)間了,用51控制了下2.4寸的TFT液晶,驅(qū)動(dòng)是一樣的。寫了下程序,放網(wǎng)上。

本文引用地址:http://butianyuan.cn/article/201611/316032.htm

/*功能描述:TFT(ILI9325)液晶測(cè)試程序 */
/*作者:ClimberWin */
/*編寫時(shí)間: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 //藍(lán)
#defineRED 0xF800 //紅
#defineGREEN 0x07E0 //綠
#define CYAN0x07FF //青
#define MAGENTA 0xF81F //洋紅
#define YELLOW0xFFE0 //黃
#define WHITE0xFFFF //白


#define LCD_DATA_PORT P0 //定義數(shù)據(jù)口 D8-D15
sbit LCD_RS = P2^0; //數(shù)據(jù)/命令切換
sbit LCD_RST = P2^7; //復(fù)位
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位數(shù)據(jù)接口發(fā)送16位寄存器地址
void LCD_Write_DATA(uint lcd_data);//8位數(shù)據(jù)接口發(fā)送16位數(shù)據(jù)
void LCD_Write_REG_DATA( uint lcd_reg,lcd_data); //設(shè)置寄存器和數(shù)據(jù)
void LCD_Add_Set(uint x1,uint y1,uint x2,uint y2);//設(shè)置坐標(biāo)
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點(diǎn)寬 320點(diǎn)長(zhǎng)

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位數(shù)據(jù)接口發(fā)送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位數(shù)據(jù)接口發(fā)送16位數(shù)據(jù)
{
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); //設(shè)置X坐標(biāo)位置
LCD_Write_REG_DATA(0x0021,y1); //設(shè)置Y坐標(biāo)位置
LCD_Write_REG_DATA(0x0050,x1); //開始X
LCD_Write_REG_DATA(0x0052,y1);//開始Y
LCD_Write_REG_DATA(0x0051,x2); //結(jié)束X
LCD_Write_REG_DATA(0x0053,y2); //結(jié)束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 //鏡像 攝像頭應(yīng)用的時(shí)候要用到

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 //對(duì)屏閃有點(diǎn)影響
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);//設(shè)置底色為黑
}

/**********************************************
函數(shù)名:Lcd全屏擦除函數(shù)
功能:將Lcd整屏擦為指定顏色
入口參數(shù):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終止位置
}

/*************************************************
函數(shù)名:Lcd光標(biāo)起點(diǎn)定位函數(shù)
功能:指定320240液晶上的一點(diǎn)作為寫數(shù)據(jù)的起始點(diǎn)
入口參數(shù):x 坐標(biāo) 0~239
y 坐標(biāo) 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



關(guān)鍵詞: TFT液晶屏C51控

評(píng)論


技術(shù)專區(qū)

關(guān)閉