www.pudn.com > RC522.zip > lcd.c, change:2015-04-14,size:44098b


#include "lcd.h" 
#include "stdlib.h" 
#include "font.h"  
#include "usart.h" 
#include "remote.h" 
#include "delay.h"	  
//////////////////////////////////////////////////////////////////////////////////	  
//本程序只供学习使用,未经作者许可,不得用于其它任何用途 
//Mini STM32开发板 
//2.4/2.8寸TFT液晶驱动	   
//支持驱动IC型号包括:ILI9341/ILI9325/RM68021/ILI9320/ILI9328/LGDP4531/LGDP4535/SPFD5408/SSD1289/1505/B505/C505等 
//正点原子@ALIENTEK 
//技术论坛:www.openedv.com 
//创建日期:2011/1/13 
//版本:V1.7 
//版权所有,盗版必究。 
//Copyright(C) 正点原子 2009-2019 
//All rights reserved 
//******************************************************************************** 
//V1.2修改说明 
//支持了SPFD5408的驱动,另外把液晶ID直接打印成HEX格式.方便查看LCD驱动IC. 
//V1.3 
//加入了快速IO的支持 
//修改了背光控制的极性(适用于V1.8及以后的开发板版本) 
//对于1.8版本之前(不包括1.8)的液晶模块,请修改LCD_Init函数的LCD_LED=1;为LCD_LED=1; 
//V1.4 
//修改了LCD_ShowChar函数,使用画点功能画字符。 
//加入了横竖屏显示的支持 
//V1.5 20110730 
//1,修改了B505液晶读颜色有误的bug. 
//2,修改了快速IO及横竖屏的设置方式. 
//V1.6 20111116 
//1,加入对LGDP4535液晶的驱动支持 
//V1.7 20120713 
//1,增加LCD_RD_DATA函数 
//2,增加对ILI9341的支持 
//3,增加ILI9325的独立驱动代码 
//4,增加LCD_Scan_Dir函数(慎重使用)	   
//6,另外修改了部分原来的函数,以适应9341的操作 
////////////////////////////////////////////////////////////////////////////////// 
	    
					  
//画笔颜色,背景颜色 
u16 POINT_COLOR = 0x0000,BACK_COLOR = 0xFFFF;   
u16 DeviceCode;	  
 
#if LCD_FAST_IO==1 //快速IO 
//写寄存器函数 
void LCD_WR_REG(u8 data) 
{  
	LCD_RS_CLR;//写地址   
 	LCD_CS_CLR;  
	DATAOUT(data);  
	LCD_WR_CLR;  
	LCD_WR_SET;  
 	LCD_CS_SET;    
} 
#else//正常IO 
//写寄存器函数 
void LCD_WR_REG(u8 data) 
{  
	LCD_RS=0;//写地址   
 	LCD_CS=0;  
	DATAOUT(data);  
	LCD_WR=0;  
	LCD_WR=1;  
 	LCD_CS=1;    
} 	 
#endif	    
//读LCD数据 
//返回值:读到的值 
u16 LCD_RD_DATA(void) 
{										    
	u16 t; 
 	GPIOB->CRL=0X88888888; //PB0-7  上拉输入 
	GPIOB->CRH=0X88888888; //PB8-15 上拉输入 
	GPIOB->ODR=0X0000;     //全部输出0 
#if LCD_FAST_IO==1 //快速IO 
	LCD_RS_SET; 
	LCD_CS_CLR; 
	//读取数据(读寄存器时,并不需要读2次) 
	LCD_RD_CLR; 
	if(DeviceCode==0X8989)delay_us(2);//FOR 8989,延时2us					    
	LCD_RD_SET; 
	t=DATAIN;   
	LCD_CS_SET;  
#else 
	LCD_RS=1; 
	LCD_CS=0; 
	//读取数据(读寄存器时,并不需要读2次) 
	LCD_RD=0;					    
	LCD_RD=1; 
	t=DATAIN;   
	LCD_CS=1;  
#endif   
	GPIOB->CRL=0X33333333; //PB0-7  上拉输出 
	GPIOB->CRH=0X33333333; //PB8-15 上拉输出 
	GPIOB->ODR=0XFFFF;    //全部输出高 
	return t;   
}	 
 
//写寄存器 
//LCD_Reg:寄存器编号 
//LCD_RegValue:要写入的值 
void LCD_WriteReg(u8 LCD_Reg, u16 LCD_RegValue) 
{	 
	LCD_WR_REG(LCD_Reg);   
	LCD_WR_DATA(LCD_RegValue);	    		  
}	    
//读寄存器 
//LCD_Reg:寄存器编号 
//返回值:读到的值 
u16 LCD_ReadReg(u8 LCD_Reg) 
{										    
 	LCD_WR_REG(LCD_Reg);  //写入要读的寄存器号   
	return LCD_RD_DATA();  
}  	  
//开始写GRAM 
void LCD_WriteRAM_Prepare(void) 
{ 
	if(DeviceCode==0X9341)LCD_WR_REG(0x2C);//ILI9341是以0X2C开始的 
	else LCD_WR_REG(R34); 
}	  
//LCD写GRAM 
//RGB_Code:颜色值 
void LCD_WriteRAM(u16 RGB_Code) 
{							     
	LCD_WR_DATA(RGB_Code);//写十六位GRAM 
} 
//从ILI93xx读出的数据为GBR格式,而我们写入的时候为RGB格式。 
//通过该函数转换 
//c:GBR格式的颜色值 
//返回值:RGB格式的颜色值 
u16 LCD_BGR2RGB(u16 c) 
{ 
	u16  r,g,b,rgb;    
	b=(c>>0)&0x1f; 
	g=(c>>5)&0x3f; 
	r=(c>>11)&0x1f;	  
	rgb=(b<<11)+(g<<5)+(r<<0);		  
	return(rgb); 
} 
		  
//读取个某点的颜色值	  
//x:0~239 
//y:0~319 
//返回值:此点的颜色 
u16 LCD_ReadPoint(u16 x,u16 y) 
{ 
 	u16 r,g,b; 
	if(x>=LCD_W||y>=LCD_H)return 0;			//超过了范围,直接返回		    
	LCD_SetCursor(x,y); 
	if(DeviceCode==0X9341)LCD_WR_REG(0X2E);	//ILI9341发送读GRAM指令 
	else LCD_WR_REG(R34);      		 		//其他IC发送读GRAM指令 
	GPIOB->CRL=0X88888888; //PB0-7  上拉输入 
	GPIOB->CRH=0X88888888; //PB8-15 上拉输入 
	GPIOB->ODR=0XFFFF;     //全部输出高 
#if LCD_FAST_IO==1 //快速IO 
	LCD_RS_SET; 
	LCD_CS_CLR; 
	//读取数据(读GRAM时,第一次为假读)	 
	LCD_RD_CLR;	 
  	LCD_RD_SET; 
 	//dummy READ 
	LCD_RD_CLR;					    
	if(DeviceCode==0X8989)delay_us(2);//FOR 8989,延时2us					    
	LCD_RD_SET; 
 	r=DATAIN;   
 	if(DeviceCode==0X9341) 
	{	  
		LCD_RD_CLR;					    
	 	LCD_RD_SET; 
		b=DATAIN;//读取蓝色值  	   
		g=r&0XFF;//对于9341,第一次读取的是RG的值,R在前,G在后,各占8位 
		g<<=8; 
	}	  
	LCD_CS_SET; 
#else 
	LCD_RS=1; 
	LCD_CS=0; 
	//读取数据(读GRAM时,需要读2次) 
	LCD_RD=0;					    
 	LCD_RD=1; 
 	//dummy READ 
	LCD_RD=0;					    
 	LCD_RD=1; 
	r=DATAIN;   
 	if(DeviceCode==0X9341) 
	{	  
		LCD_RD=0;					    
	 	LCD_RD=1; 
		b=DATAIN;//读取蓝色值  	   
		g=r&0XFF;//对于9341,第一次读取的是RG的值,R在前,G在后,各占8位 
		g<<=8; 
	}	 
	LCD_CS=1; 
#endif  
	GPIOB->CRL=0X33333333; //PB0-7  上拉输出 
	GPIOB->CRH=0X33333333; //PB8-15 上拉输出 
	GPIOB->ODR=0XFFFF;    //全部输出高   
	if(DeviceCode==0X4535||DeviceCode==0X4531||DeviceCode==0X8989||DeviceCode==0XB505)return r;	//这几种IC直接返回颜色值 
	else if(DeviceCode==0X9341)return (((r>>11)<<11)|((g>>10)<<5)|(b>>11));						//ILI9341需要公式转换一下 
	else return LCD_BGR2RGB(r);																	//其他IC 
} 
//LCD开启显示 
void LCD_DisplayOn(void) 
{	 
	if(DeviceCode==0X9341)LCD_WR_REG(0X29);	//开启显示 
	else LCD_WriteReg(R7,0x0173); 			//开启显示 
}	  
//LCD关闭显示 
void LCD_DisplayOff(void) 
{	    
	if(DeviceCode==0X9341)LCD_WR_REG(0X28);	//关闭显示 
	else LCD_WriteReg(R7, 0x0);//关闭显示  
}    
//设置光标位置 
//Xpos:横坐标 
//Ypos:纵坐标 
__inline void LCD_SetCursor(u16 Xpos, u16 Ypos) 
{ 
#if USE_HORIZONTAL==1  
	if(DeviceCode==0X8989) 
	{ 
		Xpos=319-Xpos; 
		LCD_WriteReg(0X4E, Ypos); 
		LCD_WriteReg(0X4F, Xpos); 
    }else if(DeviceCode==0X9341)//9341,设置坐标 
	{			  
		LCD_WR_REG(0x2B);  
		LCD_WR_DATA(Ypos>>8);  
		LCD_WR_DATA(Ypos&0XFF);			  
		LCD_WR_REG(0x2A);  
		LCD_WR_DATA(Xpos>>8);  
		LCD_WR_DATA(Xpos&0XFF); 
	}else 
	{ 
		Xpos=319-Xpos; 
		LCD_WriteReg(R32,Ypos); 
		LCD_WriteReg(R33,Xpos); 
	}							    
#else 
	if(DeviceCode==0X8989) 
	{ 
		LCD_WriteReg(0X4E, Xpos); 
		LCD_WriteReg(0X4F, Ypos); 
    }else if(DeviceCode==0X9341) 
	{		     
		LCD_WR_REG(0x2A);  
		LCD_WR_DATA(Xpos>>8);  
		LCD_WR_DATA(Xpos&0XFF);	  
		LCD_WR_REG(0x2B);  
		LCD_WR_DATA(Ypos>>8);  
		LCD_WR_DATA(Ypos&0XFF); 
	}else 
	{ 
		LCD_WriteReg(R32, Xpos); 
		LCD_WriteReg(R33, Ypos); 
	}						     
#endif 
} 
 
