Home Article tft144屏幕51驱动代码

tft144屏幕51驱动代码

Release time:2021-03-22 23:52:47 Author:一蓑烟雨 Reading volume:241
tft144工程文件
//********************************************************************************
#include "reg52.h"
#include <intrins.h>


#define uchar unsigned char
#define uint unsigned int

#include "delay.h"

#include "tft128128spi.h"



//---------------------------液晶屏接线说明-------------------------------------//
//接线前请参考液晶屏说明书第10页引脚定义
sbit scl       =P2^7;//接模块CLK引脚,接裸屏Pin9_SCL
sbit sda       =P2^6;//接模块DIN/MOSI引脚,接裸屏Pin8_SDA
sbit reset     =P2^5;//接模块dcT引脚,接裸屏Pin6_RES
sbit dc        =P2^4;//接模块D/C引脚,接裸屏Pin7_A0
sbit cs        =P2^3;//接模块CE引脚,接裸屏Pin12_CS
sbit bl        =P2^2;//接模块BL引脚,背光可以采用IO控制或者PWM控制,也可以直接接到高电平常亮
//---------------------------End of液晶屏接线---------------------------------//



bit USE_LANDSCAPE;//程序横竖屏切换


//向液晶屏写一个8位指令
void  LCD_WrCmd(uchar cmd)
{
 uchar i;
 cs=0;dc=0;
 for(i=0;i<8;i++)
 {
  scl=0;
  if(cmd&0x80)sda=1;else sda=0;
  scl=1;
  cmd<<=1;
 }	
 cs=1;
}

//向液晶屏写一个8位数据
void  LCD_WrDat(uchar dat)
{
 uchar i;
 cs=0;dc=1;
 for(i=0;i<8;i++)
 {
  scl=0;
  if(dat&0x80)sda=1;else sda=0;
  scl=1;
  dat<<=1;
 }	
 cs=1;
}
//向液晶屏写一个16位数据
void  LCD_WrDat_16Bit(uint dat)
{
 LCD_WrDat(dat>>8);			 //写入高8位数据
 LCD_WrDat(dat);			 //写入低8位数据
 
}

