TFT液晶屏C51控制
/*功能描述: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; //數(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_DA
void LCD_Write_REG_DA
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 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位數(shù)據(jù)接口發(fā)送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);//設(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_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
}
/*************************************************
函數(shù)名:Lcd光標(biāo)起點定位函數(shù)
功能:指定320240液晶上的一點作為寫數(shù)據(jù)的起始點
入口參數(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_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
評論