//设置LCD的自动扫描方向 
//注意:其他函数可能会受到此函数设置的影响(尤其是9341这个奇葩),所以, 
//一般设置为L2R_U2D即可,如果设置为其他扫描方式,可能导致显示不正常. 
//0~7:代表8个方向(具体定义见lcd.h) 
//9320/9325/9328/4531/4535/1505/b505/8989/5408/9341等IC已经实际测试	    
void LCD_Scan_Dir(u8 dir) 
{ 
	u16 regval=0; 
	u8 dirreg=0; 
#if USE_HORIZONTAL//使用横屏 
	switch(dir)//方向转换 
	{ 
		case 0:dir=6;break; 
		case 1:dir=7;break; 
		case 2:dir=4;break; 
		case 3:dir=5;break; 
		case 4:dir=1;break; 
		case 5:dir=0;break; 
		case 6:dir=3;break; 
		case 7:dir=2;break;	      
	} 
#endif 
	if(DeviceCode==0x9341)//9341,很特殊 
	{ 
		switch(dir) 
		{ 
			case L2R_U2D://从左到右,从上到下 
				regval|=(0<<7)|(0<<6)|(0<<5);  
				break; 
			case L2R_D2U://从左到右,从下到上 
				regval|=(1<<7)|(0<<6)|(0<<5);  
				break; 
			case R2L_U2D://从右到左,从上到下 
				regval|=(0<<7)|(1<<6)|(0<<5);  
				break; 
			case R2L_D2U://从右到左,从下到上 
				regval|=(1<<7)|(1<<6)|(0<<5);  
				break;	  
			case U2D_L2R://从上到下,从左到右 
				regval|=(0<<7)|(0<<6)|(1<<5);  
				break; 
			case U2D_R2L://从上到下,从右到左 
				regval|=(0<<7)|(1<<6)|(1<<5);  
				break; 
			case D2U_L2R://从下到上,从左到右 
				regval|=(1<<7)|(0<<6)|(1<<5);  
				break; 
			case D2U_R2L://从下到上,从右到左 
				regval|=(1<<7)|(1<<6)|(1<<5);  
				break;	  
		} 
		dirreg=0X36; 
 		regval|=0X08;//BGR    
		LCD_WriteReg(dirreg,regval); 
		if(regval&0X20) 
		{ 
 	 		LCD_WR_REG(0x2A);  
			LCD_WR_DATA(0);LCD_WR_DATA(0); 
			LCD_WR_DATA(319>>8);LCD_WR_DATA(319&0XFF); 
	 		LCD_WR_REG(0x2B);  
			LCD_WR_DATA(0);LCD_WR_DATA(0); 
			LCD_WR_DATA(239>>8);LCD_WR_DATA(239&0XFF); 
		}else  
		{ 
 	 		LCD_WR_REG(0x2A);  
			LCD_WR_DATA(0);LCD_WR_DATA(0); 
			LCD_WR_DATA(239>>8);LCD_WR_DATA(239&0XFF); 
	 		LCD_WR_REG(0x2B);  
			LCD_WR_DATA(0);LCD_WR_DATA(0); 
			LCD_WR_DATA(319>>8);LCD_WR_DATA(319&0XFF); 
		}   
 	}else  
	{ 
		switch(dir) 
		{ 
			case L2R_U2D://从左到右,从上到下 
				regval|=(1<<5)|(1<<4)|(0<<3);  
				break; 
			case L2R_D2U://从左到右,从下到上 
				regval|=(0<<5)|(1<<4)|(0<<3);  
				break; 
			case R2L_U2D://从右到左,从上到下 
				regval|=(1<<5)|(0<<4)|(0<<3); 
				break; 
			case R2L_D2U://从右到左,从下到上 
				regval|=(0<<5)|(0<<4)|(0<<3);  
				break;	  
			case U2D_L2R://从上到下,从左到右 
				regval|=(1<<5)|(1<<4)|(1<<3);  
				break; 
			case U2D_R2L://从上到下,从右到左 
				regval|=(1<<5)|(0<<4)|(1<<3);  
				break; 
			case D2U_L2R://从下到上,从左到右 
				regval|=(0<<5)|(1<<4)|(1<<3);  
				break; 
			case D2U_R2L://从下到上,从右到左 
				regval|=(0<<5)|(0<<4)|(1<<3);  
				break;	  
		} 
		if(DeviceCode==0x8989)//8989 IC 
		{ 
			dirreg=0X11; 
			regval|=0X6040;	//65K    
	 	}else//其他驱动IC		   
		{ 
			dirreg=0X03; 
			regval|=1<<12;   
		} 
		LCD_WriteReg(dirreg,regval); 
	} 
}  
//画点 
//x:0~239 
//y:0~319 
//POINT_COLOR:此点的颜色 
void LCD_DrawPoint(u16 x,u16 y) 
{ 
	LCD_SetCursor(x,y);//设置光标位置  
	LCD_WriteRAM_Prepare();	//开始写入GRAM 
	LCD_WR_DATA(POINT_COLOR);  
} 	  
//初始化lcd 
//该初始化函数可以初始化各种ILI93XX液晶,但是其他函数是基于ILI9320的!!! 
//在其他型号的驱动芯片上没有测试!  
void LCD_Init(void) 
{   
     										  
	GPIO_InitTypeDef GPIO_InitStructure; 
 
 	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO, ENABLE);  
	GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable , ENABLE); 
	 
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10|GPIO_Pin_9|GPIO_Pin_8|GPIO_Pin_7|GPIO_Pin_6;	   //GPIO_Pin_10 
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;  //推挽输出 
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 
	GPIO_Init(GPIOC, &GPIO_InitStructure); //GPIOC	 
    //GPIO_WriteBit(GPIOC,GPIO_Pin_10|GPIO_Pin_9|GPIO_Pin_8|GPIO_Pin_7|GPIO_Pin_6,Bit_SET); 
	GPIO_SetBits(GPIOC,GPIO_Pin_10|GPIO_Pin_9|GPIO_Pin_8|GPIO_Pin_7|GPIO_Pin_6); 
 
 
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;	//   
	GPIO_Init(GPIOB, &GPIO_InitStructure); //GPIOB 
	//GPIO_WriteBit(GPIOC,GPIO_Pin_All,Bit_SET);  
	GPIO_SetBits(GPIOB,GPIO_Pin_All); 
  
	delay_ms(50); // delay 50 ms  
	LCD_WriteReg(0x0000,0x0001); 
	delay_ms(50); // delay 50 ms  
	DeviceCode = LCD_ReadReg(0x0000);    
 	if(DeviceCode==0||DeviceCode==0XFFFF)//读到ID不正确 
	{	 
		//可能是9341,尝试9341的ID读取		 
		LCD_WR_REG(0XD3);				    
		LCD_RD_DATA(); 			//dummy read 	 
 		LCD_RD_DATA();   	    //读回0X00 
  		DeviceCode=LCD_RD_DATA()&0XBF;//这里读回0XD3,实际是0X93才对.强制去掉第6位   								    
 		DeviceCode<<=8; 
		DeviceCode|=LCD_RD_DATA();	      
	} 
	printf(" LCD ID:%x\r\n",DeviceCode); //打印LCD ID  
	if(DeviceCode==0X9341)	//9341初始化 
	{ 
		LCD_WR_REG(0xCF);   
		LCD_WR_DATA(0x00);  
		LCD_WR_DATA(0xC1);  
		LCD_WR_DATA(0X30);  
		LCD_WR_REG(0xED);   
		LCD_WR_DATA(0x64);  
		LCD_WR_DATA(0x03);  
		LCD_WR_DATA(0X12);  
		LCD_WR_DATA(0X81);  
		LCD_WR_REG(0xE8);   
		LCD_WR_DATA(0x85);  
		LCD_WR_DATA(0x10);  
		LCD_WR_DATA(0x7A);  
		LCD_WR_REG(0xCB);   
		LCD_WR_DATA(0x39);  
		LCD_WR_DATA(0x2C);  
		LCD_WR_DATA(0x00);  
		LCD_WR_DATA(0x34);  
		LCD_WR_DATA(0x02);  
		LCD_WR_REG(0xF7);   
		LCD_WR_DATA(0x20);  
		LCD_WR_REG(0xEA);   
		LCD_WR_DATA(0x00);  
		LCD_WR_DATA(0x00);  
		LCD_WR_REG(0xC0);    //Power control  
		LCD_WR_DATA(0x1B);   //VRH[5:0]  
		LCD_WR_REG(0xC1);    //Power control  
		LCD_WR_DATA(0x01);   //SAP[2:0];BT[3:0]  
		LCD_WR_REG(0xC5);    //VCM control  
		LCD_WR_DATA(0x30); 	 //3F 
		LCD_WR_DATA(0x30); 	 //3C 
		LCD_WR_REG(0xC7);    //VCM control2  
		LCD_WR_DATA(0XB7);  
		LCD_WR_REG(0x36);    // Memory Access Control  
		LCD_WR_DATA(0x48);  
		LCD_WR_REG(0x3A);    
		LCD_WR_DATA(0x55);  
		LCD_WR_REG(0xB1);    
		LCD_WR_DATA(0x00);    
		LCD_WR_DATA(0x1A);  
		LCD_WR_REG(0xB6);    // Display Function Control  
		LCD_WR_DATA(0x0A);  
		LCD_WR_DATA(0xA2);  
		LCD_WR_REG(0xF2);    // 3Gamma Function Disable  
		LCD_WR_DATA(0x00);  
		LCD_WR_REG(0x26);    //Gamma curve selected  
		LCD_WR_DATA(0x01);  
		LCD_WR_REG(0xE0);    //Set Gamma  
		LCD_WR_DATA(0x0F);  
		LCD_WR_DATA(0x2A);  
		LCD_WR_DATA(0x28);  
		LCD_WR_DATA(0x08);  
		LCD_WR_DATA(0x0E);  
		LCD_WR_DATA(0x08);  
		LCD_WR_DATA(0x54);  
		LCD_WR_DATA(0XA9);  
		LCD_WR_DATA(0x43);  
		LCD_WR_DATA(0x0A);  
		LCD_WR_DATA(0x0F);  
		LCD_WR_DATA(0x00);  
		LCD_WR_DATA(0x00);  
		LCD_WR_DATA(0x00);  
		LCD_WR_DATA(0x00); 		  
		LCD_WR_REG(0XE1);    //Set Gamma  
		LCD_WR_DATA(0x00);  
		LCD_WR_DATA(0x15);  
		LCD_WR_DATA(0x17);  
		LCD_WR_DATA(0x07);  
		LCD_WR_DATA(0x11);  
		LCD_WR_DATA(0x06);  
		LCD_WR_DATA(0x2B);  
		LCD_WR_DATA(0x56);  
		LCD_WR_DATA(0x3C);  
		LCD_WR_DATA(0x05);  
		LCD_WR_DATA(0x10);  
		LCD_WR_DATA(0x0F);  
		LCD_WR_DATA(0x3F);  
		LCD_WR_DATA(0x3F);  
		LCD_WR_DATA(0x0F);  
		LCD_WR_REG(0x2B);  
		LCD_WR_DATA(0x00); 
		LCD_WR_DATA(0x00); 
		LCD_WR_DATA(0x01);
		LCD_WR_DATA(0x3f); 
		LCD_WR_REG(0x2A);  
		LCD_WR_DATA(0x00); 
		LCD_WR_DATA(0x00); 
		LCD_WR_DATA(0x00);
		LCD_WR_DATA(0xef);	  
		LCD_WR_REG(0x11); //Exit Sleep 
		delay_ms(120); 
		LCD_WR_REG(0x29); //display on	 
	}else if(DeviceCode==0x9325) //9325初始化 
	{ 
		LCD_WriteReg(0x00E5,0x78F0);  
		LCD_WriteReg(0x0001,0x0100);  
		LCD_WriteReg(0x0002,0x0700);  
		LCD_WriteReg(0x0003,0x1030);  
		LCD_WriteReg(0x0004,0x0000);  
		LCD_WriteReg(0x0008,0x0202);   
		LCD_WriteReg(0x0009,0x0000); 
		LCD_WriteReg(0x000A,0x0000);  
		LCD_WriteReg(0x000C,0x0000);  
		LCD_WriteReg(0x000D,0x0000); 
		LCD_WriteReg(0x000F,0x0000); 
		//power on sequence VGHVGL 
		LCD_WriteReg(0x0010,0x0000);    
		LCD_WriteReg(0x0011,0x0007);   
		LCD_WriteReg(0x0012,0x0000);   
		LCD_WriteReg(0x0013,0x0000);  
		LCD_WriteReg(0x0007,0x0000);  
		//vgh  
		LCD_WriteReg(0x0010,0x1690);    
		LCD_WriteReg(0x0011,0x0227); 
		//delayms(100); 
		//vregiout  
		LCD_WriteReg(0x0012,0x009D); //0x001b 
		//delayms(100);  
		//vom amplitude 
		LCD_WriteReg(0x0013,0x1900); 
		//delayms(100);  
		//vom H 
		LCD_WriteReg(0x0029,0x0025);  
		LCD_WriteReg(0x002B,0x000D);  
		//gamma 
		LCD_WriteReg(0x0030,0x0007); 
		LCD_WriteReg(0x0031,0x0303); 
		LCD_WriteReg(0x0032,0x0003);// 0006 
		LCD_WriteReg(0x0035,0x0206); 
		LCD_WriteReg(0x0036,0x0008); 
		LCD_WriteReg(0x0037,0x0406);  
		LCD_WriteReg(0x0038,0x0304);//0200 
		LCD_WriteReg(0x0039,0x0007);  
		LCD_WriteReg(0x003C,0x0602);// 0504 
		LCD_WriteReg(0x003D,0x0008);  
		//ram 
		LCD_WriteReg(0x0050,0x0000);  
		LCD_WriteReg(0x0051,0x00EF); 
		LCD_WriteReg(0x0052,0x0000);  
		LCD_WriteReg(0x0053,0x013F);   
		LCD_WriteReg(0x0060,0xA700);  
		LCD_WriteReg(0x0061,0x0001);  
		LCD_WriteReg(0x006A,0x0000);  
		// 
		LCD_WriteReg(0x0080,0x0000);  
		LCD_WriteReg(0x0081,0x0000);  
		LCD_WriteReg(0x0082,0x0000);  
		LCD_WriteReg(0x0083,0x0000);  
		LCD_WriteReg(0x0084,0x0000);  
		LCD_WriteReg(0x0085,0x0000);  
		// 
		LCD_WriteReg(0x0090,0x0010);  
		LCD_WriteReg(0x0092,0x0600);  
		 
		LCD_WriteReg(0x0007,0x0133); 
		LCD_WriteReg(0x00,0x0022);//	 
	}else if(DeviceCode==0x9328)//ILI9328 
	{ 
  		LCD_WriteReg(0x00e7,0x0010);       
        LCD_WriteReg(0x0000,0x0001);//开启内部时钟 
        LCD_WriteReg(0x0001,0x0100);      
        LCD_WriteReg(0x0002,0x0700);//电源开启                     
		//LCD_WriteReg(0x0003,(1<<3)|(1<<4) ); 	//65K  RGB 
		//DRIVE TABLE(寄存器 03H) 
		//BIT3=AM BIT4:5=ID0:1 
		//AM ID0 ID1   FUNCATION 
		// 0  0   0	   R->L D->U 
		// 1  0   0	   D->U	R->L 
		// 0  1   0	   L->R D->U 
		// 1  1   0    D->U	L->R 
		// 0  0   1	   R->L U->D 
		// 1  0   1    U->D	R->L 
		// 0  1   1    L->R U->D 正常就用这个. 
		// 1  1   1	   U->D	L->R 
        LCD_WriteReg(0x0003,(1<<12)|(3<<4)|(0<<3) );//65K     
        LCD_WriteReg(0x0004,0x0000);                                    
        LCD_WriteReg(0x0008,0x0207);	            
        LCD_WriteReg(0x0009,0x0000);          
        LCD_WriteReg(0x000a,0x0000);//display setting          
        LCD_WriteReg(0x000c,0x0001);//display setting           
        LCD_WriteReg(0x000d,0x0000);//0f3c           
        LCD_WriteReg(0x000f,0x0000); 
		//电源配置 
        LCD_WriteReg(0x0010,0x0000);    
        LCD_WriteReg(0x0011,0x0007); 
        LCD_WriteReg(0x0012,0x0000);                                                                  
        LCD_WriteReg(0x0013,0x0000);                  
        delay_ms(50);  
        LCD_WriteReg(0x0010,0x1590);    
        LCD_WriteReg(0x0011,0x0227); 
        delay_ms(50);  
        LCD_WriteReg(0x0012,0x009c);                   
        delay_ms(50);  
        LCD_WriteReg(0x0013,0x1900);    
        LCD_WriteReg(0x0029,0x0023); 
        LCD_WriteReg(0x002b,0x000e); 
        delay_ms(50);  
        LCD_WriteReg(0x0020,0x0000);                                                             
        LCD_WriteReg(0x0021,0x013f);            
		delay_ms(50);  
		//伽马校正 
        LCD_WriteReg(0x0030,0x0007);  
        LCD_WriteReg(0x0031,0x0707);    
        LCD_WriteReg(0x0032,0x0006); 
        LCD_WriteReg(0x0035,0x0704); 
        LCD_WriteReg(0x0036,0x1f04);  
        LCD_WriteReg(0x0037,0x0004); 
        LCD_WriteReg(0x0038,0x0000);         
        LCD_WriteReg(0x0039,0x0706);      
        LCD_WriteReg(0x003c,0x0701); 
        LCD_WriteReg(0x003d,0x000f); 
        delay_ms(50);  
        LCD_WriteReg(0x0050,0x0000); //水平GRAM起始位置  
        LCD_WriteReg(0x0051,0x00ef); //水平GRAM终止位置                     
        LCD_WriteReg(0x0052,0x0000); //垂直GRAM起始位置                     
        LCD_WriteReg(0x0053,0x013f); //垂直GRAM终止位置   
         
        LCD_WriteReg(0x0060,0xa700);         
        LCD_WriteReg(0x0061,0x0001);  
        LCD_WriteReg(0x006a,0x0000); 
        LCD_WriteReg(0x0080,0x0000); 
        LCD_WriteReg(0x0081,0x0000); 
        LCD_WriteReg(0x0082,0x0000); 
        LCD_WriteReg(0x0083,0x0000); 
        LCD_WriteReg(0x0084,0x0000); 
        LCD_WriteReg(0x0085,0x0000); 
       
        LCD_WriteReg(0x0090,0x0010);      
        LCD_WriteReg(0x0092,0x0000);   
        LCD_WriteReg(0x0093,0x0003); 
        LCD_WriteReg(0x0095,0x0110); 
        LCD_WriteReg(0x0097,0x0000);         
        LCD_WriteReg(0x0098,0x0000);   
        //开启显示设置     
        LCD_WriteReg(0x0007,0x0133);    
        LCD_WriteReg(0x0020,0x0000);                                                             
        LCD_WriteReg(0x0021,0x013f); 
	}else if(DeviceCode==0x9320||DeviceCode==0x9300) 
	{ 
		LCD_WriteReg(0x00,0x0000); 
		LCD_WriteReg(0x01,0x0100);	//Driver Output Contral. 
		LCD_WriteReg(0x02,0x0700);	//LCD Driver Waveform Contral. 
		LCD_WriteReg(0x03,0x1030);//Entry Mode Set. 
		//LCD_WriteReg(0x03,0x1018);	//Entry Mode Set. 
	 
		LCD_WriteReg(0x04,0x0000);	//Scalling Contral. 
		LCD_WriteReg(0x08,0x0202);	//Display Contral 2.(0x0207) 
		LCD_WriteReg(0x09,0x0000);	//Display Contral 3.(0x0000) 
		LCD_WriteReg(0x0a,0x0000);	//Frame Cycle Contal.(0x0000) 
		LCD_WriteReg(0x0c,(1<<0));	//Extern Display Interface Contral 1.(0x0000) 
		LCD_WriteReg(0x0d,0x0000);	//Frame Maker Position. 
		LCD_WriteReg(0x0f,0x0000);	//Extern Display Interface Contral 2.	     
		delay_ms(50);  
		LCD_WriteReg(0x07,0x0101);	//Display Contral. 
		delay_ms(50); 								   
		LCD_WriteReg(0x10,(1<<12)|(0<<8)|(1<<7)|(1<<6)|(0<<4));	//Power Control 1.(0x16b0) 
		LCD_WriteReg(0x11,0x0007);								//Power Control 2.(0x0001) 
		LCD_WriteReg(0x12,(1<<8)|(1<<4)|(0<<0));				//Power Control 3.(0x0138) 
		LCD_WriteReg(0x13,0x0b00);								//Power Control 4. 
		LCD_WriteReg(0x29,0x0000);								//Power Control 7. 
	 
		LCD_WriteReg(0x2b,(1<<14)|(1<<4));	     
		LCD_WriteReg(0x50,0);	//Set X Star 
		//水平GRAM终止位置Set X End. 
		LCD_WriteReg(0x51,239);	//Set Y Star 
		LCD_WriteReg(0x52,0);	//Set Y End.t. 
		LCD_WriteReg(0x53,319);	// 
	 
		LCD_WriteReg(0x60,0x2700);	//Driver Output Control. 
		LCD_WriteReg(0x61,0x0001);	//Driver Output Control. 
		LCD_WriteReg(0x6a,0x0000);	//Vertical Srcoll Control. 
	 
		LCD_WriteReg(0x80,0x0000);	//Display Position? Partial Display 1. 
		LCD_WriteReg(0x81,0x0000);	//RAM Address Start? Partial Display 1. 
		LCD_WriteReg(0x82,0x0000);	//RAM Address End-Partial Display 1. 
		LCD_WriteReg(0x83,0x0000);	//Displsy Position? Partial Display 2. 
		LCD_WriteReg(0x84,0x0000);	//RAM Address Start? Partial Display 2. 
		LCD_WriteReg(0x85,0x0000);	//RAM Address End? Partial Display 2. 
	 
		LCD_WriteReg(0x90,(0<<7)|(16<<0));	//Frame Cycle Contral.(0x0013) 
		LCD_WriteReg(0x92,0x0000);	//Panel Interface Contral 2.(0x0000) 
		LCD_WriteReg(0x93,0x0001);	//Panel Interface Contral 3. 
		LCD_WriteReg(0x95,0x0110);	//Frame Cycle Contral.(0x0110) 
		LCD_WriteReg(0x97,(0<<8));	// 
		LCD_WriteReg(0x98,0x0000);	//Frame Cycle Contral.	    
		LCD_WriteReg(0x07,0x0173);	//(0x0173) 
	}else if(DeviceCode==0x5408) 
	{ 
		LCD_WriteReg(0x01,0x0100);								   
		LCD_WriteReg(0x02,0x0700);//LCD Driving Waveform Contral  
		LCD_WriteReg(0x03,0x1030);//Entry Mode设置 	    
		//指针从左至右自上而下的自动增模式 
		//Normal Mode(Window Mode disable) 
		//RGB格式 
		//16位数据2次传输的8总线设置 
		LCD_WriteReg(0x04,0x0000); //Scalling Control register      
		LCD_WriteReg(0x08,0x0207); //Display Control 2  
		LCD_WriteReg(0x09,0x0000); //Display Control 3	  
		LCD_WriteReg(0x0A,0x0000); //Frame Cycle Control	  
		LCD_WriteReg(0x0C,0x0000); //External Display Interface Control 1  
		LCD_WriteReg(0x0D,0x0000); //Frame Maker Position		  
		LCD_WriteReg(0x0F,0x0000); //External Display Interface Control 2  
 		delay_ms(20); 
		//TFT 液晶彩色图像显示方法14 
		LCD_WriteReg(0x10,0x16B0); //0x14B0 //Power Control 1 
		LCD_WriteReg(0x11,0x0001); //0x0007 //Power Control 2 
		LCD_WriteReg(0x17,0x0001); //0x0000 //Power Control 3 
		LCD_WriteReg(0x12,0x0138); //0x013B //Power Control 4 
		LCD_WriteReg(0x13,0x0800); //0x0800 //Power Control 5 
		LCD_WriteReg(0x29,0x0009); //NVM read data 2 
		LCD_WriteReg(0x2a,0x0009); //NVM read data 3 
		LCD_WriteReg(0xa4,0x0000);	  
		LCD_WriteReg(0x50,0x0000); //设置操作窗口的X轴开始列 
		LCD_WriteReg(0x51,0x00EF); //设置操作窗口的X轴结束列 
		LCD_WriteReg(0x52,0x0000); //设置操作窗口的Y轴开始行 
		LCD_WriteReg(0x53,0x013F); //设置操作窗口的Y轴结束行 
		LCD_WriteReg(0x60,0x2700); //Driver Output Control 
		//设置屏幕的点数以及扫描的起始行 
		LCD_WriteReg(0x61,0x0001); //Driver Output Control 
		LCD_WriteReg(0x6A,0x0000); //Vertical Scroll Control 
		LCD_WriteReg(0x80,0x0000); //Display Position – Partial Display 1 
		LCD_WriteReg(0x81,0x0000); //RAM Address Start – Partial Display 1 
		LCD_WriteReg(0x82,0x0000); //RAM address End - Partial Display 1 
		LCD_WriteReg(0x83,0x0000); //Display Position – Partial Display 2 
		LCD_WriteReg(0x84,0x0000); //RAM Address Start – Partial Display 2 
		LCD_WriteReg(0x85,0x0000); //RAM address End – Partail Display2 
		LCD_WriteReg(0x90,0x0013); //Frame Cycle Control 
		LCD_WriteReg(0x92,0x0000);  //Panel Interface Control 2 
		LCD_WriteReg(0x93,0x0003); //Panel Interface control 3 
		LCD_WriteReg(0x95,0x0110);  //Frame Cycle Control 
		LCD_WriteReg(0x07,0x0173);		  
		delay_ms(50); 
	}	 
	else if(DeviceCode==0x1505) 
	{ 
		// second release on 3/5  ,luminance is acceptable,water wave appear during camera preview 
        LCD_WriteReg(0x0007,0x0000); 
        delay_ms(50);  
        LCD_WriteReg(0x0012,0x011C);//0x011A   why need to set several times? 
        LCD_WriteReg(0x00A4,0x0001);//NVM	  
        LCD_WriteReg(0x0008,0x000F); 
        LCD_WriteReg(0x000A,0x0008); 
        LCD_WriteReg(0x000D,0x0008);	     
  		//伽马校正 
        LCD_WriteReg(0x0030,0x0707); 
        LCD_WriteReg(0x0031,0x0007); //0x0707 
        LCD_WriteReg(0x0032,0x0603);  
        LCD_WriteReg(0x0033,0x0700);  
        LCD_WriteReg(0x0034,0x0202);  
        LCD_WriteReg(0x0035,0x0002); //?0x0606 
        LCD_WriteReg(0x0036,0x1F0F); 
        LCD_WriteReg(0x0037,0x0707); //0x0f0f  0x0105 
        LCD_WriteReg(0x0038,0x0000);  
        LCD_WriteReg(0x0039,0x0000);  
        LCD_WriteReg(0x003A,0x0707);  
        LCD_WriteReg(0x003B,0x0000); //0x0303 
        LCD_WriteReg(0x003C,0x0007); //?0x0707 
        LCD_WriteReg(0x003D,0x0000); //0x1313//0x1f08 
        delay_ms(50);  
        LCD_WriteReg(0x0007,0x0001); 
        LCD_WriteReg(0x0017,0x0001);//开启电源 
        delay_ms(50);  
  		//电源配置 
        LCD_WriteReg(0x0010,0x17A0);  
        LCD_WriteReg(0x0011,0x0217);//reference voltage VC[2:0]   Vciout = 1.00*Vcivl 
        LCD_WriteReg(0x0012,0x011E);//0x011c  //Vreg1out = Vcilvl*1.80   is it the same as Vgama1out ? 
        LCD_WriteReg(0x0013,0x0F00);//VDV[4:0]-->VCOM Amplitude VcomL = VcomH - Vcom Ampl 
        LCD_WriteReg(0x002A,0x0000);   
        LCD_WriteReg(0x0029,0x000A);//0x0001F  Vcomh = VCM1[4:0]*Vreg1out    gate source voltage?? 
        LCD_WriteReg(0x0012,0x013E);// 0x013C  power supply on 
        //Coordinates Control// 
        LCD_WriteReg(0x0050,0x0000);//0x0e00 
        LCD_WriteReg(0x0051,0x00EF);  
        LCD_WriteReg(0x0052,0x0000);  
        LCD_WriteReg(0x0053,0x013F);  
    	//Pannel Image Control// 
        LCD_WriteReg(0x0060,0x2700);  
        LCD_WriteReg(0x0061,0x0001);  
        LCD_WriteReg(0x006A,0x0000);  
        LCD_WriteReg(0x0080,0x0000);  
    	//Partial Image Control// 
        LCD_WriteReg(0x0081,0x0000);  
        LCD_WriteReg(0x0082,0x0000);  
        LCD_WriteReg(0x0083,0x0000);  
        LCD_WriteReg(0x0084,0x0000);  
        LCD_WriteReg(0x0085,0x0000);  
  		//Panel Interface Control// 
        LCD_WriteReg(0x0090,0x0013);//0x0010 frenqucy 
        LCD_WriteReg(0x0092,0x0300);  
        LCD_WriteReg(0x0093,0x0005);  
        LCD_WriteReg(0x0095,0x0000);  
        LCD_WriteReg(0x0097,0x0000);  
        LCD_WriteReg(0x0098,0x0000);  
   
        LCD_WriteReg(0x0001,0x0100);  
        LCD_WriteReg(0x0002,0x0700);  
        LCD_WriteReg(0x0003,0x1030);  
        LCD_WriteReg(0x0004,0x0000);  
        LCD_WriteReg(0x000C,0x0000);  
        LCD_WriteReg(0x000F,0x0000);  
        LCD_WriteReg(0x0020,0x0000);  
        LCD_WriteReg(0x0021,0x0000);  
        LCD_WriteReg(0x0007,0x0021);  
        delay_ms(20); 
        LCD_WriteReg(0x0007,0x0061);  
        delay_ms(20); 
        LCD_WriteReg(0x0007,0x0173);  
        delay_ms(20); 
	}else if(DeviceCode==0xB505) 
	{ 
		LCD_WriteReg(0x0000,0x0000); 
		LCD_WriteReg(0x0000,0x0000); 
		LCD_WriteReg(0x0000,0x0000); 
		LCD_WriteReg(0x0000,0x0000); 
		 
		LCD_WriteReg(0x00a4,0x0001); 
		delay_ms(20);		   
		LCD_WriteReg(0x0060,0x2700); 
		LCD_WriteReg(0x0008,0x0202); 
		 
		LCD_WriteReg(0x0030,0x0214); 
		LCD_WriteReg(0x0031,0x3715); 
		LCD_WriteReg(0x0032,0x0604); 
		LCD_WriteReg(0x0033,0x0e16); 
		LCD_WriteReg(0x0034,0x2211); 
		LCD_WriteReg(0x0035,0x1500); 
		LCD_WriteReg(0x0036,0x8507); 
		LCD_WriteReg(0x0037,0x1407); 
		LCD_WriteReg(0x0038,0x1403); 
		LCD_WriteReg(0x0039,0x0020); 
		 
		LCD_WriteReg(0x0090,0x001a); 
		LCD_WriteReg(0x0010,0x0000); 
		LCD_WriteReg(0x0011,0x0007); 
		LCD_WriteReg(0x0012,0x0000); 
		LCD_WriteReg(0x0013,0x0000); 
		delay_ms(20); 
		 
		LCD_WriteReg(0x0010,0x0730); 
		LCD_WriteReg(0x0011,0x0137); 
		delay_ms(20); 
		 
		LCD_WriteReg(0x0012,0x01b8); 
		delay_ms(20); 
		 
		LCD_WriteReg(0x0013,0x0f00); 
		LCD_WriteReg(0x002a,0x0080); 
		LCD_WriteReg(0x0029,0x0048); 
		delay_ms(20); 
		 
		LCD_WriteReg(0x0001,0x0100); 
		LCD_WriteReg(0x0002,0x0700); 
		LCD_WriteReg(0x0003,0x1230); 
		LCD_WriteReg(0x0008,0x0202); 
		LCD_WriteReg(0x000a,0x0000); 
		LCD_WriteReg(0x000c,0x0000); 
		LCD_WriteReg(0x000d,0x0000); 
		LCD_WriteReg(0x000e,0x0030); 
		LCD_WriteReg(0x0050,0x0000); 
		LCD_WriteReg(0x0051,0x00ef); 
		LCD_WriteReg(0x0052,0x0000); 
		LCD_WriteReg(0x0053,0x013f); 
		LCD_WriteReg(0x0060,0x2700); 
		LCD_WriteReg(0x0061,0x0001); 
		LCD_WriteReg(0x006a,0x0000); 
		//LCD_WriteReg(0x0080,0x0000); 
		//LCD_WriteReg(0x0081,0x0000); 
		LCD_WriteReg(0x0090,0X0011); 
		LCD_WriteReg(0x0092,0x0600); 
		LCD_WriteReg(0x0093,0x0402); 
		LCD_WriteReg(0x0094,0x0002); 
		delay_ms(20); 
		 
		LCD_WriteReg(0x0007,0x0001); 
		delay_ms(20); 
		LCD_WriteReg(0x0007,0x0061); 
		LCD_WriteReg(0x0007,0x0173); 
		 
		LCD_WriteReg(0x0020,0x0000); 
		LCD_WriteReg(0x0021,0x0000);	   
		LCD_WriteReg(0x00,0x22);   
	}else if(DeviceCode==0xC505) 
	{ 
		LCD_WriteReg(0x0000,0x0000); 
		LCD_WriteReg(0x0000,0x0000); 
		delay_ms(20);		   
		LCD_WriteReg(0x0000,0x0000); 
		LCD_WriteReg(0x0000,0x0000); 
		LCD_WriteReg(0x0000,0x0000); 
		LCD_WriteReg(0x0000,0x0000); 
 		LCD_WriteReg(0x00a4,0x0001); 
		delay_ms(20);		   
		LCD_WriteReg(0x0060,0x2700); 
		LCD_WriteReg(0x0008,0x0806); 
		 
		LCD_WriteReg(0x0030,0x0703);//gamma setting 
		LCD_WriteReg(0x0031,0x0001); 
		LCD_WriteReg(0x0032,0x0004); 
		LCD_WriteReg(0x0033,0x0102); 
		LCD_WriteReg(0x0034,0x0300); 
		LCD_WriteReg(0x0035,0x0103); 
		LCD_WriteReg(0x0036,0x001F); 
		LCD_WriteReg(0x0037,0x0703); 
		LCD_WriteReg(0x0038,0x0001); 
		LCD_WriteReg(0x0039,0x0004); 
		 
		 
		 
		LCD_WriteReg(0x0090, 0x0015);	//80Hz 
		LCD_WriteReg(0x0010, 0X0410);	//BT,AP 
		LCD_WriteReg(0x0011,0x0247);	//DC1,DC0,VC 
		LCD_WriteReg(0x0012, 0x01BC); 
		LCD_WriteReg(0x0013, 0x0e00); 
		delay_ms(120); 
		LCD_WriteReg(0x0001, 0x0100); 
		LCD_WriteReg(0x0002, 0x0200); 
		LCD_WriteReg(0x0003, 0x1030); 
		 
		LCD_WriteReg(0x000A, 0x0008); 
		LCD_WriteReg(0x000C, 0x0000); 
		 
		LCD_WriteReg(0x000E, 0x0020); 
		LCD_WriteReg(0x000F, 0x0000); 
		LCD_WriteReg(0x0020, 0x0000);	//H Start 
		LCD_WriteReg(0x0021, 0x0000);	//V Start 
		LCD_WriteReg(0x002A,0x003D);	//vcom2 
		delay_ms(20); 
		LCD_WriteReg(0x0029, 0x002d); 
		LCD_WriteReg(0x0050, 0x0000); 
		LCD_WriteReg(0x0051, 0xD0EF); 
		LCD_WriteReg(0x0052, 0x0000); 
		LCD_WriteReg(0x0053, 0x013F); 
		LCD_WriteReg(0x0061, 0x0000); 
		LCD_WriteReg(0x006A, 0x0000); 
		LCD_WriteReg(0x0092,0x0300);  
  
 		LCD_WriteReg(0x0093, 0x0005); 
		LCD_WriteReg(0x0007, 0x0100); 
	}else if(DeviceCode==0x8989) 
	{	    
		LCD_WriteReg(0x0000,0x0001);//打开晶振 
    	LCD_WriteReg(0x0003,0xA8A4);//0xA8A4 
    	LCD_WriteReg(0x000C,0x0000);     
    	LCD_WriteReg(0x000D,0x080C);    
    	LCD_WriteReg(0x000E,0x2B00);     
    	LCD_WriteReg(0x001E,0x00B0);     
    	LCD_WriteReg(0x0001,0x2B3F);//驱动输出控制320*240  0x6B3F 
    	LCD_WriteReg(0x0002,0x0600); 
    	LCD_WriteReg(0x0010,0x0000);   
    	LCD_WriteReg(0x0011,0x6070); //定义数据格式  16位色 		横屏 0x6058 
    	LCD_WriteReg(0x0005,0x0000);   
    	LCD_WriteReg(0x0006,0x0000);   
    	LCD_WriteReg(0x0016,0xEF1C);   
    	LCD_WriteReg(0x0017,0x0003);   
    	LCD_WriteReg(0x0007,0x0233); //0x0233        
    	LCD_WriteReg(0x000B,0x0000);   
    	LCD_WriteReg(0x000F,0x0000); //扫描开始地址 
    	LCD_WriteReg(0x0041,0x0000);   
    	LCD_WriteReg(0x0042,0x0000);   
    	LCD_WriteReg(0x0048,0x0000);   
    	LCD_WriteReg(0x0049,0x013F);   
    	LCD_WriteReg(0x004A,0x0000);   
    	LCD_WriteReg(0x004B,0x0000);   
    	LCD_WriteReg(0x0044,0xEF00);   
    	LCD_WriteReg(0x0045,0x0000);   
    	LCD_WriteReg(0x0046,0x013F);   
    	LCD_WriteReg(0x0030,0x0707);   
    	LCD_WriteReg(0x0031,0x0204);   
    	LCD_WriteReg(0x0032,0x0204);   
    	LCD_WriteReg(0x0033,0x0502);   
    	LCD_WriteReg(0x0034,0x0507);   
    	LCD_WriteReg(0x0035,0x0204);   
    	LCD_WriteReg(0x0036,0x0204);   
    	LCD_WriteReg(0x0037,0x0502);   
    	LCD_WriteReg(0x003A,0x0302);   
    	LCD_WriteReg(0x003B,0x0302);   
    	LCD_WriteReg(0x0023,0x0000);   
    	LCD_WriteReg(0x0024,0x0000);   
    	LCD_WriteReg(0x0025,0x8000);   
    	LCD_WriteReg(0x004f,0);        //行首址0 
    	LCD_WriteReg(0x004e,0);        //列首址0 
	}else if(DeviceCode==0x4531) 
	{ 
		LCD_WriteReg(0X00,0X0001);    
		delay_ms(10);    
		LCD_WriteReg(0X10,0X1628);    
		LCD_WriteReg(0X12,0X000e);//0x0006     
		LCD_WriteReg(0X13,0X0A39);    
		delay_ms(10);    
		LCD_WriteReg(0X11,0X0040);    
		LCD_WriteReg(0X15,0X0050);    
		delay_ms(10);    
		LCD_WriteReg(0X12,0X001e);//16     
		delay_ms(10);    
		LCD_WriteReg(0X10,0X1620);    
		LCD_WriteReg(0X13,0X2A39);    
		delay_ms(10);    
		LCD_WriteReg(0X01,0X0100);    
		LCD_WriteReg(0X02,0X0300);    
		LCD_WriteReg(0X03,0X1030);//改变方向的    
		LCD_WriteReg(0X08,0X0202);    
		LCD_WriteReg(0X0A,0X0008);    
		LCD_WriteReg(0X30,0X0000);    
		LCD_WriteReg(0X31,0X0402);    
		LCD_WriteReg(0X32,0X0106);    
		LCD_WriteReg(0X33,0X0503);    
		LCD_WriteReg(0X34,0X0104);    
		LCD_WriteReg(0X35,0X0301);    
		LCD_WriteReg(0X36,0X0707);    
		LCD_WriteReg(0X37,0X0305);    
		LCD_WriteReg(0X38,0X0208);    
		LCD_WriteReg(0X39,0X0F0B);    
		LCD_WriteReg(0X41,0X0002);    
		LCD_WriteReg(0X60,0X2700);    
		LCD_WriteReg(0X61,0X0001);    
		LCD_WriteReg(0X90,0X0210);    
		LCD_WriteReg(0X92,0X010A);    
		LCD_WriteReg(0X93,0X0004);    
		LCD_WriteReg(0XA0,0X0100);    
		LCD_WriteReg(0X07,0X0001);    
		LCD_WriteReg(0X07,0X0021);    
		LCD_WriteReg(0X07,0X0023);    
		LCD_WriteReg(0X07,0X0033);    
		LCD_WriteReg(0X07,0X0133);    
		LCD_WriteReg(0XA0,0X0000);  
	}else if(DeviceCode==0x4535) 
	{			       
		LCD_WriteReg(0X15,0X0030);    
		LCD_WriteReg(0X9A,0X0010);    
 		LCD_WriteReg(0X11,0X0020);    
 		LCD_WriteReg(0X10,0X3428);    
		LCD_WriteReg(0X12,0X0002);//16     
 		LCD_WriteReg(0X13,0X1038);    
		delay_ms(40);    
		LCD_WriteReg(0X12,0X0012);//16     
		delay_ms(40);    
  		LCD_WriteReg(0X10,0X3420);    
 		LCD_WriteReg(0X13,0X3038);    
		delay_ms(70);    
		LCD_WriteReg(0X30,0X0000);    
		LCD_WriteReg(0X31,0X0402);    
		LCD_WriteReg(0X32,0X0307);    
		LCD_WriteReg(0X33,0X0304);    
		LCD_WriteReg(0X34,0X0004);    
		LCD_WriteReg(0X35,0X0401);    
		LCD_WriteReg(0X36,0X0707);    
		LCD_WriteReg(0X37,0X0305);    
		LCD_WriteReg(0X38,0X0610);    
		LCD_WriteReg(0X39,0X0610);  
		   
		LCD_WriteReg(0X01,0X0100);    
		LCD_WriteReg(0X02,0X0300);    
		LCD_WriteReg(0X03,0X1030);//改变方向的    
		LCD_WriteReg(0X08,0X0808);    
		LCD_WriteReg(0X0A,0X0008);    
 		LCD_WriteReg(0X60,0X2700);    
		LCD_WriteReg(0X61,0X0001);    
		LCD_WriteReg(0X90,0X013E);    
		LCD_WriteReg(0X92,0X0100);    
		LCD_WriteReg(0X93,0X0100);    
 		LCD_WriteReg(0XA0,0X3000);    
 		LCD_WriteReg(0XA3,0X0010);    
		LCD_WriteReg(0X07,0X0001);    
		LCD_WriteReg(0X07,0X0021);    
		LCD_WriteReg(0X07,0X0023);    
		LCD_WriteReg(0X07,0X0033);    
		LCD_WriteReg(0X07,0X0133);    
	}	 
	LCD_Scan_Dir(DFT_SCAN_DIR);		  
	LCD_LED=1;//点亮背光	  
	LCD_Clear(WHITE); 
}  		   
   