void Reset()
{
    reset=0;
    delayms(100);
    reset=1;
    delayms(100);
}
//////////////////////////////////////////////////////////////////////////////////////////////
//液晶屏初始化 for S6D02A1
void lcd_initial()
{	Reset();//Reset before LCD Init.
		
	//LCD Init For 1.44Inch LCD Panel with ST7735R.
	LCD_WrCmd(0x11);//Sleep exit 
	delayms (120);
		
	//ST7735R Frame Rate
	LCD_WrCmd(0xB1); 
	LCD_WrDat(0x01); 
	LCD_WrDat(0x2C); 
	LCD_WrDat(0x2D); 

	LCD_WrCmd(0xB2); 
	LCD_WrDat(0x01); 
	LCD_WrDat(0x2C); 
	LCD_WrDat(0x2D); 

	LCD_WrCmd(0xB3); 
	LCD_WrDat(0x01); 
	LCD_WrDat(0x2C); 
	LCD_WrDat(0x2D); 
	LCD_WrDat(0x01); 
	LCD_WrDat(0x2C); 
	LCD_WrDat(0x2D); 
	
	LCD_WrCmd(0xB4); //Column invedcion 
	LCD_WrDat(0x07); 
	
	//ST7735R Power Sequence
	LCD_WrCmd(0xC0); 
	LCD_WrDat(0xA2); 
	LCD_WrDat(0x02); 
	LCD_WrDat(0x84); 
	LCD_WrCmd(0xC1); 
	LCD_WrDat(0xC5); 

	LCD_WrCmd(0xC2); 
	LCD_WrDat(0x0A); 
	LCD_WrDat(0x00); 

	LCD_WrCmd(0xC3); 
	LCD_WrDat(0x8A); 
	LCD_WrDat(0x2A); 
	LCD_WrCmd(0xC4); 
	LCD_WrDat(0x8A); 
	LCD_WrDat(0xEE); 
	
	LCD_WrCmd(0xC5); //VCOM 
	LCD_WrDat(0x0E); 
	
	LCD_WrCmd(0x36); //MX, MY, RGB mode 
if(USE_LANDSCAPE)
	LCD_WrDat(0xA8); //竖屏C8 横屏08 A8
else
	LCD_WrDat(0xC8); //竖屏C8 横屏08 A8
	
	//ST7735R Gamma Sequence
	LCD_WrCmd(0xe0); 
	LCD_WrDat(0x0f); 
	LCD_WrDat(0x1a); 
	LCD_WrDat(0x0f); 
	LCD_WrDat(0x18); 
	LCD_WrDat(0x2f); 
	LCD_WrDat(0x28); 
	LCD_WrDat(0x20); 
	LCD_WrDat(0x22); 
	LCD_WrDat(0x1f); 
	LCD_WrDat(0x1b); 
	LCD_WrDat(0x23); 
	LCD_WrDat(0x37); 
	LCD_WrDat(0x00); 	
	LCD_WrDat(0x07); 
	LCD_WrDat(0x02); 
	LCD_WrDat(0x10); 

	LCD_WrCmd(0xe1); 
	LCD_WrDat(0x0f); 
	LCD_WrDat(0x1b); 
	LCD_WrDat(0x0f); 
	LCD_WrDat(0x17); 
	LCD_WrDat(0x33); 
	LCD_WrDat(0x2c); 
	LCD_WrDat(0x29); 
	LCD_WrDat(0x2e); 
	LCD_WrDat(0x30); 
	LCD_WrDat(0x30); 
	LCD_WrDat(0x39); 
	LCD_WrDat(0x3f); 
	LCD_WrDat(0x00); 
	LCD_WrDat(0x07); 
	LCD_WrDat(0x03); 
	LCD_WrDat(0x10);  
	
	LCD_WrCmd(0x2a);
	LCD_WrDat(0x00);
	LCD_WrDat(0x00+2);
	LCD_WrDat(0x00);
	LCD_WrDat(0x80+2);

	LCD_WrCmd(0x2b);
	LCD_WrDat(0x00);
	LCD_WrDat(0x00+3);
	LCD_WrDat(0x00);
	LCD_WrDat(0x80+3);
	
	LCD_WrCmd(0xF0); //Enable test command  
	LCD_WrDat(0x01); 
	LCD_WrCmd(0xF6); //Disable ram power save mode 
	LCD_WrDat(0x00); 
	
	LCD_WrCmd(0x3A); //65k mode 
	LCD_WrDat(0x05); 
	
	
	LCD_WrCmd(0x29);//Display on


	bl=1;			 //背光

}



/*************************************************
函数名:LCD_Set_Region
功能:设置lcd显示区域,在此区域写点数据自动换行
入口参数:xy起点和终点
返回值:无
*************************************************/
void Lcd_SetRegion(uint x_start,uint y_start,uint x_end,uint y_end)reentrant
{	
if(USE_LANDSCAPE)//使用横屏模式
   {
    LCD_WrCmd(0x2a);
	LCD_WrDat(0x00);
	LCD_WrDat(x_start+3);
	LCD_WrDat(0x00);
	LCD_WrDat(x_end+3);

	LCD_WrCmd(0x2b);
	LCD_WrDat(0x00);
	LCD_WrDat(y_start+2);
	LCD_WrDat(0x00);
	LCD_WrDat(y_end+2);
   }
else//竖屏模式	
  {
	LCD_WrCmd(0x2a);
	LCD_WrDat(0x00);
	LCD_WrDat(x_start+2);
	LCD_WrDat(0x00);
	LCD_WrDat(x_end+2);

	LCD_WrCmd(0x2b);
	LCD_WrDat(0x00);
	LCD_WrDat(y_start+3);
	LCD_WrDat(0x00);
	LCD_WrDat(y_end+3);	
  }
	LCD_WrCmd(0x2c);
}




