|
原创程序)TFT屏驱动程序
/*============================================================
* TFT屏驱动程序
* 作者 :梦想科技*老高
* Email:9902013327@163.com
* 单片机采用AT89S52,晶振频率为:12.00MHz。
==============================================================
硬件:?22*32)模拟口线接线方式,连接线图:
--------------------------------------------------|
|DB0-----P0.0 | DB4-----P0.4 | RW-------P1.1 | A0--------P1.0 |
|DB1-----P0.1 | DB5-----P0.5 | RD-------P1.2 | Ext直接接到GND |
|DB2-----P0.2 | DB6-----P0.6 | CS-------P1.3 |
|DB3-----P0.3 | DB7-----P0.7 | REST-------P1.4 |
=============================================================*/
#include <AT89X55.H>
#include <intrins.h>
#define uchar unsigned char
#define LCD_DATA P0
//****定义引脚********//
sbit LCD_A0=P1^0; //指令或数据选择
sbit LCD_RW=P1^1; //写数据
sbit LCD_RD=P1^2; //读数据
sbit LCD_CS=P1^3; //片选信号
sbit LCD_RST=P1^4; //软件复位
uchar show[]="Comedia";
//延时程序
void delay(uchar second) //second=1时,延时5ms子程序
{
unsigned char i,j,k;
for(i=second;i>0;i--)
for(j=10;j>0;j--)
for(k=248;k>0;k--);
}
//复位函数实现
void Rst_bit ()
{
P1=P1&0xf7; //片选液晶屏LCD_CS=0;
P1=P1&0xef; //低电瓶有效LCD_RST=0;
delay(10);
P1=P1|0x10; //低电瓶有效LCD_RST=1;
}
//写指令子函数
void write_code(uchar com)
{
P1=P1&0xfe; //选择写指令LCD_A0 = 0;
delay(1);
P1=P1|0x04; //读操作LCD_RD = 1;
delay(1);
LCD_DATA = com;
P1=P1&0xfd; //写操作LCD_RW = 0;
delay(1);
_nop_();
_nop_();
P1=P1|0x02; //写操作LCD_RW = 1;
}
//写数据子函数
void write_data0(uchar dat)
{
P1=P1|0x01; //选择写数据LCD_A0 = 1;
delay(1);
P1=P1&0xfb; //读操作LCD_RD = 0;
// P1=P1|0x04; //读操作LCD_RD = 1;
delay(1);
LCD_DATA = dat;
delay(1);
P1=P1&0xfd; //写操作LCD_RW = 0;
delay(1);
_nop_();
_nop_();
P1=P1|0x02; //写操作LCD_RW = 1;
}
//写数据子函数
void write_data(uchar dat)
{
P1=P1|0x01; //选择写数据LCD_A0 = 1;
delay(1);
// P1=P1&0xfb; //读操作LCD_RD = 0;
P1=P1|0x04; //读操作LCD_RD = 1;
delay(1);
LCD_DATA = dat;
delay(1);
P1=P1&0xfd; //写操作LCD_RW = 0;
delay(1);
_nop_();
_nop_();
P1=P1|0x02; //写操作LCD_RW = 1;
}
//初始化液晶屏
void Initial(void)
{
write_code(0x01); //Software Reset
delay(30); //delay 150mS
write_code(0xD7); //Autoread control
write_data(0xBF); //Disable Autoread
write_code(0xE0); //Control OTP/MTP
write_data(0x00); //Read Mode
delay(2); //delay 10mS
write_code(0xE3); //Control OTP/MTP
delay(4); //delay 20mS
write_code(0xE1); //Close Read Mode
//-----------------------------------------------------------------------------------//
write_code(0x11); //Sleep Out
write_code(0x20); //Normal Display
//------------------------------------OTPB Set---------------------------------------//
write_code(0xC3); //Bias Set:1/12
write_data(0x00); //1/12
write_code(0xC4); //Booster Set
write_data(0x06); //
write_code(0xC5); //Booster Efficiency Set
write_data(0x01); //
write_code(0xCB); //VG Booster Set
write_data(0x01); //
write_code(0xCC); //ID1 Set
write_data(0x45); //
write_code(0xCE); //ID3 Set
write_data(0x00); //
write_code(0xB7); //Glass Direction
write_data(0xC0); //
write_code(0xD0); //Follower Type set
write_data(0x19); //
//------------------------------------MTP Set----------------------------------------//
write_code(0xD7); //Autoread control
write_data(0xBF); //
// write_code(0x00,0xC7); //V0 Offset Voltage Set
// write_data(0x00,0x00); //
// write_data(0x00,0x00); //
write_code(0xB5); //N-line Set
write_data(0x00); //
write_code(0xCD); //ID2 Set
write_data(0xD2); //
write_code(0xD0); //Set Vg Source
write_data(0x19); //
write_code(0xB4); //PTL Saving Mode Set
write_data(0x18); //Power Normal Mode
//-----------------------------------------------------------------------------------//
//----------------------------Command Table 1----------------------------------------//
//-----------------------------------------------------------------------------------//
// write_code(0x00,0x38); //Idle Mode Off
write_code(0x25);
// write_data(0x00); //Contrast Difference Set
write_data(0x35); //
// write_code(0x00,0x13); //Partial Mode Off
// write_code(0x00,0x34); //TE Off
// write_code(0x00,0x33); //Scroll Area Set
// write_data(0x00,0x00); //Top Address
// write_data(0x00,0x84); //Height Address
// write_data(0x00,0x00); //Botton Address
// write_code(0x00,0x37); //Scroll Start Address Set
// write_data(0x00,0x00); //
write_code(0x3A); //Pixel Format Set
write_data(0x05); //
write_code(0x36); //Memory Access Control
write_data(0x08); //
write_code(0x29); //Display On
//-----------------------------------------------------------------------------------//
//------------------------Command Table 2 [XXXX/XXXX/GAMM]---------------------------//
//-----------------------------------------------------------------------------------//
write_code(0xB0); //Duty Set
write_data(0x83); //
write_code(0xB1); //First COM Set
write_data(0x00); //
write_code(0xB3); //OSC Div. Set
write_data(0x00); //
write_code(0xC0); //V0 Voltage Set
write_data(0x33); //
write_data(0x01); //
write_code(0xC6); //V0 Bias Set
write_data(0x00); //
write_code(0xB7); //Glass Direction
write_data(0xC0); //
//------------------------------Gamma Table Set--------------------------------------//
write_code(0xF9); //Gamma
write_data(0x00); //
write_data(0x03); //
write_data(0x05); //
write_data(0x07); //
write_data(0x09); //
write_data(0x0B); //
write_data(0x0D); //
write_data(0x0F); //
write_data(0x11); //
write_data(0x13); //
write_data(0x15); //
write_data(0x17); //
write_data(0x19); //
write_data(0x1B); //
write_data(0x1D); //
write_data(0x1F);
}
void fill_color(uchar X1, uchar Y1, uchar X2, uchar Y2)
{
unsigned int i=0;
write_code(0x2A);
write_data(X1);
write_data(X2);
write_code(0x2B);
write_data(Y1);
write_data(Y2);
write_code(0x2D);
for(i=1000;i>0;i--)
{
// write_data(0x00);
// write_data(0x00);
write_data(0x00);
write_data(0x1f);
}
}
void main(void)
{
delay(4); //启动等待,等LCM讲入工作状态
Rst_bit ();
delay(4); //启动等待,等LCM讲入工作状态
Initial();
fill_color(0x30,0x30,0x70,0x70);
while(1)
{
}
}
|
|