//清屏函数 
//Color:要清屏的填充色 
void LCD_Clear(u16 Color) 
{ 
	u32 index=0;       
	LCD_SetCursor(0x00,0x0000);//设置光标位置  
	LCD_WriteRAM_Prepare();     //开始写入GRAM	 	   
	for(index=0;index<76800;index++) 
	{ 
		LCD_WR_DATA(Color);     
	} 
}   
//在指定区域内填充指定颜色 
//区域大小:(xend-xsta+1)*(yend-ysta+1) 
//xsta 
//color:要填充的颜色 
void LCD_Fill(u16 sx,u16 sy,u16 ex,u16 ey,u16 color) 
{           
	u16 i,j; 
	u16 xlen=0; 
	LCD_Scan_Dir(L2R_U2D); 
#if USE_HORIZONTAL==1 
	xlen=ey-sy+1;	    
	for(i=sx;i<=ex;i++) 
	{ 
		if(Remote_Rdy)return; 
	 	LCD_SetCursor(i,sy);      				//设置光标位置  
		LCD_WriteRAM_Prepare();     			//开始写入GRAM	   
		for(j=0;j<xlen;j++) 
		{ 
			if(Remote_Rdy)return; 
			LCD_WR_DATA(color);	//设置光标位置 	   
		} 
	} 
#else 
	xlen=ex-sx+1;	    
	for(i=sy;i<=ey;i++) 
	{ 
		if(Remote_Rdy)return; 
	 	LCD_SetCursor(sx,i);      				//设置光标位置  
		LCD_WriteRAM_Prepare();     			//开始写入GRAM	   
		for(j=0;j<xlen;j++) 
		{ 
			if(Remote_Rdy)return; 
			LCD_WR_DATA(color);	//设置光标位置 	  
		}			 
	} 
#endif 
	LCD_Scan_Dir(DFT_SCAN_DIR); 
}   
 