void LCD_Clear(int color)
{
 	uchar i,j;
	Lcd_SetRegion(0,0,128-1,128-1);
 	for (i=0;i<128;i++)
    	for (j=0;j<128;j++)
        	LCD_WrDat_16Bit(color);
}



void LCD_A_Char8X16(uint x, uint y, uint fc, uint bc, uchar *s)reentrant
{
 uchar i,j,temp;
 Lcd_SetRegion(x,y,x+8-1,y+16-1);
 for(i=0;i<16;i++)
	{
	 temp=s[i];
	 for(j=0;j<8;j++)
	   {
	    if(temp&0x80)LCD_WrDat_16Bit(fc);
		else if	(fc!=bc) LCD_WrDat_16Bit(bc);
	    temp<<=1;
	   }  
	}

}

//void LCD_Char8X16_String(uint x,uint y,uint fc,uint bc,uchar *s,uchar c)reentrant
//{
// uchar i;
// for(i=0;i<c;i++) LCD_A_Char8X16(x+i*8,y,fc,bc,s+i*16);
//}



void LCD_CHN16X16(uint x, uint y, uint fc, uint bc, uchar *s) //显示一个汉字
{
 uchar i,j,temp;
 Lcd_SetRegion(x,y,x+16-1,y+16-1);
 for(i=0;i<32;i++)
	{
	 temp=s[i];
	 for(j=0;j<8;j++)
	   {
	    if(temp&0x80)LCD_WrDat_16Bit(fc);
		else if	(fc!=bc) LCD_WrDat_16Bit(bc);
	    temp<<=1;
	   }  
	}
}

void LCD_CHN16X16_String(uint x,uint y,uint fc,uint bc,uchar *s,uchar c)
{
 uchar i;
 for(i=0;i<c;i++)LCD_CHN16X16(x+i*16,y,fc,bc,s+i*32);
}
 
//void LCD_A_Char16X32(uint x, uint y, uint fc, uint bc, uchar *s)
//{
// uchar i,j,temp;
// Lcd_SetRegion(x,y,x+16-1,y+32-1);
// for(i=0;i<64;i++)						  //16*32西文字符点阵64个8位字节
//	{
//	 temp=s[i];
//	 for(j=0;j<8;j++)
//	   {
//	    if(temp&0x80)LCD_WrDat_16Bit(fc);
//		else if	(fc!=bc) LCD_WrDat_16Bit(bc);
//	    temp<<=1;
//	   }  
//	}
//
//}


/*
 void LCD_A_Char24X48(uint x, uint y, uint fc, uint bc, uchar *s)
{
 uchar i,j,temp;
 Lcd_SetRegion(x,y,x+24-1,y+48-1);
 for(i=0;i<144;i++)						  //24*48西文字符点阵144个8位字节
	{
	 temp=s[i];
	 for(j=0;j<8;j++)
	   {
	    if(temp&0x80)LCD_WrDat_16Bit(fc);
		else if	(fc!=bc) LCD_WrDat_16Bit(bc);
	    temp<<=1;
	   }  
	}

}





void LCD_CHN32X32(uint x, uint y, uint fc, uint bc, uchar *s) //显示一个32*32汉字
{
 uchar i,j,temp;
 Lcd_SetRegion(x,y,x+32-1,y+32-1);
 for(i=0;i<128;i++)											 //32*32汉字128字节
	{
	 temp=s[i];
	 for(j=0;j<8;j++)
	   {
	    if(temp&0x80)LCD_WrDat_16Bit(fc);
		else if	(fc!=bc) LCD_WrDat_16Bit(bc);
	    temp<<=1;
	   }  
	}
}

void LCD_CHN32X32_String(uint x,uint y,uint fc,uint bc,uchar *s,uchar c)//显示一串32*32汉字
{
 uchar i;
 for(i=0;i<c;i++)LCD_CHN32X32(x+i*32,y,fc,bc,s+i*128);
}

*/
  
I want to comment

Search

classification

Leave a message
http://blog.rjxj513.com/
User login
You have not written any reviews yet!
You have commented!
Can only praise once!
You have a collection!