//画线 
//x1,y1:起点坐标 
//x2,y2:终点坐标   
void LCD_DrawLine(u16 x1, u16 y1, u16 x2, u16 y2) 
{ 
	u16 t;  
	int xerr=0,yerr=0,delta_x,delta_y,distance;  
	int incx,incy,uRow,uCol;  
 
	delta_x=x2-x1; //计算坐标增量  
	delta_y=y2-y1;  
	uRow=x1;  
	uCol=y1;  
	if(delta_x>0)incx=1; //设置单步方向  
	else if(delta_x==0)incx=0;//垂直线  
	else {incx=-1;delta_x=-delta_x;}  
	if(delta_y>0)incy=1;  
	else if(delta_y==0)incy=0;//水平线  
	else{incy=-1;delta_y=-delta_y;}  
	if( delta_x>delta_y)distance=delta_x; //选取基本增量坐标轴  
	else distance=delta_y;  
	for(t=0;t<=distance+1;t++ )//画线输出  
	{   
		LCD_DrawPoint(uRow,uCol);//画点  
		xerr+=delta_x ;  
		yerr+=delta_y ;  
		if(xerr>distance)  
		{  
			xerr-=distance;  
			uRow+=incx;  
		}  
		if(yerr>distance)  
		{  
			yerr-=distance;  
			uCol+=incy;  
		}  
	}   
}     
//画矩形 
void LCD_DrawRectangle(u16 x1, u16 y1, u16 x2, u16 y2) 
{ 
	LCD_DrawLine(x1,y1,x2,y1); 
	LCD_DrawLine(x1,y1,x1,y2); 
	LCD_DrawLine(x1,y2,x2,y2); 
	LCD_DrawLine(x2,y1,x2,y2); 
} 
//在指定位置画一个指定大小的圆 
//(x,y):中心点 
//r    :半径 
void Draw_Circle(u16 x0,u16 y0,u8 r) 
{ 
	int a,b; 
	int di; 
	a=0;b=r;	   
	di=3-(r<<1);             //判断下个点位置的标志 
	while(a<=b) 
	{ 
		LCD_DrawPoint(x0-b,y0-a);             //3            
		LCD_DrawPoint(x0+b,y0-a);             //0            
		LCD_DrawPoint(x0-a,y0+b);             //1        
		LCD_DrawPoint(x0-b,y0-a);             //7            
		LCD_DrawPoint(x0-a,y0-b);             //2              
		LCD_DrawPoint(x0+b,y0+a);             //4                
		LCD_DrawPoint(x0+a,y0-b);             //5 
		LCD_DrawPoint(x0+a,y0+b);             //6  
		LCD_DrawPoint(x0-b,y0+a);              
		a++; 
		//使用Bresenham算法画圆      
		if(di<0)di +=4*a+6;	   
		else 
		{ 
			di+=10+4*(a-b);    
			b--; 
		}  
		LCD_DrawPoint(x0+a,y0+b); 
	} 
}  
//在指定位置显示一个字符 
//x:0~234 
//y:0~308 
//num:要显示的字符:" "--->"~" 
//size:字体大小 12/16 
//mode:叠加方式(1)还是非叠加方式(0) 
//在指定位置显示一个字符 
//x:0~234 
//y:0~308 
//num:要显示的字符:" "--->"~" 
//size:字体大小 12/16 
//mode:叠加方式(1)还是非叠加方式(0) 
void LCD_ShowChar(u16 x,u16 y,u8 num,u8 size,u8 mode) 
{   
#if USE_HORIZONTAL==1 
#define MAX_CHAR_POSX 312 
#define MAX_CHAR_POSY 232  
#else      
#define MAX_CHAR_POSX 232 
#define MAX_CHAR_POSY 312 
#endif  
    u8 temp; 
    u8 pos,t; 
	u16 x0=x; 
	u16 colortemp=POINT_COLOR;       
    if(x>MAX_CHAR_POSX||y>MAX_CHAR_POSY)return;	     
	//设置窗口		    
	num=num-' ';//得到偏移后的值 
	if(!mode) //非叠加方式 
	{ 
		for(pos=0;pos<size;pos++) 
		{ 
			if(size==12)temp=asc2_1206[num][pos];//调用1206字体 
			else temp=asc2_1608[num][pos];		 //调用1608字体 
			for(t=0;t<size/2;t++) 
		    {                  
		        if(temp&0x01)POINT_COLOR=colortemp; 
				else POINT_COLOR=BACK_COLOR; 
				LCD_DrawPoint(x,y);	 
				temp>>=1;  
				x++; 
		    } 
			x=x0; 
			y++; 
		}	 
	}else//叠加方式 
	{ 
		for(pos=0;pos<size;pos++) 
		{ 
			if(size==12)temp=asc2_1206[num][pos];//调用1206字体 
			else temp=asc2_1608[num][pos];		 //调用1608字体 
			for(t=0;t<size/2;t++) 
		    {                  
		        if(temp&0x01)LCD_DrawPoint(x+t,y+pos);//画一个点      
		        temp>>=1;  
		    } 
		} 
	} 
	POINT_COLOR=colortemp;	    	   	 	   
}    
//m^n函数 
u32 mypow(u8 m,u8 n) 
{ 
	u32 result=1;	  
	while(n--)result*=m;     
	return result; 
}			  
//显示2个数字 
//x,y :起点坐标	  
//len :数字的位数 
//size:字体大小 
//color:颜色 
//num:数值(0~4294967295);	  
void LCD_ShowNum(u16 x,u16 y,u32 num,u8 len,u8 size) 
{         	 
	u8 t,temp; 
	u8 enshow=0;						    
	for(t=0;t<len;t++) 
	{ 
		temp=(num/mypow(10,len-t-1))%10; 
		if(enshow==0&&t<(len-1)) 
		{ 
			if(temp==0) 
			{ 
				LCD_ShowChar(x+(size/2)*t,y,' ',size,0); 
				continue; 
			}else enshow=1;  
		 	  
		} 
	 	LCD_ShowChar(x+(size/2)*t,y,temp+'0',size,0);  
	} 
}  
//显示2个数字 
//x,y:起点坐标 
//size:字体大小 
//mode:模式	0,填充模式;1,叠加模式 
//num:数值(0~99);	  
void LCD_Show2Num(u16 x,u16 y,u16 num,u8 len,u8 size,u8 mode) 
{         	 
	u8 t,temp;						    
	for(t=0;t<len;t++) 
	{ 
		temp=(num/mypow(10,len-t-1))%10; 
	 	LCD_ShowChar(x+(size/2)*t,y,temp+'0',size,mode);  
	} 
}  
//显示字符串 
//x,y:起点坐标   
//*p:字符串起始地址 
//用16字体 
void LCD_ShowString(u16 x,u16 y,const u8 *p) 
{          
    while(*p!='\0') 
    {        
        if(x>MAX_CHAR_POSX){x=0;y+=16;} 
        if(y>MAX_CHAR_POSY){y=x=0;LCD_Clear(WHITE);} 
        LCD_ShowChar(x,y,*p,16,0); 
        x+=8; 
        p++; 
    }   
} 
 
void ConvertIntToHex(u8 *Int,u8 *Buf) 
{ 
	while(*Int!='\0') 
	{ 
		*Buf=*Int/16; 
		 Buf++; 
		*Buf=*Int%16; 
		 Buf++; 
	   Int++; 
	} 
	 
} 
 
u8 UcharToASCII(u8 num) 
{ 
	u8 temp; 
	temp = num&0x0f; 
	if(temp<10) 
	 	return (0x30+temp); 
 
	else if((temp>9)&&(temp<16)) 
		return (0x41-10+temp); 
	return 0x58; 
}	 
 
void ShowNum(u8 x,u16 y,u8 num) 
{ 
	switch(num) 
	{ 
		case 0:LCD_ShowString(x,y,"0");	break; 
		case 1:LCD_ShowString(x,y,"1");	break; 
		case 2:LCD_ShowString(x,y,"2");	break; 
		case 3:LCD_ShowString(x,y,"3");	break; 
		case 4:LCD_ShowString(x,y,"4");	break; 
		case 5:LCD_ShowString(x,y,"5");	break; 
		case 6:LCD_ShowString(x,y,"6");	break; 
		case 7:LCD_ShowString(x,y,"7");	break; 
		case 8:LCD_ShowString(x,y,"8");	break; 
		case 9:LCD_ShowString(x,y,"9");	break; 
		case 10:LCD_ShowString(x,y,"A");	break; 
		case 11:LCD_ShowString(x,y,"B");	break; 
		case 12:LCD_ShowString(x,y,"C");	break; 
		case 13:LCD_ShowString(x,y,"D");	break; 
		case 14:LCD_ShowString(x,y,"E");	break; 
		case 15:LCD_ShowString(x,y,"F");	break; 
    default:break; 
	} 
} 
 
void ChangeNumberTOString(u8 x,u16 y,u8 num) 
{ 
	u8 decade,units; 
 	 
	decade=num/16; 
 	ShowNum(x,y,decade); 
	units=num%16; 
 	ShowNum(x+8,y,units);	 
} 
 
void LCD_ShowHexBuffer(u8 x,u16 y,u8 distance, u8 *array,u8 len) 
{ 
	u8 i; 
	u16 subx; 
	static u8 tempshaobing=0; 
	 
	for(i=0;i<len;i++) 
	{ 
		subx=(16+distance)*i; 
		if(!tempshaobing) 
		{ 
			if(subx>=240) 
			{ 
				 subx-=240; 
				 tempshaobing=1; 
				 y+=30; 
			} 
	  } 
		ChangeNumberTOString(x+subx,y,*array); 
    array++; 
	} 
} 
 
void ShowNByte(u8 x,u16 y,u8 array[],u8 len,u8 distance) 
{ 
   u8 i; 
	 
	for(i=0;i<len;i++) 
	{ 
		  if(Remote_Rdy) return; 
			LCD_ShowNum(x+distance*i,y,array[i],3,16); 
	} 
 } 
  
void Show_PreData(u8 key,u8 array[]) 
{ 
			switch(key) 
		{ 
			case 0: 
			POINT_COLOR=DARKBLUE;	 
			LCD_ShowNum(60,240,array[0],3,16); 
			POINT_COLOR=RED; 
			LCD_ShowNum(90,240,array[1],3,16);	 
			LCD_ShowNum(120,240,array[2],3,16);	 
			LCD_ShowNum(150,240,array[3],3,16);		 
			LCD_ShowNum(180,240,array[4],3,16);			 
			LCD_ShowNum(210,240,array[5],3,16);							 
			break; 
			case 1: 
			POINT_COLOR=DARKBLUE;	 
			LCD_ShowNum(90,240,array[1],3,16); 
			POINT_COLOR=RED; 
			LCD_ShowNum(60,240,array[0],3,16);					 
			LCD_ShowNum(120,240,array[2],3,16);	 
			LCD_ShowNum(150,240,array[3],3,16);		 
			LCD_ShowNum(180,240,array[4],3,16);			 
			LCD_ShowNum(210,240,array[5],3,16);							 
			break; 
			case 2: 
			POINT_COLOR=DARKBLUE;	 
			LCD_ShowNum(120,240,array[2],3,16);	 
			POINT_COLOR=RED; 
			LCD_ShowNum(90,240,array[1],3,16);	 
			LCD_ShowNum(60,240,array[0],3,16);			 
			LCD_ShowNum(150,240,array[3],3,16);		 
			LCD_ShowNum(180,240,array[4],3,16);			 
			LCD_ShowNum(210,240,array[5],3,16);							 
			break; 
			case 3: 
			POINT_COLOR=DARKBLUE;	 
			LCD_ShowNum(150,240,array[3],3,16);		 
			POINT_COLOR=RED; 
			LCD_ShowNum(90,240,array[1],3,16);	 
			LCD_ShowNum(120,240,array[2],3,16);	 
			LCD_ShowNum(180,240,array[4],3,16);			 
			LCD_ShowNum(210,240,array[5],3,16);		 
			LCD_ShowNum(60,240,array[0],3,16); 
			break; 
			case 4: 
			POINT_COLOR=DARKBLUE;	 
			LCD_ShowNum(180,240,array[4],3,16);			 
			POINT_COLOR=RED; 
			LCD_ShowNum(90,240,array[1],3,16);	 
			LCD_ShowNum(120,240,array[2],3,16);	 
			LCD_ShowNum(150,240,array[3],3,16);		 
			LCD_ShowNum(210,240,array[5],3,16); 
			LCD_ShowNum(60,240,array[0],3,16); 
			break; 
			case 5: 
			POINT_COLOR=DARKBLUE;	 
			LCD_ShowNum(210,240,array[5],3,16);							 
			POINT_COLOR=RED; 
			LCD_ShowNum(90,240,array[1],3,16);	 
			LCD_ShowNum(120,240,array[2],3,16);	 
			LCD_ShowNum(150,240,array[3],3,16);		 
			LCD_ShowNum(180,240,array[4],3,16);	 
			LCD_ShowNum(60,240,array[0],3,16); 
			break; 
		 default:break; 
		} 
} 
 
void Array_Copy(u8 start_array[],u8 global_array[],u8 start_bit,u8 end_bit) 
{ 
	u8 i; 
	 
	for(i=start_bit;i<=end_bit;i++) 
	{ 
		global_array[i]=start_array[i]; 
	} 
}