利用CubeMX复现正点原子TFTLCD驱动例程

来源:正点原子

FMC的工作原理暂时先欠着,先记录一下CRUD的过程。

第一步准备一个us级别延时函数,不会的参考拙作:STM32的定时器简介-CSDN博客

第二部开启FMC外设:

①进入 Pinout->FMC 配置栏,配置 FMC 基本参数。这里我们使用的是BANK1 的第一个分区 NE1 ,同时把 LCD 作为 SRAM 使用, 19 位地址线 16 位数据线。 配置参数如下图 17.5.1 所示:

点击 Configuration->FMC 进入 FMC 配置界面,在 NOR/SRAM 1 选项卡之下配置相关参数。

第三步生成代码并编辑工程,绝大部分都是直接CV正点原子的源码:

①准备delay.c、delay.h、sys.c和sys.h四个文件

delay.c

#include "delay.h"//延时nus
//nus:要延时的us数
void delay_us(uint32_t us)
{		uint16_t differ = 0xffff-us-5;                __HAL_TIM_SET_COUNTER(&htim6,differ);    HAL_TIM_Base_Start(&htim6);         while(differ < 0xffff-5){    differ = __HAL_TIM_GET_COUNTER(&htim6);        }HAL_TIM_Base_Stop(&htim6);
}//延时nms
//nms:要延时的ms数
void delay_ms(uint16_t nms)
{uint32_t i;for(i=0;i<nms;i++) {delay_us(1000);}
}

delay.h

#ifndef __delay_H
#define __delay_H#include "tim.h"void delay_us(uint32_t us);
void delay_ms(uint16_t nms);#endif

sys.c

#include "sys.h"//THUMB指令不支持汇编内联
//采用如下方法实现执行汇编指令WFI  
__asm void WFI_SET(void)
{WFI;		  
}
//关闭所有中断(但是不包括fault和NMI中断)
__asm void INTX_DISABLE(void)
{CPSID   IBX      LR	  
}
//开启所有中断
__asm void INTX_ENABLE(void)
{CPSIE   IBX      LR  
}
//设置栈顶地址
//addr:栈顶地址
__asm void MSR_MSP(uint32_t addr) 
{MSR MSP, r0 			//set Main Stack valueBX r14
}

sys.h

#ifndef __sys_H
#define __sys_H#include "main.h"//定义一些常用的数据类型短关键字 
typedef int32_t  s32;
typedef int16_t s16;
typedef int8_t  s8;typedef const int32_t sc32;  
typedef const int16_t sc16;  
typedef const int8_t sc8;  typedef __IO int32_t  vs32;
typedef __IO int16_t  vs16;
typedef __IO int8_t   vs8;typedef __I int32_t vsc32;  
typedef __I int16_t vsc16; 
typedef __I int8_t vsc8;   typedef uint32_t  u32;
typedef uint16_t u16;
typedef uint8_t  u8;typedef const uint32_t uc32;  
typedef const uint16_t uc16;  
typedef const uint8_t uc8; typedef __IO uint32_t  vu32;
typedef __IO uint16_t vu16;
typedef __IO uint8_t  vu8;typedef __I uint32_t vuc32;  
typedef __I uint16_t vuc16; 
typedef __I uint8_t vuc8;  //位带操作,实现51类似的GPIO控制功能
//具体实现思想,参考<<CM3权威指南>>第五章(87页~92页).M4同M3类似,只是寄存器地址变了.
//IO口操作宏定义
#define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2)) 
#define MEM_ADDR(addr)  *((volatile unsigned long  *)(addr)) 
#define BIT_ADDR(addr, bitnum)   MEM_ADDR(BITBAND(addr, bitnum)) 
//IO口地址映射
#define GPIOA_ODR_Addr    (GPIOA_BASE+20) //0x40020014
#define GPIOB_ODR_Addr    (GPIOB_BASE+20) //0x40020414 
#define GPIOC_ODR_Addr    (GPIOC_BASE+20) //0x40020814 
#define GPIOD_ODR_Addr    (GPIOD_BASE+20) //0x40020C14 
#define GPIOE_ODR_Addr    (GPIOE_BASE+20) //0x40021014 
#define GPIOF_ODR_Addr    (GPIOF_BASE+20) //0x40021414    
#define GPIOG_ODR_Addr    (GPIOG_BASE+20) //0x40021814   
#define GPIOH_ODR_Addr    (GPIOH_BASE+20) //0x40021C14    
#define GPIOI_ODR_Addr    (GPIOI_BASE+20) //0x40022014 
#define GPIOJ_ODR_ADDr    (GPIOJ_BASE+20) //0x40022414
#define GPIOK_ODR_ADDr    (GPIOK_BASE+20) //0x40022814#define GPIOA_IDR_Addr    (GPIOA_BASE+16) //0x40020010 
#define GPIOB_IDR_Addr    (GPIOB_BASE+16) //0x40020410 
#define GPIOC_IDR_Addr    (GPIOC_BASE+16) //0x40020810 
#define GPIOD_IDR_Addr    (GPIOD_BASE+16) //0x40020C10 
#define GPIOE_IDR_Addr    (GPIOE_BASE+16) //0x40021010 
#define GPIOF_IDR_Addr    (GPIOF_BASE+16) //0x40021410 
#define GPIOG_IDR_Addr    (GPIOG_BASE+16) //0x40021810 
#define GPIOH_IDR_Addr    (GPIOH_BASE+16) //0x40021C10 
#define GPIOI_IDR_Addr    (GPIOI_BASE+16) //0x40022010 
#define GPIOJ_IDR_Addr    (GPIOJ_BASE+16) //0x40022410 
#define GPIOK_IDR_Addr    (GPIOK_BASE+16) //0x40022810 //IO口操作,只对单一的IO口!
//确保n的值小于16!
#define PAout(n)   BIT_ADDR(GPIOA_ODR_Addr,n)  //输出 
#define PAin(n)    BIT_ADDR(GPIOA_IDR_Addr,n)  //输入 #define PBout(n)   BIT_ADDR(GPIOB_ODR_Addr,n)  //输出 
#define PBin(n)    BIT_ADDR(GPIOB_IDR_Addr,n)  //输入 #define PCout(n)   BIT_ADDR(GPIOC_ODR_Addr,n)  //输出 
#define PCin(n)    BIT_ADDR(GPIOC_IDR_Addr,n)  //输入 #define PDout(n)   BIT_ADDR(GPIOD_ODR_Addr,n)  //输出 
#define PDin(n)    BIT_ADDR(GPIOD_IDR_Addr,n)  //输入 #define PEout(n)   BIT_ADDR(GPIOE_ODR_Addr,n)  //输出 
#define PEin(n)    BIT_ADDR(GPIOE_IDR_Addr,n)  //输入#define PFout(n)   BIT_ADDR(GPIOF_ODR_Addr,n)  //输出 
#define PFin(n)    BIT_ADDR(GPIOF_IDR_Addr,n)  //输入#define PGout(n)   BIT_ADDR(GPIOG_ODR_Addr,n)  //输出 
#define PGin(n)    BIT_ADDR(GPIOG_IDR_Addr,n)  //输入#define PHout(n)   BIT_ADDR(GPIOH_ODR_Addr,n)  //输出 
#define PHin(n)    BIT_ADDR(GPIOH_IDR_Addr,n)  //输入#define PIout(n)   BIT_ADDR(GPIOI_ODR_Addr,n)  //输出 
#define PIin(n)    BIT_ADDR(GPIOI_IDR_Addr,n)  //输入#define PJout(n)   BIT_ADDR(GPIOJ_ODR_Addr,n)  //输出 
#define PJin(n)    BIT_ADDR(GPIOJ_IDR_Addr,n)  //输入#define PKout(n)   BIT_ADDR(GPIOK_ODR_Addr,n)  //输出 
#define PKin(n)    BIT_ADDR(GPIOK_IDR_Addr,n)  //输入//以下为汇编函数
void WFI_SET(void);		//执行WFI指令
void INTX_DISABLE(void);//关闭所有中断
void INTX_ENABLE(void);	//开启所有中断
void MSR_MSP(u32 addr);	//设置堆栈地址 #endif

②把fmc自动生成的代码注释掉一部分

③这个printf语句要屏蔽掉

④整体代码,按需裁剪

lcd.c

#include "lcd.h"
#include "font.h"SRAM_HandleTypeDef SRAM_Handler;    //SRAM句柄(用于控制LCD)//LCD的画笔颜色和背景色
u32 POINT_COLOR = 0xFF000000;		//画笔颜色
u32 BACK_COLOR = 0xFFFFFFFF;  	//背景色//管理LCD重要参数
//默认为竖屏
_lcd_dev lcddev;//写寄存器函数
//regval:寄存器值
void LCD_WR_REG(vu16 regval)
{regval = regval;		//使用-O2优化的时候,必须插入的延时LCD->LCD_REG = regval; //写入要写的寄存器序号
}
//写LCD数据
//data:要写入的值
void LCD_WR_DATA(vu16 data)
{data = data;			//使用-O2优化的时候,必须插入的延时LCD->LCD_RAM = data;
}
//读LCD数据
//返回值:读到的值
u16 LCD_RD_DATA(void)
{vu16 ram;			//防止被优化ram = LCD->LCD_RAM;return ram;
}
//写寄存器
//LCD_Reg:寄存器地址
//LCD_RegValue:要写入的数据
void LCD_WriteReg(u16 LCD_Reg, u16 LCD_RegValue)
{LCD->LCD_REG = LCD_Reg;		//写入要写的寄存器序号LCD->LCD_RAM = LCD_RegValue;//写入数据
}
//读寄存器
//LCD_Reg:寄存器地址
//返回值:读到的数据
u16 LCD_ReadReg(u16 LCD_Reg)
{LCD_WR_REG(LCD_Reg);		//写入要读的寄存器序号delay_us(5);return LCD_RD_DATA();		//返回读到的值
}
//开始写GRAM
void LCD_WriteRAM_Prepare(void)
{LCD->LCD_REG = lcddev.wramcmd;
}
//LCD写GRAM
//RGB_Code:颜色值
void LCD_WriteRAM(u16 RGB_Code)
{LCD->LCD_RAM = 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);
}
//当mdk -O1时间优化时需要设置
//延时i
void opt_delay(u8 i)
{while (i--);
}
//读取个某点的颜色值
//x,y:坐标
//返回值:此点的颜色
u32 LCD_ReadPoint(u16 x, u16 y)
{u16 r = 0, g = 0, b = 0;if (x >= lcddev.width || y >= lcddev.height)return 0;	//超过了范围,直接返回LCD_SetCursor(x, y);if (lcddev.id == 0X5510)    //5510 发送读GRAM指令{LCD_WR_REG(0X2E00);}else                        //其他IC(9341/5310/1963/7789/7796/9806)发送读GRAM指令{LCD_WR_REG(0X2E);}r = LCD_RD_DATA();								//dummy Readif (lcddev.id == 0X1963)return r;					//1963直接读就可以opt_delay(2);r = LCD_RD_DATA();  		  						//实际坐标颜色if (lcddev.id == 0X7796)    //7796 一次读取一个像素值{return r;}//9341/5310/5510/7789/9806 要分2次读出opt_delay(2);b = LCD_RD_DATA();g = r & 0XFF;		//对于 9341/5310/5510/7789/9806, 第一次读取的是RG的值,R在前,G在后,各占8位g <<= 8;return (((r >> 11) << 11) | ((g >> 10) << 5) | (b >> 11));	// ILI9341/NT35310/NT35510/ST7789/ILI9806 需要公式转换一下
}//LCD开启显示
void LCD_DisplayOn(void)
{if (lcddev.id == 0X5510)    //5510开启显示指令{LCD_WR_REG(0X2900);     //开启显示}else                        //9341/5310/1963/7789/7796/9806 等发送开启显示指令{LCD_WR_REG(0X29);       //开启显示}
}
//LCD关闭显示
void LCD_DisplayOff(void)
{if (lcddev.id == 0X5510)    //5510关闭显示指令{LCD_WR_REG(0X2800);     //关闭显示}else                        //9341/5310/1963/7789/7796/9806 等发送关闭显示指令{LCD_WR_REG(0X28);       //关闭显示}
}
//设置光标位置(对RGB屏无效)
//Xpos:横坐标
//Ypos:纵坐标
void LCD_SetCursor(u16 Xpos, u16 Ypos)
{if (lcddev.id == 0X1963){if (lcddev.dir == 0)   //x坐标需要变换{Xpos = lcddev.width - 1 - Xpos;LCD_WR_REG(lcddev.setxcmd);LCD_WR_DATA(0);LCD_WR_DATA(0);LCD_WR_DATA(Xpos >> 8);LCD_WR_DATA(Xpos & 0XFF);}else{LCD_WR_REG(lcddev.setxcmd);LCD_WR_DATA(Xpos >> 8);LCD_WR_DATA(Xpos & 0XFF);LCD_WR_DATA((lcddev.width - 1) >> 8);LCD_WR_DATA((lcddev.width - 1) & 0XFF);}LCD_WR_REG(lcddev.setycmd);LCD_WR_DATA(Ypos >> 8);LCD_WR_DATA(Ypos & 0XFF);LCD_WR_DATA((lcddev.height - 1) >> 8);LCD_WR_DATA((lcddev.height - 1) & 0XFF);}else if (lcddev.id == 0X5510){LCD_WR_REG(lcddev.setxcmd);LCD_WR_DATA(Xpos >> 8);LCD_WR_REG(lcddev.setxcmd + 1);LCD_WR_DATA(Xpos & 0XFF);LCD_WR_REG(lcddev.setycmd);LCD_WR_DATA(Ypos >> 8);LCD_WR_REG(lcddev.setycmd + 1);LCD_WR_DATA(Ypos & 0XFF);}else     // 9341/5310/7789/7796/9806 等设置坐标{LCD_WR_REG(lcddev.setxcmd);LCD_WR_DATA(Xpos >> 8);LCD_WR_DATA(Xpos & 0XFF);LCD_WR_REG(lcddev.setycmd);LCD_WR_DATA(Ypos >> 8);LCD_WR_DATA(Ypos & 0XFF);}
}
//设置LCD的自动扫描方向(对RGB屏无效)
//注意:其他函数可能会受到此函数设置的影响(尤其是9341),
//所以,一般设置为L2R_U2D即可,如果设置为其他扫描方式,可能导致显示不正常.
//dir:0~7,代表8个方向(具体定义见lcd.h)
//9341/5310/5510/1963/7789等IC已经实际测试
void LCD_Scan_Dir(u8 dir)
{u16 regval = 0;u16 dirreg = 0;u16 temp;//横屏时,对1963不改变扫描方向!竖屏时1963改变方向if ((lcddev.dir == 1 && lcddev.id != 0X1963) || (lcddev.dir == 0 && lcddev.id == 0X1963)) {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;}}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;if (lcddev.id == 0X5510)dirreg = 0X3600;if (lcddev.id == 0X9341 || lcddev.id == 0X7789 || lcddev.id == 0x7796)   //9341 & 7789 &7796 要设置BGR位{regval |= 0X08;}LCD_WriteReg(dirreg, regval);if (lcddev.id != 0X1963) //1963不做坐标处理{if (regval & 0X20){if (lcddev.width < lcddev.height) //交换X,Y{temp = lcddev.width;lcddev.width = lcddev.height;lcddev.height = temp;}}else{if (lcddev.width > lcddev.height) //交换X,Y{temp = lcddev.width;lcddev.width = lcddev.height;lcddev.height = temp;}}}if (lcddev.id == 0X5510){LCD_WR_REG(lcddev.setxcmd);LCD_WR_DATA(0);LCD_WR_REG(lcddev.setxcmd + 1);LCD_WR_DATA(0);LCD_WR_REG(lcddev.setxcmd + 2);LCD_WR_DATA((lcddev.width - 1) >> 8);LCD_WR_REG(lcddev.setxcmd + 3);LCD_WR_DATA((lcddev.width - 1) & 0XFF);LCD_WR_REG(lcddev.setycmd);LCD_WR_DATA(0);LCD_WR_REG(lcddev.setycmd + 1);LCD_WR_DATA(0);LCD_WR_REG(lcddev.setycmd + 2);LCD_WR_DATA((lcddev.height - 1) >> 8);LCD_WR_REG(lcddev.setycmd + 3);LCD_WR_DATA((lcddev.height - 1) & 0XFF);}else{LCD_WR_REG(lcddev.setxcmd);LCD_WR_DATA(0);LCD_WR_DATA(0);LCD_WR_DATA((lcddev.width - 1) >> 8);LCD_WR_DATA((lcddev.width - 1) & 0XFF);LCD_WR_REG(lcddev.setycmd);LCD_WR_DATA(0);LCD_WR_DATA(0);LCD_WR_DATA((lcddev.height - 1) >> 8);LCD_WR_DATA((lcddev.height - 1) & 0XFF);}
}
//画点
//x,y:坐标
//POINT_COLOR:此点的颜色
void LCD_DrawPoint(u16 x, u16 y)
{LCD_SetCursor(x, y);		//设置光标位置LCD_WriteRAM_Prepare();	//开始写入GRAMLCD->LCD_RAM = POINT_COLOR;
}
//快速画点
//x,y:坐标
//color:颜色
void LCD_Fast_DrawPoint(u16 x, u16 y, u32 color)
{if (lcddev.id == 0X5510){LCD_WR_REG(lcddev.setxcmd);LCD_WR_DATA(x >> 8);LCD_WR_REG(lcddev.setxcmd + 1);LCD_WR_DATA(x & 0XFF);LCD_WR_REG(lcddev.setycmd);LCD_WR_DATA(y >> 8);LCD_WR_REG(lcddev.setycmd + 1);LCD_WR_DATA(y & 0XFF);}else if (lcddev.id == 0X1963){if (lcddev.dir == 0)x = lcddev.width - 1 - x;LCD_WR_REG(lcddev.setxcmd);LCD_WR_DATA(x >> 8);LCD_WR_DATA(x & 0XFF);LCD_WR_DATA(x >> 8);LCD_WR_DATA(x & 0XFF);LCD_WR_REG(lcddev.setycmd);LCD_WR_DATA(y >> 8);LCD_WR_DATA(y & 0XFF);LCD_WR_DATA(y >> 8);LCD_WR_DATA(y & 0XFF);}else     //9341/5310/7789等设置坐标{LCD_WR_REG(lcddev.setxcmd);LCD_WR_DATA(x >> 8);LCD_WR_DATA(x & 0XFF);LCD_WR_REG(lcddev.setycmd);LCD_WR_DATA(y >> 8);LCD_WR_DATA(y & 0XFF);}LCD->LCD_REG=lcddev.wramcmd; LCD->LCD_RAM=color; 
}
//SSD1963 背光设置
//pwm:背光等级,0~100.越大越亮.
void LCD_SSD_BackLightSet(u8 pwm)
{LCD_WR_REG(0xBE);	//配置PWM输出LCD_WR_DATA(0x05);	//1设置PWM频率LCD_WR_DATA(pwm * 2.55); //2设置PWM占空比LCD_WR_DATA(0x01);	//3设置CLCD_WR_DATA(0xFF);	//4设置DLCD_WR_DATA(0x00);	//5设置ELCD_WR_DATA(0x00);	//6设置F
}//设置LCD显示方向
//dir:0,竖屏;1,横屏
void LCD_Display_Dir(u8 dir)
{lcddev.dir = dir;       //竖屏/横屏if (dir == 0)           //竖屏{lcddev.width = 240;lcddev.height = 320;if (lcddev.id == 0x5510){lcddev.wramcmd = 0X2C00;lcddev.setxcmd = 0X2A00;lcddev.setycmd = 0X2B00;lcddev.width = 480;lcddev.height = 800;}else if (lcddev.id == 0X1963){lcddev.wramcmd = 0X2C;  //设置写入GRAM的指令lcddev.setxcmd = 0X2B;  //设置写X坐标指令lcddev.setycmd = 0X2A;  //设置写Y坐标指令lcddev.width = 480;     //设置宽度480lcddev.height = 800;    //设置高度800}else                        //其他IC, 包括:  9341/5310/7789/7796/9806等IC{lcddev.wramcmd = 0X2C;lcddev.setxcmd = 0X2A;lcddev.setycmd = 0X2B;}if (lcddev.id == 0X5310 || lcddev.id == 0x7796)    //如果是5310/7796  则表示是 320*480分辨率{lcddev.width = 320;lcddev.height = 480;}if (lcddev.id == 0X9806)    // 如果是9806 则表示是 480*800 分辨率 {lcddev.width = 480;lcddev.height = 800;}  }else     //横屏{lcddev.width = 320;lcddev.height = 240;if (lcddev.id == 0x5510){lcddev.wramcmd = 0X2C00;lcddev.setxcmd = 0X2A00;lcddev.setycmd = 0X2B00;lcddev.width = 800;lcddev.height = 480;}else if (lcddev.id == 0X1963 || lcddev.id == 0x9806){lcddev.wramcmd = 0X2C;  //设置写入GRAM的指令lcddev.setxcmd = 0X2A;  //设置写X坐标指令lcddev.setycmd = 0X2B;  //设置写Y坐标指令lcddev.width = 800;     //设置宽度800lcddev.height = 480;    //设置高度480}else                        //其他IC, 包括: 9341/5310/7789/7796等IC{lcddev.wramcmd = 0X2C;lcddev.setxcmd = 0X2A;lcddev.setycmd = 0X2B;}if (lcddev.id == 0X5310 || lcddev.id == 0x7796)    //如果是5310/7796 则表示是 320*480分辨率{lcddev.width = 480;lcddev.height = 320;}}LCD_Scan_Dir(DFT_SCAN_DIR);     //默认扫描方向
}//设置窗口(对RGB屏无效),并自动设置画点坐标到窗口左上角(sx,sy).
//sx,sy:窗口起始坐标(左上角)
//width,height:窗口宽度和高度,必须大于0!!
//窗体大小:width*height.
void LCD_Set_Window(u16 sx, u16 sy, u16 width, u16 height)
{u16 twidth, theight;twidth = sx + width - 1;theight = sy + height - 1;if (lcddev.id == 0X1963 && lcddev.dir != 1)     //1963竖屏特殊处理{sx = lcddev.width - width - sx;height = sy + height - 1;LCD_WR_REG(lcddev.setxcmd);LCD_WR_DATA(sx >> 8);LCD_WR_DATA(sx & 0XFF);LCD_WR_DATA((sx + width - 1) >> 8);LCD_WR_DATA((sx + width - 1) & 0XFF);LCD_WR_REG(lcddev.setycmd);LCD_WR_DATA(sy >> 8);LCD_WR_DATA(sy & 0XFF);LCD_WR_DATA(height >> 8);LCD_WR_DATA(height & 0XFF);}else if (lcddev.id == 0X5510){LCD_WR_REG(lcddev.setxcmd);LCD_WR_DATA(sx >> 8);LCD_WR_REG(lcddev.setxcmd + 1);LCD_WR_DATA(sx & 0XFF);LCD_WR_REG(lcddev.setxcmd + 2);LCD_WR_DATA(twidth >> 8);LCD_WR_REG(lcddev.setxcmd + 3);LCD_WR_DATA(twidth & 0XFF);LCD_WR_REG(lcddev.setycmd);LCD_WR_DATA(sy >> 8);LCD_WR_REG(lcddev.setycmd + 1);LCD_WR_DATA(sy & 0XFF);LCD_WR_REG(lcddev.setycmd + 2);LCD_WR_DATA(theight >> 8);LCD_WR_REG(lcddev.setycmd + 3);LCD_WR_DATA(theight & 0XFF);}else     //9341/5310/7789/1963/7796/9806横屏 等 设置窗口{LCD_WR_REG(lcddev.setxcmd);LCD_WR_DATA(sx >> 8);LCD_WR_DATA(sx & 0XFF);LCD_WR_DATA(twidth >> 8);LCD_WR_DATA(twidth & 0XFF);LCD_WR_REG(lcddev.setycmd);LCD_WR_DATA(sy >> 8);LCD_WR_DATA(sy & 0XFF);LCD_WR_DATA(theight >> 8);LCD_WR_DATA(theight & 0XFF);}
}
//SRAM底层驱动,时钟使能,引脚分配
//此函数会被HAL_SRAM_Init()调用
//hsram:SRAM句柄
void HAL_SRAM_MspInit(SRAM_HandleTypeDef *hsram)
{GPIO_InitTypeDef GPIO_Initure;__HAL_RCC_FMC_CLK_ENABLE();				//使能FMC时钟__HAL_RCC_GPIOD_CLK_ENABLE();			//使能GPIOD时钟__HAL_RCC_GPIOE_CLK_ENABLE();			//使能GPIOE时钟//初始化PD0,1,4,5,7,8,9,10,13,14,15GPIO_Initure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_7 | GPIO_PIN_8 | \GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;GPIO_Initure.Mode = GPIO_MODE_AF_PP; 		//推挽复用GPIO_Initure.Pull = GPIO_PULLUP;			//上拉GPIO_Initure.Speed = GPIO_SPEED_HIGH;		//高速GPIO_Initure.Alternate = GPIO_AF12_FMC;	//复用为FMCHAL_GPIO_Init(GPIOD, &GPIO_Initure);    //初始化//初始化PE7,8,9,10,11,12,13,14,15GPIO_Initure.Pin = GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | \GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;HAL_GPIO_Init(GPIOE, &GPIO_Initure);
}//初始化lcd
//该初始化函数可以初始化各种型号的LCD(详见本.c文件最前面的描述)
void LCD_Init(void)
{GPIO_InitTypeDef GPIO_Initure;FMC_NORSRAM_TimingTypeDef FMC_ReadWriteTim;FMC_NORSRAM_TimingTypeDef FMC_WriteTim;__HAL_RCC_GPIOB_CLK_ENABLE();			//开启GPIOB时钟GPIO_Initure.Pin = GPIO_PIN_5;          //PB5,背光控制GPIO_Initure.Mode = GPIO_MODE_OUTPUT_PP; //推挽输出GPIO_Initure.Pull = GPIO_PULLUP;        //上拉GPIO_Initure.Speed = GPIO_SPEED_HIGH;   //高速HAL_GPIO_Init(GPIOB, &GPIO_Initure);SRAM_Handler.Instance = FMC_NORSRAM_DEVICE;SRAM_Handler.Extended = FMC_NORSRAM_EXTENDED_DEVICE;SRAM_Handler.Init.NSBank = FMC_NORSRAM_BANK1;   //使用NE1SRAM_Handler.Init.DataAddressMux = FMC_DATA_ADDRESS_MUX_DISABLE; //地址/数据线不复用SRAM_Handler.Init.MemoryType = FMC_MEMORY_TYPE_SRAM; //SRAMSRAM_Handler.Init.MemoryDataWidth = FMC_NORSRAM_MEM_BUS_WIDTH_16; //16位数据宽度SRAM_Handler.Init.BurstAccessMode = FMC_BURST_ACCESS_MODE_DISABLE; //是否使能突发访问,仅对同步突发存储器有效,此处未用到SRAM_Handler.Init.WaitSignalPolarity = FMC_WAIT_SIGNAL_POLARITY_LOW; //等待信号的极性,仅在突发模式访问下有用SRAM_Handler.Init.WaitSignalActive = FMC_WAIT_TIMING_BEFORE_WS; //存储器是在等待周期之前的一个时钟周期还是等待周期期间使能NWAITSRAM_Handler.Init.WriteOperation = FMC_WRITE_OPERATION_ENABLE;  //存储器写使能SRAM_Handler.Init.WaitSignal = FMC_WAIT_SIGNAL_DISABLE;         //等待使能位,此处未用到SRAM_Handler.Init.ExtendedMode = FMC_EXTENDED_MODE_ENABLE;      //读写使用不同的时序SRAM_Handler.Init.AsynchronousWait = FMC_ASYNCHRONOUS_WAIT_DISABLE; //是否使能同步传输模式下的等待信号,此处未用到SRAM_Handler.Init.WriteBurst = FMC_WRITE_BURST_DISABLE;         //禁止突发写SRAM_Handler.Init.ContinuousClock = FMC_CONTINUOUS_CLOCK_SYNC_ASYNC;//FMC读时序控制寄存器FMC_ReadWriteTim.AddressSetupTime = 0x0F;      //地址建立时间(ADDSET)为15个HCLK 1/180M*15=5.5ns*15=82.5nsFMC_ReadWriteTim.AddressHoldTime = 0x00;FMC_ReadWriteTim.DataSetupTime = 0x46;         //数据保存时间(DATAST)为70个HCLK	=5.5*70=385nsFMC_ReadWriteTim.AccessMode = FMC_ACCESS_MODE_A; //模式A//FMC写时序控制寄存器FMC_WriteTim.AddressSetupTime = 0x0F;          //地址建立时间(ADDSET)为15个HCLK=82.5nsFMC_WriteTim.AddressHoldTime = 0x00;FMC_WriteTim.DataSetupTime = 0x0F;             //数据保存时间(DATAST)为5.5ns*15个HCLK=82.5nsFMC_WriteTim.AccessMode = FMC_ACCESS_MODE_A;   //模式AHAL_SRAM_Init(&SRAM_Handler, &FMC_ReadWriteTim, &FMC_WriteTim);delay_ms(50); // delay 50 ms//尝试9341 ID的读取LCD_WR_REG(0XD3);lcddev.id = LCD_RD_DATA();	//dummy readlcddev.id = LCD_RD_DATA();	//读到0X00lcddev.id = LCD_RD_DATA();   	//读取93lcddev.id <<= 8;lcddev.id |= LCD_RD_DATA();  	//读取41if (lcddev.id != 0X9341)		//非9341,尝试看看是不是NT35310{LCD_WR_REG(0X04);lcddev.id = LCD_RD_DATA();      //dummy readlcddev.id = LCD_RD_DATA();      //读到0X85lcddev.id = LCD_RD_DATA();      //读取0X85lcddev.id <<= 8;lcddev.id |= LCD_RD_DATA();     //读取0X52if (lcddev.id == 0X8552)        //将8552的ID转换成7789{lcddev.id = 0x7789;}if (lcddev.id != 0x7789)        //也不是ST7789, 尝试是不是 NT35310{LCD_WR_REG(0XD4);lcddev.id = LCD_RD_DATA(); //dummy readlcddev.id = LCD_RD_DATA(); //读回0X01lcddev.id = LCD_RD_DATA(); //读回0X53lcddev.id <<= 8;lcddev.id |= LCD_RD_DATA();	//这里读回0X10if (lcddev.id != 0X5310)    //也不是NT35310,尝试看看是不是NT35510{LCD_WR_REG(0XD3);lcddev.id = LCD_RD_DATA();  /* dummy read */lcddev.id = LCD_RD_DATA();  /* 读到0X00 */lcddev.id = LCD_RD_DATA();  /* 读取0X77 */lcddev.id <<= 8;lcddev.id |= LCD_RD_DATA(); /* 读取0X96 */if (lcddev.id != 0x7796)    /* 也不是ST7796,尝试看看是不是NT35510 */{//发送秘钥(厂家提供,照搬即可)LCD_WriteReg(0xF000, 0x0055);LCD_WriteReg(0xF001, 0x00AA);LCD_WriteReg(0xF002, 0x0052);LCD_WriteReg(0xF003, 0x0008);LCD_WriteReg(0xF004, 0x0001);LCD_WR_REG(0xC500);             //读取ID高8位lcddev.id = LCD_RD_DATA();      //读回0X55lcddev.id <<= 8;LCD_WR_REG(0xC501);             //读取ID低8位lcddev.id |= LCD_RD_DATA();     //读回0X10delay_ms(5);if (lcddev.id != 0X5510)        //也不是NT5510,尝试看看是不是SSD1963{LCD_WR_REG(0XD3);lcddev.id = LCD_RD_DATA();  /* dummy read */lcddev.id = LCD_RD_DATA();  /* 读回0X00 */lcddev.id = LCD_RD_DATA();  /* 读回0X98 */lcddev.id <<= 8;lcddev.id |= LCD_RD_DATA(); /* 读回0X06 */if (lcddev.id != 0x9806)    /* 也不是ILI9806,尝试看看是不是SSD1963 */{LCD_WR_REG(0XA1);lcddev.id = LCD_RD_DATA();lcddev.id = LCD_RD_DATA();  //读回0X57lcddev.id <<= 8;lcddev.id |= LCD_RD_DATA(); //读回0X61if (lcddev.id == 0X5761)lcddev.id = 0X1963; //SSD1963读回的ID是5761H,为方便区分,我们强制设置为1963}}}}}}if (lcddev.id == 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 controlLCD_WR_DATA(0x1B);   //VRH[5:0]LCD_WR_REG(0xC1);    //Power controlLCD_WR_DATA(0x01);   //SAP[2:0];BT[3:0]LCD_WR_REG(0xC5);    //VCM controlLCD_WR_DATA(0x30); 	 //3FLCD_WR_DATA(0x30); 	 //3CLCD_WR_REG(0xC7);    //VCM control2LCD_WR_DATA(0XB7);LCD_WR_REG(0x36);    // Memory Access ControlLCD_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 ControlLCD_WR_DATA(0x0A);LCD_WR_DATA(0xA2);LCD_WR_REG(0xF2);    // 3Gamma Function DisableLCD_WR_DATA(0x00);LCD_WR_REG(0x26);    //Gamma curve selectedLCD_WR_DATA(0x01);LCD_WR_REG(0xE0);    //Set GammaLCD_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 GammaLCD_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 Sleepdelay_ms(120);LCD_WR_REG(0x29); //display on}else if (lcddev.id == 0x7789)   //7789初始化{LCD_WR_REG(0x11);delay_ms(120);LCD_WR_REG(0x36);LCD_WR_DATA(0x00);LCD_WR_REG(0x3A);LCD_WR_DATA(0X05);LCD_WR_REG(0xB2);LCD_WR_DATA(0x0C);LCD_WR_DATA(0x0C);LCD_WR_DATA(0x00);LCD_WR_DATA(0x33);LCD_WR_DATA(0x33);LCD_WR_REG(0xB7);LCD_WR_DATA(0x35);LCD_WR_REG(0xBB);       //vcomLCD_WR_DATA(0x32);      //30LCD_WR_REG(0xC0);LCD_WR_DATA(0x0C);LCD_WR_REG(0xC2);LCD_WR_DATA(0x01);LCD_WR_REG(0xC3);       //vrhLCD_WR_DATA(0x10);      //17 0DLCD_WR_REG(0xC4);       //vdvLCD_WR_DATA(0x20);      //20LCD_WR_REG(0xC6);LCD_WR_DATA(0x0f);LCD_WR_REG(0xD0);LCD_WR_DATA(0xA4);LCD_WR_DATA(0xA1);LCD_WR_REG(0xE0);       //Set GammaLCD_WR_DATA(0xd0);LCD_WR_DATA(0x00);LCD_WR_DATA(0x02);LCD_WR_DATA(0x07);LCD_WR_DATA(0x0a);LCD_WR_DATA(0x28);LCD_WR_DATA(0x32);LCD_WR_DATA(0X44);LCD_WR_DATA(0x42);LCD_WR_DATA(0x06);LCD_WR_DATA(0x0e);LCD_WR_DATA(0x12);LCD_WR_DATA(0x14);LCD_WR_DATA(0x17);LCD_WR_REG(0XE1);       //Set GammaLCD_WR_DATA(0xd0);LCD_WR_DATA(0x00);LCD_WR_DATA(0x02);LCD_WR_DATA(0x07);LCD_WR_DATA(0x0a);LCD_WR_DATA(0x28);LCD_WR_DATA(0x31);LCD_WR_DATA(0x54);LCD_WR_DATA(0x47);LCD_WR_DATA(0x0e);LCD_WR_DATA(0x1c);LCD_WR_DATA(0x17);LCD_WR_DATA(0x1b);LCD_WR_DATA(0x1e);LCD_WR_REG(0x2A);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0xef);LCD_WR_REG(0x2B);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x01);LCD_WR_DATA(0x3f);LCD_WR_REG(0x29);       //display on}else if (lcddev.id == 0x5310){LCD_WR_REG(0xED);LCD_WR_DATA(0x01);LCD_WR_DATA(0xFE);LCD_WR_REG(0xEE);LCD_WR_DATA(0xDE);LCD_WR_DATA(0x21);LCD_WR_REG(0xF1);LCD_WR_DATA(0x01);LCD_WR_REG(0xDF);LCD_WR_DATA(0x10);//VCOMvoltage//LCD_WR_REG(0xC4);LCD_WR_DATA(0x8F);	  //5fLCD_WR_REG(0xC6);LCD_WR_DATA(0x00);LCD_WR_DATA(0xE2);LCD_WR_DATA(0xE2);LCD_WR_DATA(0xE2);LCD_WR_REG(0xBF);LCD_WR_DATA(0xAA);LCD_WR_REG(0xB0);LCD_WR_DATA(0x0D);LCD_WR_DATA(0x00);LCD_WR_DATA(0x0D);LCD_WR_DATA(0x00);LCD_WR_DATA(0x11);LCD_WR_DATA(0x00);LCD_WR_DATA(0x19);LCD_WR_DATA(0x00);LCD_WR_DATA(0x21);LCD_WR_DATA(0x00);LCD_WR_DATA(0x2D);LCD_WR_DATA(0x00);LCD_WR_DATA(0x3D);LCD_WR_DATA(0x00);LCD_WR_DATA(0x5D);LCD_WR_DATA(0x00);LCD_WR_DATA(0x5D);LCD_WR_DATA(0x00);LCD_WR_REG(0xB1);LCD_WR_DATA(0x80);LCD_WR_DATA(0x00);LCD_WR_DATA(0x8B);LCD_WR_DATA(0x00);LCD_WR_DATA(0x96);LCD_WR_DATA(0x00);LCD_WR_REG(0xB2);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x02);LCD_WR_DATA(0x00);LCD_WR_DATA(0x03);LCD_WR_DATA(0x00);LCD_WR_REG(0xB3);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_REG(0xB4);LCD_WR_DATA(0x8B);LCD_WR_DATA(0x00);LCD_WR_DATA(0x96);LCD_WR_DATA(0x00);LCD_WR_DATA(0xA1);LCD_WR_DATA(0x00);LCD_WR_REG(0xB5);LCD_WR_DATA(0x02);LCD_WR_DATA(0x00);LCD_WR_DATA(0x03);LCD_WR_DATA(0x00);LCD_WR_DATA(0x04);LCD_WR_DATA(0x00);LCD_WR_REG(0xB6);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_REG(0xB7);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x3F);LCD_WR_DATA(0x00);LCD_WR_DATA(0x5E);LCD_WR_DATA(0x00);LCD_WR_DATA(0x64);LCD_WR_DATA(0x00);LCD_WR_DATA(0x8C);LCD_WR_DATA(0x00);LCD_WR_DATA(0xAC);LCD_WR_DATA(0x00);LCD_WR_DATA(0xDC);LCD_WR_DATA(0x00);LCD_WR_DATA(0x70);LCD_WR_DATA(0x00);LCD_WR_DATA(0x90);LCD_WR_DATA(0x00);LCD_WR_DATA(0xEB);LCD_WR_DATA(0x00);LCD_WR_DATA(0xDC);LCD_WR_DATA(0x00);LCD_WR_REG(0xB8);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_REG(0xBA);LCD_WR_DATA(0x24);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_REG(0xC1);LCD_WR_DATA(0x20);LCD_WR_DATA(0x00);LCD_WR_DATA(0x54);LCD_WR_DATA(0x00);LCD_WR_DATA(0xFF);LCD_WR_DATA(0x00);LCD_WR_REG(0xC2);LCD_WR_DATA(0x0A);LCD_WR_DATA(0x00);LCD_WR_DATA(0x04);LCD_WR_DATA(0x00);LCD_WR_REG(0xC3);LCD_WR_DATA(0x3C);LCD_WR_DATA(0x00);LCD_WR_DATA(0x3A);LCD_WR_DATA(0x00);LCD_WR_DATA(0x39);LCD_WR_DATA(0x00);LCD_WR_DATA(0x37);LCD_WR_DATA(0x00);LCD_WR_DATA(0x3C);LCD_WR_DATA(0x00);LCD_WR_DATA(0x36);LCD_WR_DATA(0x00);LCD_WR_DATA(0x32);LCD_WR_DATA(0x00);LCD_WR_DATA(0x2F);LCD_WR_DATA(0x00);LCD_WR_DATA(0x2C);LCD_WR_DATA(0x00);LCD_WR_DATA(0x29);LCD_WR_DATA(0x00);LCD_WR_DATA(0x26);LCD_WR_DATA(0x00);LCD_WR_DATA(0x24);LCD_WR_DATA(0x00);LCD_WR_DATA(0x24);LCD_WR_DATA(0x00);LCD_WR_DATA(0x23);LCD_WR_DATA(0x00);LCD_WR_DATA(0x3C);LCD_WR_DATA(0x00);LCD_WR_DATA(0x36);LCD_WR_DATA(0x00);LCD_WR_DATA(0x32);LCD_WR_DATA(0x00);LCD_WR_DATA(0x2F);LCD_WR_DATA(0x00);LCD_WR_DATA(0x2C);LCD_WR_DATA(0x00);LCD_WR_DATA(0x29);LCD_WR_DATA(0x00);LCD_WR_DATA(0x26);LCD_WR_DATA(0x00);LCD_WR_DATA(0x24);LCD_WR_DATA(0x00);LCD_WR_DATA(0x24);LCD_WR_DATA(0x00);LCD_WR_DATA(0x23);LCD_WR_DATA(0x00);LCD_WR_REG(0xC4);LCD_WR_DATA(0x62);LCD_WR_DATA(0x00);LCD_WR_DATA(0x05);LCD_WR_DATA(0x00);LCD_WR_DATA(0x84);LCD_WR_DATA(0x00);LCD_WR_DATA(0xF0);LCD_WR_DATA(0x00);LCD_WR_DATA(0x18);LCD_WR_DATA(0x00);LCD_WR_DATA(0xA4);LCD_WR_DATA(0x00);LCD_WR_DATA(0x18);LCD_WR_DATA(0x00);LCD_WR_DATA(0x50);LCD_WR_DATA(0x00);LCD_WR_DATA(0x0C);LCD_WR_DATA(0x00);LCD_WR_DATA(0x17);LCD_WR_DATA(0x00);LCD_WR_DATA(0x95);LCD_WR_DATA(0x00);LCD_WR_DATA(0xF3);LCD_WR_DATA(0x00);LCD_WR_DATA(0xE6);LCD_WR_DATA(0x00);LCD_WR_REG(0xC5);LCD_WR_DATA(0x32);LCD_WR_DATA(0x00);LCD_WR_DATA(0x44);LCD_WR_DATA(0x00);LCD_WR_DATA(0x65);LCD_WR_DATA(0x00);LCD_WR_DATA(0x76);LCD_WR_DATA(0x00);LCD_WR_DATA(0x88);LCD_WR_DATA(0x00);LCD_WR_REG(0xC6);LCD_WR_DATA(0x20);LCD_WR_DATA(0x00);LCD_WR_DATA(0x17);LCD_WR_DATA(0x00);LCD_WR_DATA(0x01);LCD_WR_DATA(0x00);LCD_WR_REG(0xC7);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_REG(0xC8);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_REG(0xC9);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_REG(0xE0);LCD_WR_DATA(0x16);LCD_WR_DATA(0x00);LCD_WR_DATA(0x1C);LCD_WR_DATA(0x00);LCD_WR_DATA(0x21);LCD_WR_DATA(0x00);LCD_WR_DATA(0x36);LCD_WR_DATA(0x00);LCD_WR_DATA(0x46);LCD_WR_DATA(0x00);LCD_WR_DATA(0x52);LCD_WR_DATA(0x00);LCD_WR_DATA(0x64);LCD_WR_DATA(0x00);LCD_WR_DATA(0x7A);LCD_WR_DATA(0x00);LCD_WR_DATA(0x8B);LCD_WR_DATA(0x00);LCD_WR_DATA(0x99);LCD_WR_DATA(0x00);LCD_WR_DATA(0xA8);LCD_WR_DATA(0x00);LCD_WR_DATA(0xB9);LCD_WR_DATA(0x00);LCD_WR_DATA(0xC4);LCD_WR_DATA(0x00);LCD_WR_DATA(0xCA);LCD_WR_DATA(0x00);LCD_WR_DATA(0xD2);LCD_WR_DATA(0x00);LCD_WR_DATA(0xD9);LCD_WR_DATA(0x00);LCD_WR_DATA(0xE0);LCD_WR_DATA(0x00);LCD_WR_DATA(0xF3);LCD_WR_DATA(0x00);LCD_WR_REG(0xE1);LCD_WR_DATA(0x16);LCD_WR_DATA(0x00);LCD_WR_DATA(0x1C);LCD_WR_DATA(0x00);LCD_WR_DATA(0x22);LCD_WR_DATA(0x00);LCD_WR_DATA(0x36);LCD_WR_DATA(0x00);LCD_WR_DATA(0x45);LCD_WR_DATA(0x00);LCD_WR_DATA(0x52);LCD_WR_DATA(0x00);LCD_WR_DATA(0x64);LCD_WR_DATA(0x00);LCD_WR_DATA(0x7A);LCD_WR_DATA(0x00);LCD_WR_DATA(0x8B);LCD_WR_DATA(0x00);LCD_WR_DATA(0x99);LCD_WR_DATA(0x00);LCD_WR_DATA(0xA8);LCD_WR_DATA(0x00);LCD_WR_DATA(0xB9);LCD_WR_DATA(0x00);LCD_WR_DATA(0xC4);LCD_WR_DATA(0x00);LCD_WR_DATA(0xCA);LCD_WR_DATA(0x00);LCD_WR_DATA(0xD2);LCD_WR_DATA(0x00);LCD_WR_DATA(0xD8);LCD_WR_DATA(0x00);LCD_WR_DATA(0xE0);LCD_WR_DATA(0x00);LCD_WR_DATA(0xF3);LCD_WR_DATA(0x00);LCD_WR_REG(0xE2);LCD_WR_DATA(0x05);LCD_WR_DATA(0x00);LCD_WR_DATA(0x0B);LCD_WR_DATA(0x00);LCD_WR_DATA(0x1B);LCD_WR_DATA(0x00);LCD_WR_DATA(0x34);LCD_WR_DATA(0x00);LCD_WR_DATA(0x44);LCD_WR_DATA(0x00);LCD_WR_DATA(0x4F);LCD_WR_DATA(0x00);LCD_WR_DATA(0x61);LCD_WR_DATA(0x00);LCD_WR_DATA(0x79);LCD_WR_DATA(0x00);LCD_WR_DATA(0x88);LCD_WR_DATA(0x00);LCD_WR_DATA(0x97);LCD_WR_DATA(0x00);LCD_WR_DATA(0xA6);LCD_WR_DATA(0x00);LCD_WR_DATA(0xB7);LCD_WR_DATA(0x00);LCD_WR_DATA(0xC2);LCD_WR_DATA(0x00);LCD_WR_DATA(0xC7);LCD_WR_DATA(0x00);LCD_WR_DATA(0xD1);LCD_WR_DATA(0x00);LCD_WR_DATA(0xD6);LCD_WR_DATA(0x00);LCD_WR_DATA(0xDD);LCD_WR_DATA(0x00);LCD_WR_DATA(0xF3);LCD_WR_DATA(0x00);LCD_WR_REG(0xE3);LCD_WR_DATA(0x05);LCD_WR_DATA(0x00);LCD_WR_DATA(0xA);LCD_WR_DATA(0x00);LCD_WR_DATA(0x1C);LCD_WR_DATA(0x00);LCD_WR_DATA(0x33);LCD_WR_DATA(0x00);LCD_WR_DATA(0x44);LCD_WR_DATA(0x00);LCD_WR_DATA(0x50);LCD_WR_DATA(0x00);LCD_WR_DATA(0x62);LCD_WR_DATA(0x00);LCD_WR_DATA(0x78);LCD_WR_DATA(0x00);LCD_WR_DATA(0x88);LCD_WR_DATA(0x00);LCD_WR_DATA(0x97);LCD_WR_DATA(0x00);LCD_WR_DATA(0xA6);LCD_WR_DATA(0x00);LCD_WR_DATA(0xB7);LCD_WR_DATA(0x00);LCD_WR_DATA(0xC2);LCD_WR_DATA(0x00);LCD_WR_DATA(0xC7);LCD_WR_DATA(0x00);LCD_WR_DATA(0xD1);LCD_WR_DATA(0x00);LCD_WR_DATA(0xD5);LCD_WR_DATA(0x00);LCD_WR_DATA(0xDD);LCD_WR_DATA(0x00);LCD_WR_DATA(0xF3);LCD_WR_DATA(0x00);LCD_WR_REG(0xE4);LCD_WR_DATA(0x01);LCD_WR_DATA(0x00);LCD_WR_DATA(0x01);LCD_WR_DATA(0x00);LCD_WR_DATA(0x02);LCD_WR_DATA(0x00);LCD_WR_DATA(0x2A);LCD_WR_DATA(0x00);LCD_WR_DATA(0x3C);LCD_WR_DATA(0x00);LCD_WR_DATA(0x4B);LCD_WR_DATA(0x00);LCD_WR_DATA(0x5D);LCD_WR_DATA(0x00);LCD_WR_DATA(0x74);LCD_WR_DATA(0x00);LCD_WR_DATA(0x84);LCD_WR_DATA(0x00);LCD_WR_DATA(0x93);LCD_WR_DATA(0x00);LCD_WR_DATA(0xA2);LCD_WR_DATA(0x00);LCD_WR_DATA(0xB3);LCD_WR_DATA(0x00);LCD_WR_DATA(0xBE);LCD_WR_DATA(0x00);LCD_WR_DATA(0xC4);LCD_WR_DATA(0x00);LCD_WR_DATA(0xCD);LCD_WR_DATA(0x00);LCD_WR_DATA(0xD3);LCD_WR_DATA(0x00);LCD_WR_DATA(0xDD);LCD_WR_DATA(0x00);LCD_WR_DATA(0xF3);LCD_WR_DATA(0x00);LCD_WR_REG(0xE5);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x02);LCD_WR_DATA(0x00);LCD_WR_DATA(0x29);LCD_WR_DATA(0x00);LCD_WR_DATA(0x3C);LCD_WR_DATA(0x00);LCD_WR_DATA(0x4B);LCD_WR_DATA(0x00);LCD_WR_DATA(0x5D);LCD_WR_DATA(0x00);LCD_WR_DATA(0x74);LCD_WR_DATA(0x00);LCD_WR_DATA(0x84);LCD_WR_DATA(0x00);LCD_WR_DATA(0x93);LCD_WR_DATA(0x00);LCD_WR_DATA(0xA2);LCD_WR_DATA(0x00);LCD_WR_DATA(0xB3);LCD_WR_DATA(0x00);LCD_WR_DATA(0xBE);LCD_WR_DATA(0x00);LCD_WR_DATA(0xC4);LCD_WR_DATA(0x00);LCD_WR_DATA(0xCD);LCD_WR_DATA(0x00);LCD_WR_DATA(0xD3);LCD_WR_DATA(0x00);LCD_WR_DATA(0xDC);LCD_WR_DATA(0x00);LCD_WR_DATA(0xF3);LCD_WR_DATA(0x00);LCD_WR_REG(0xE6);LCD_WR_DATA(0x11);LCD_WR_DATA(0x00);LCD_WR_DATA(0x34);LCD_WR_DATA(0x00);LCD_WR_DATA(0x56);LCD_WR_DATA(0x00);LCD_WR_DATA(0x76);LCD_WR_DATA(0x00);LCD_WR_DATA(0x77);LCD_WR_DATA(0x00);LCD_WR_DATA(0x66);LCD_WR_DATA(0x00);LCD_WR_DATA(0x88);LCD_WR_DATA(0x00);LCD_WR_DATA(0x99);LCD_WR_DATA(0x00);LCD_WR_DATA(0xBB);LCD_WR_DATA(0x00);LCD_WR_DATA(0x99);LCD_WR_DATA(0x00);LCD_WR_DATA(0x66);LCD_WR_DATA(0x00);LCD_WR_DATA(0x55);LCD_WR_DATA(0x00);LCD_WR_DATA(0x55);LCD_WR_DATA(0x00);LCD_WR_DATA(0x45);LCD_WR_DATA(0x00);LCD_WR_DATA(0x43);LCD_WR_DATA(0x00);LCD_WR_DATA(0x44);LCD_WR_DATA(0x00);LCD_WR_REG(0xE7);LCD_WR_DATA(0x32);LCD_WR_DATA(0x00);LCD_WR_DATA(0x55);LCD_WR_DATA(0x00);LCD_WR_DATA(0x76);LCD_WR_DATA(0x00);LCD_WR_DATA(0x66);LCD_WR_DATA(0x00);LCD_WR_DATA(0x67);LCD_WR_DATA(0x00);LCD_WR_DATA(0x67);LCD_WR_DATA(0x00);LCD_WR_DATA(0x87);LCD_WR_DATA(0x00);LCD_WR_DATA(0x99);LCD_WR_DATA(0x00);LCD_WR_DATA(0xBB);LCD_WR_DATA(0x00);LCD_WR_DATA(0x99);LCD_WR_DATA(0x00);LCD_WR_DATA(0x77);LCD_WR_DATA(0x00);LCD_WR_DATA(0x44);LCD_WR_DATA(0x00);LCD_WR_DATA(0x56);LCD_WR_DATA(0x00);LCD_WR_DATA(0x23);LCD_WR_DATA(0x00);LCD_WR_DATA(0x33);LCD_WR_DATA(0x00);LCD_WR_DATA(0x45);LCD_WR_DATA(0x00);LCD_WR_REG(0xE8);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x99);LCD_WR_DATA(0x00);LCD_WR_DATA(0x87);LCD_WR_DATA(0x00);LCD_WR_DATA(0x88);LCD_WR_DATA(0x00);LCD_WR_DATA(0x77);LCD_WR_DATA(0x00);LCD_WR_DATA(0x66);LCD_WR_DATA(0x00);LCD_WR_DATA(0x88);LCD_WR_DATA(0x00);LCD_WR_DATA(0xAA);LCD_WR_DATA(0x00);LCD_WR_DATA(0xBB);LCD_WR_DATA(0x00);LCD_WR_DATA(0x99);LCD_WR_DATA(0x00);LCD_WR_DATA(0x66);LCD_WR_DATA(0x00);LCD_WR_DATA(0x55);LCD_WR_DATA(0x00);LCD_WR_DATA(0x55);LCD_WR_DATA(0x00);LCD_WR_DATA(0x44);LCD_WR_DATA(0x00);LCD_WR_DATA(0x44);LCD_WR_DATA(0x00);LCD_WR_DATA(0x55);LCD_WR_DATA(0x00);LCD_WR_REG(0xE9);LCD_WR_DATA(0xAA);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_REG(0x00);LCD_WR_DATA(0xAA);LCD_WR_REG(0xCF);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_REG(0xF0);LCD_WR_DATA(0x00);LCD_WR_DATA(0x50);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_REG(0xF3);LCD_WR_DATA(0x00);LCD_WR_REG(0xF9);LCD_WR_DATA(0x06);LCD_WR_DATA(0x10);LCD_WR_DATA(0x29);LCD_WR_DATA(0x00);LCD_WR_REG(0x3A);LCD_WR_DATA(0x55);	//66LCD_WR_REG(0x11);delay_ms(100);LCD_WR_REG(0x29);LCD_WR_REG(0x35);LCD_WR_DATA(0x00);LCD_WR_REG(0x51);LCD_WR_DATA(0xFF);LCD_WR_REG(0x53);LCD_WR_DATA(0x2C);LCD_WR_REG(0x55);LCD_WR_DATA(0x82);LCD_WR_REG(0x2c);}else if (lcddev.id == 0x5510){LCD_WriteReg(0xF000, 0x55);LCD_WriteReg(0xF001, 0xAA);LCD_WriteReg(0xF002, 0x52);LCD_WriteReg(0xF003, 0x08);LCD_WriteReg(0xF004, 0x01);//AVDD Set AVDD 5.2VLCD_WriteReg(0xB000, 0x0D);LCD_WriteReg(0xB001, 0x0D);LCD_WriteReg(0xB002, 0x0D);//AVDD ratioLCD_WriteReg(0xB600, 0x34);LCD_WriteReg(0xB601, 0x34);LCD_WriteReg(0xB602, 0x34);//AVEE -5.2VLCD_WriteReg(0xB100, 0x0D);LCD_WriteReg(0xB101, 0x0D);LCD_WriteReg(0xB102, 0x0D);//AVEE ratioLCD_WriteReg(0xB700, 0x34);LCD_WriteReg(0xB701, 0x34);LCD_WriteReg(0xB702, 0x34);//VCL -2.5VLCD_WriteReg(0xB200, 0x00);LCD_WriteReg(0xB201, 0x00);LCD_WriteReg(0xB202, 0x00);//VCL ratioLCD_WriteReg(0xB800, 0x24);LCD_WriteReg(0xB801, 0x24);LCD_WriteReg(0xB802, 0x24);//VGH 15V (Free pump)LCD_WriteReg(0xBF00, 0x01);LCD_WriteReg(0xB300, 0x0F);LCD_WriteReg(0xB301, 0x0F);LCD_WriteReg(0xB302, 0x0F);//VGH ratioLCD_WriteReg(0xB900, 0x34);LCD_WriteReg(0xB901, 0x34);LCD_WriteReg(0xB902, 0x34);//VGL_REG -10VLCD_WriteReg(0xB500, 0x08);LCD_WriteReg(0xB501, 0x08);LCD_WriteReg(0xB502, 0x08);LCD_WriteReg(0xC200, 0x03);//VGLX ratioLCD_WriteReg(0xBA00, 0x24);LCD_WriteReg(0xBA01, 0x24);LCD_WriteReg(0xBA02, 0x24);//VGMP/VGSP 4.5V/0VLCD_WriteReg(0xBC00, 0x00);LCD_WriteReg(0xBC01, 0x78);LCD_WriteReg(0xBC02, 0x00);//VGMN/VGSN -4.5V/0VLCD_WriteReg(0xBD00, 0x00);LCD_WriteReg(0xBD01, 0x78);LCD_WriteReg(0xBD02, 0x00);//VCOMLCD_WriteReg(0xBE00, 0x00);LCD_WriteReg(0xBE01, 0x64);//Gamma SettingLCD_WriteReg(0xD100, 0x00);LCD_WriteReg(0xD101, 0x33);LCD_WriteReg(0xD102, 0x00);LCD_WriteReg(0xD103, 0x34);LCD_WriteReg(0xD104, 0x00);LCD_WriteReg(0xD105, 0x3A);LCD_WriteReg(0xD106, 0x00);LCD_WriteReg(0xD107, 0x4A);LCD_WriteReg(0xD108, 0x00);LCD_WriteReg(0xD109, 0x5C);LCD_WriteReg(0xD10A, 0x00);LCD_WriteReg(0xD10B, 0x81);LCD_WriteReg(0xD10C, 0x00);LCD_WriteReg(0xD10D, 0xA6);LCD_WriteReg(0xD10E, 0x00);LCD_WriteReg(0xD10F, 0xE5);LCD_WriteReg(0xD110, 0x01);LCD_WriteReg(0xD111, 0x13);LCD_WriteReg(0xD112, 0x01);LCD_WriteReg(0xD113, 0x54);LCD_WriteReg(0xD114, 0x01);LCD_WriteReg(0xD115, 0x82);LCD_WriteReg(0xD116, 0x01);LCD_WriteReg(0xD117, 0xCA);LCD_WriteReg(0xD118, 0x02);LCD_WriteReg(0xD119, 0x00);LCD_WriteReg(0xD11A, 0x02);LCD_WriteReg(0xD11B, 0x01);LCD_WriteReg(0xD11C, 0x02);LCD_WriteReg(0xD11D, 0x34);LCD_WriteReg(0xD11E, 0x02);LCD_WriteReg(0xD11F, 0x67);LCD_WriteReg(0xD120, 0x02);LCD_WriteReg(0xD121, 0x84);LCD_WriteReg(0xD122, 0x02);LCD_WriteReg(0xD123, 0xA4);LCD_WriteReg(0xD124, 0x02);LCD_WriteReg(0xD125, 0xB7);LCD_WriteReg(0xD126, 0x02);LCD_WriteReg(0xD127, 0xCF);LCD_WriteReg(0xD128, 0x02);LCD_WriteReg(0xD129, 0xDE);LCD_WriteReg(0xD12A, 0x02);LCD_WriteReg(0xD12B, 0xF2);LCD_WriteReg(0xD12C, 0x02);LCD_WriteReg(0xD12D, 0xFE);LCD_WriteReg(0xD12E, 0x03);LCD_WriteReg(0xD12F, 0x10);LCD_WriteReg(0xD130, 0x03);LCD_WriteReg(0xD131, 0x33);LCD_WriteReg(0xD132, 0x03);LCD_WriteReg(0xD133, 0x6D);LCD_WriteReg(0xD200, 0x00);LCD_WriteReg(0xD201, 0x33);LCD_WriteReg(0xD202, 0x00);LCD_WriteReg(0xD203, 0x34);LCD_WriteReg(0xD204, 0x00);LCD_WriteReg(0xD205, 0x3A);LCD_WriteReg(0xD206, 0x00);LCD_WriteReg(0xD207, 0x4A);LCD_WriteReg(0xD208, 0x00);LCD_WriteReg(0xD209, 0x5C);LCD_WriteReg(0xD20A, 0x00);LCD_WriteReg(0xD20B, 0x81);LCD_WriteReg(0xD20C, 0x00);LCD_WriteReg(0xD20D, 0xA6);LCD_WriteReg(0xD20E, 0x00);LCD_WriteReg(0xD20F, 0xE5);LCD_WriteReg(0xD210, 0x01);LCD_WriteReg(0xD211, 0x13);LCD_WriteReg(0xD212, 0x01);LCD_WriteReg(0xD213, 0x54);LCD_WriteReg(0xD214, 0x01);LCD_WriteReg(0xD215, 0x82);LCD_WriteReg(0xD216, 0x01);LCD_WriteReg(0xD217, 0xCA);LCD_WriteReg(0xD218, 0x02);LCD_WriteReg(0xD219, 0x00);LCD_WriteReg(0xD21A, 0x02);LCD_WriteReg(0xD21B, 0x01);LCD_WriteReg(0xD21C, 0x02);LCD_WriteReg(0xD21D, 0x34);LCD_WriteReg(0xD21E, 0x02);LCD_WriteReg(0xD21F, 0x67);LCD_WriteReg(0xD220, 0x02);LCD_WriteReg(0xD221, 0x84);LCD_WriteReg(0xD222, 0x02);LCD_WriteReg(0xD223, 0xA4);LCD_WriteReg(0xD224, 0x02);LCD_WriteReg(0xD225, 0xB7);LCD_WriteReg(0xD226, 0x02);LCD_WriteReg(0xD227, 0xCF);LCD_WriteReg(0xD228, 0x02);LCD_WriteReg(0xD229, 0xDE);LCD_WriteReg(0xD22A, 0x02);LCD_WriteReg(0xD22B, 0xF2);LCD_WriteReg(0xD22C, 0x02);LCD_WriteReg(0xD22D, 0xFE);LCD_WriteReg(0xD22E, 0x03);LCD_WriteReg(0xD22F, 0x10);LCD_WriteReg(0xD230, 0x03);LCD_WriteReg(0xD231, 0x33);LCD_WriteReg(0xD232, 0x03);LCD_WriteReg(0xD233, 0x6D);LCD_WriteReg(0xD300, 0x00);LCD_WriteReg(0xD301, 0x33);LCD_WriteReg(0xD302, 0x00);LCD_WriteReg(0xD303, 0x34);LCD_WriteReg(0xD304, 0x00);LCD_WriteReg(0xD305, 0x3A);LCD_WriteReg(0xD306, 0x00);LCD_WriteReg(0xD307, 0x4A);LCD_WriteReg(0xD308, 0x00);LCD_WriteReg(0xD309, 0x5C);LCD_WriteReg(0xD30A, 0x00);LCD_WriteReg(0xD30B, 0x81);LCD_WriteReg(0xD30C, 0x00);LCD_WriteReg(0xD30D, 0xA6);LCD_WriteReg(0xD30E, 0x00);LCD_WriteReg(0xD30F, 0xE5);LCD_WriteReg(0xD310, 0x01);LCD_WriteReg(0xD311, 0x13);LCD_WriteReg(0xD312, 0x01);LCD_WriteReg(0xD313, 0x54);LCD_WriteReg(0xD314, 0x01);LCD_WriteReg(0xD315, 0x82);LCD_WriteReg(0xD316, 0x01);LCD_WriteReg(0xD317, 0xCA);LCD_WriteReg(0xD318, 0x02);LCD_WriteReg(0xD319, 0x00);LCD_WriteReg(0xD31A, 0x02);LCD_WriteReg(0xD31B, 0x01);LCD_WriteReg(0xD31C, 0x02);LCD_WriteReg(0xD31D, 0x34);LCD_WriteReg(0xD31E, 0x02);LCD_WriteReg(0xD31F, 0x67);LCD_WriteReg(0xD320, 0x02);LCD_WriteReg(0xD321, 0x84);LCD_WriteReg(0xD322, 0x02);LCD_WriteReg(0xD323, 0xA4);LCD_WriteReg(0xD324, 0x02);LCD_WriteReg(0xD325, 0xB7);LCD_WriteReg(0xD326, 0x02);LCD_WriteReg(0xD327, 0xCF);LCD_WriteReg(0xD328, 0x02);LCD_WriteReg(0xD329, 0xDE);LCD_WriteReg(0xD32A, 0x02);LCD_WriteReg(0xD32B, 0xF2);LCD_WriteReg(0xD32C, 0x02);LCD_WriteReg(0xD32D, 0xFE);LCD_WriteReg(0xD32E, 0x03);LCD_WriteReg(0xD32F, 0x10);LCD_WriteReg(0xD330, 0x03);LCD_WriteReg(0xD331, 0x33);LCD_WriteReg(0xD332, 0x03);LCD_WriteReg(0xD333, 0x6D);LCD_WriteReg(0xD400, 0x00);LCD_WriteReg(0xD401, 0x33);LCD_WriteReg(0xD402, 0x00);LCD_WriteReg(0xD403, 0x34);LCD_WriteReg(0xD404, 0x00);LCD_WriteReg(0xD405, 0x3A);LCD_WriteReg(0xD406, 0x00);LCD_WriteReg(0xD407, 0x4A);LCD_WriteReg(0xD408, 0x00);LCD_WriteReg(0xD409, 0x5C);LCD_WriteReg(0xD40A, 0x00);LCD_WriteReg(0xD40B, 0x81);LCD_WriteReg(0xD40C, 0x00);LCD_WriteReg(0xD40D, 0xA6);LCD_WriteReg(0xD40E, 0x00);LCD_WriteReg(0xD40F, 0xE5);LCD_WriteReg(0xD410, 0x01);LCD_WriteReg(0xD411, 0x13);LCD_WriteReg(0xD412, 0x01);LCD_WriteReg(0xD413, 0x54);LCD_WriteReg(0xD414, 0x01);LCD_WriteReg(0xD415, 0x82);LCD_WriteReg(0xD416, 0x01);LCD_WriteReg(0xD417, 0xCA);LCD_WriteReg(0xD418, 0x02);LCD_WriteReg(0xD419, 0x00);LCD_WriteReg(0xD41A, 0x02);LCD_WriteReg(0xD41B, 0x01);LCD_WriteReg(0xD41C, 0x02);LCD_WriteReg(0xD41D, 0x34);LCD_WriteReg(0xD41E, 0x02);LCD_WriteReg(0xD41F, 0x67);LCD_WriteReg(0xD420, 0x02);LCD_WriteReg(0xD421, 0x84);LCD_WriteReg(0xD422, 0x02);LCD_WriteReg(0xD423, 0xA4);LCD_WriteReg(0xD424, 0x02);LCD_WriteReg(0xD425, 0xB7);LCD_WriteReg(0xD426, 0x02);LCD_WriteReg(0xD427, 0xCF);LCD_WriteReg(0xD428, 0x02);LCD_WriteReg(0xD429, 0xDE);LCD_WriteReg(0xD42A, 0x02);LCD_WriteReg(0xD42B, 0xF2);LCD_WriteReg(0xD42C, 0x02);LCD_WriteReg(0xD42D, 0xFE);LCD_WriteReg(0xD42E, 0x03);LCD_WriteReg(0xD42F, 0x10);LCD_WriteReg(0xD430, 0x03);LCD_WriteReg(0xD431, 0x33);LCD_WriteReg(0xD432, 0x03);LCD_WriteReg(0xD433, 0x6D);LCD_WriteReg(0xD500, 0x00);LCD_WriteReg(0xD501, 0x33);LCD_WriteReg(0xD502, 0x00);LCD_WriteReg(0xD503, 0x34);LCD_WriteReg(0xD504, 0x00);LCD_WriteReg(0xD505, 0x3A);LCD_WriteReg(0xD506, 0x00);LCD_WriteReg(0xD507, 0x4A);LCD_WriteReg(0xD508, 0x00);LCD_WriteReg(0xD509, 0x5C);LCD_WriteReg(0xD50A, 0x00);LCD_WriteReg(0xD50B, 0x81);LCD_WriteReg(0xD50C, 0x00);LCD_WriteReg(0xD50D, 0xA6);LCD_WriteReg(0xD50E, 0x00);LCD_WriteReg(0xD50F, 0xE5);LCD_WriteReg(0xD510, 0x01);LCD_WriteReg(0xD511, 0x13);LCD_WriteReg(0xD512, 0x01);LCD_WriteReg(0xD513, 0x54);LCD_WriteReg(0xD514, 0x01);LCD_WriteReg(0xD515, 0x82);LCD_WriteReg(0xD516, 0x01);LCD_WriteReg(0xD517, 0xCA);LCD_WriteReg(0xD518, 0x02);LCD_WriteReg(0xD519, 0x00);LCD_WriteReg(0xD51A, 0x02);LCD_WriteReg(0xD51B, 0x01);LCD_WriteReg(0xD51C, 0x02);LCD_WriteReg(0xD51D, 0x34);LCD_WriteReg(0xD51E, 0x02);LCD_WriteReg(0xD51F, 0x67);LCD_WriteReg(0xD520, 0x02);LCD_WriteReg(0xD521, 0x84);LCD_WriteReg(0xD522, 0x02);LCD_WriteReg(0xD523, 0xA4);LCD_WriteReg(0xD524, 0x02);LCD_WriteReg(0xD525, 0xB7);LCD_WriteReg(0xD526, 0x02);LCD_WriteReg(0xD527, 0xCF);LCD_WriteReg(0xD528, 0x02);LCD_WriteReg(0xD529, 0xDE);LCD_WriteReg(0xD52A, 0x02);LCD_WriteReg(0xD52B, 0xF2);LCD_WriteReg(0xD52C, 0x02);LCD_WriteReg(0xD52D, 0xFE);LCD_WriteReg(0xD52E, 0x03);LCD_WriteReg(0xD52F, 0x10);LCD_WriteReg(0xD530, 0x03);LCD_WriteReg(0xD531, 0x33);LCD_WriteReg(0xD532, 0x03);LCD_WriteReg(0xD533, 0x6D);LCD_WriteReg(0xD600, 0x00);LCD_WriteReg(0xD601, 0x33);LCD_WriteReg(0xD602, 0x00);LCD_WriteReg(0xD603, 0x34);LCD_WriteReg(0xD604, 0x00);LCD_WriteReg(0xD605, 0x3A);LCD_WriteReg(0xD606, 0x00);LCD_WriteReg(0xD607, 0x4A);LCD_WriteReg(0xD608, 0x00);LCD_WriteReg(0xD609, 0x5C);LCD_WriteReg(0xD60A, 0x00);LCD_WriteReg(0xD60B, 0x81);LCD_WriteReg(0xD60C, 0x00);LCD_WriteReg(0xD60D, 0xA6);LCD_WriteReg(0xD60E, 0x00);LCD_WriteReg(0xD60F, 0xE5);LCD_WriteReg(0xD610, 0x01);LCD_WriteReg(0xD611, 0x13);LCD_WriteReg(0xD612, 0x01);LCD_WriteReg(0xD613, 0x54);LCD_WriteReg(0xD614, 0x01);LCD_WriteReg(0xD615, 0x82);LCD_WriteReg(0xD616, 0x01);LCD_WriteReg(0xD617, 0xCA);LCD_WriteReg(0xD618, 0x02);LCD_WriteReg(0xD619, 0x00);LCD_WriteReg(0xD61A, 0x02);LCD_WriteReg(0xD61B, 0x01);LCD_WriteReg(0xD61C, 0x02);LCD_WriteReg(0xD61D, 0x34);LCD_WriteReg(0xD61E, 0x02);LCD_WriteReg(0xD61F, 0x67);LCD_WriteReg(0xD620, 0x02);LCD_WriteReg(0xD621, 0x84);LCD_WriteReg(0xD622, 0x02);LCD_WriteReg(0xD623, 0xA4);LCD_WriteReg(0xD624, 0x02);LCD_WriteReg(0xD625, 0xB7);LCD_WriteReg(0xD626, 0x02);LCD_WriteReg(0xD627, 0xCF);LCD_WriteReg(0xD628, 0x02);LCD_WriteReg(0xD629, 0xDE);LCD_WriteReg(0xD62A, 0x02);LCD_WriteReg(0xD62B, 0xF2);LCD_WriteReg(0xD62C, 0x02);LCD_WriteReg(0xD62D, 0xFE);LCD_WriteReg(0xD62E, 0x03);LCD_WriteReg(0xD62F, 0x10);LCD_WriteReg(0xD630, 0x03);LCD_WriteReg(0xD631, 0x33);LCD_WriteReg(0xD632, 0x03);LCD_WriteReg(0xD633, 0x6D);//LV2 Page 0 enableLCD_WriteReg(0xF000, 0x55);LCD_WriteReg(0xF001, 0xAA);LCD_WriteReg(0xF002, 0x52);LCD_WriteReg(0xF003, 0x08);LCD_WriteReg(0xF004, 0x00);//Display controlLCD_WriteReg(0xB100, 0xCC);LCD_WriteReg(0xB101, 0x00);//Source hold timeLCD_WriteReg(0xB600, 0x05);//Gate EQ controlLCD_WriteReg(0xB700, 0x70);LCD_WriteReg(0xB701, 0x70);//Source EQ control (Mode 2)LCD_WriteReg(0xB800, 0x01);LCD_WriteReg(0xB801, 0x03);LCD_WriteReg(0xB802, 0x03);LCD_WriteReg(0xB803, 0x03);//Inversion mode (2-dot)LCD_WriteReg(0xBC00, 0x02);LCD_WriteReg(0xBC01, 0x00);LCD_WriteReg(0xBC02, 0x00);//Timing control 4H w/ 4-delayLCD_WriteReg(0xC900, 0xD0);LCD_WriteReg(0xC901, 0x02);LCD_WriteReg(0xC902, 0x50);LCD_WriteReg(0xC903, 0x50);LCD_WriteReg(0xC904, 0x50);LCD_WriteReg(0x3500, 0x00);LCD_WriteReg(0x3A00, 0x55); //16-bit/pixelLCD_WR_REG(0x1100);delay_us(120);LCD_WR_REG(0x2900);}else if (lcddev.id == 0x7796){LCD_WR_REG(0x11);delay_ms(120); LCD_WR_REG(0x36); /* Memory Data Access Control MY,MX~~ */LCD_WR_DATA(0x48);LCD_WR_REG(0x3A);LCD_WR_DATA(0x55);LCD_WR_REG(0xF0);LCD_WR_DATA(0xC3);LCD_WR_REG(0xF0);LCD_WR_DATA(0x96);LCD_WR_REG(0xB4);LCD_WR_DATA(0x01);LCD_WR_REG(0xB6); /* Display Function Control */LCD_WR_DATA(0x0A);LCD_WR_DATA(0xA2);LCD_WR_REG(0xB7);LCD_WR_DATA(0xC6);LCD_WR_REG(0xB9);LCD_WR_DATA(0x02);LCD_WR_DATA(0xE0);LCD_WR_REG(0xC0);LCD_WR_DATA(0x80);LCD_WR_DATA(0x16);LCD_WR_REG(0xC1);LCD_WR_DATA(0x19);LCD_WR_REG(0xC2);LCD_WR_DATA(0xA7);LCD_WR_REG(0xC5);LCD_WR_DATA(0x16);   LCD_WR_REG(0xE8);LCD_WR_DATA(0x40);LCD_WR_DATA(0x8A);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x29);LCD_WR_DATA(0x19);LCD_WR_DATA(0xA5);LCD_WR_DATA(0x33);LCD_WR_REG(0xE0);LCD_WR_DATA(0xF0);LCD_WR_DATA(0x07);LCD_WR_DATA(0x0D);LCD_WR_DATA(0x04);LCD_WR_DATA(0x05);LCD_WR_DATA(0x14);LCD_WR_DATA(0x36);LCD_WR_DATA(0x54);LCD_WR_DATA(0x4C);LCD_WR_DATA(0x38);LCD_WR_DATA(0x13);LCD_WR_DATA(0x14);LCD_WR_DATA(0x2E);LCD_WR_DATA(0x34);LCD_WR_REG(0xE1);LCD_WR_DATA(0xF0);LCD_WR_DATA(0x10);LCD_WR_DATA(0x14);LCD_WR_DATA(0x0E);LCD_WR_DATA(0x0C);LCD_WR_DATA(0x08);LCD_WR_DATA(0x35);LCD_WR_DATA(0x44);LCD_WR_DATA(0x4C);LCD_WR_DATA(0x26);LCD_WR_DATA(0x10);LCD_WR_DATA(0x12);LCD_WR_DATA(0x2C);LCD_WR_DATA(0x32);LCD_WR_REG(0xF0);LCD_WR_DATA(0x3C);LCD_WR_REG(0xF0);LCD_WR_DATA(0x69);delay_ms(120);LCD_WR_REG(0x21);LCD_WR_REG(0x29);}else if (lcddev.id == 0x9806){LCD_WR_REG(0xFF); /* EXTC Command Set enable register */LCD_WR_DATA(0xFF);LCD_WR_DATA(0x98);LCD_WR_DATA(0x06);LCD_WR_REG(0xBC); /* GIP 1 */LCD_WR_DATA(0x01);LCD_WR_DATA(0x0F);LCD_WR_DATA(0x61);LCD_WR_DATA(0xFF);LCD_WR_DATA(0x01);LCD_WR_DATA(0x01);LCD_WR_DATA(0x0B);LCD_WR_DATA(0x10);LCD_WR_DATA(0x37);LCD_WR_DATA(0x63);LCD_WR_DATA(0xFF);LCD_WR_DATA(0xFF);LCD_WR_DATA(0x01);LCD_WR_DATA(0x01);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0xFF);LCD_WR_DATA(0x52);LCD_WR_DATA(0x01);LCD_WR_DATA(0x00);LCD_WR_DATA(0x40);LCD_WR_REG(0xBD); /* GIP 2 */LCD_WR_DATA(0x01);LCD_WR_DATA(0x23);LCD_WR_DATA(0x45);LCD_WR_DATA(0x67);LCD_WR_DATA(0x01);LCD_WR_DATA(0x23);LCD_WR_DATA(0x45);LCD_WR_DATA(0x67);LCD_WR_REG(0xBE); /* GIP 3 */LCD_WR_DATA(0x00);LCD_WR_DATA(0x01);LCD_WR_DATA(0xAB);LCD_WR_DATA(0x60);LCD_WR_DATA(0x22);LCD_WR_DATA(0x22);LCD_WR_DATA(0x22);LCD_WR_DATA(0x22);LCD_WR_DATA(0x22);LCD_WR_REG(0xC7); /* VCOM Control */LCD_WR_DATA(0x36);LCD_WR_REG(0xED); /* EN_volt_reg VGMP / VGMN /VGSP / VGSN voltage to output */LCD_WR_DATA(0x7F);LCD_WR_DATA(0x0F);LCD_WR_REG(0XC0); /* Power Control 1 Setting AVDD / AVEE / VGH / VGL */LCD_WR_DATA(0x0F);LCD_WR_DATA(0x0B);LCD_WR_DATA(0x0A);  /* VGH 15V,VGLO-10V */LCD_WR_REG(0XFC); /* AVDD / AVEE generated by internal pumping. */LCD_WR_DATA(0x08);LCD_WR_REG(0XDF); LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x20);LCD_WR_REG(0XF3); /* DVDD Voltage Setting */LCD_WR_DATA(0x74);LCD_WR_REG(0xB4); /* Inversion Type */LCD_WR_DATA(0x00);  /* 02 */LCD_WR_DATA(0x00);  /* 02 */LCD_WR_DATA(0x00);  /* 02 */LCD_WR_REG(0xF7); /* Resolution Control */LCD_WR_DATA(0x82);  /* 480*800 */LCD_WR_REG(0xB1); /* FRAME RATE Setting */LCD_WR_DATA(0x00);LCD_WR_DATA(0x13);LCD_WR_DATA(0x13); LCD_WR_REG(0XF2); /* CR_EQ_PC_SDT  #C0,06,40,28 */LCD_WR_DATA(0x80);LCD_WR_DATA(0x04);LCD_WR_DATA(0x40);LCD_WR_DATA(0x28);LCD_WR_REG(0XC1); /* Power Control 2  SD OP Bias_VRH1_VRH2_EXT_CPCK_SEL */LCD_WR_DATA(0x17);LCD_WR_DATA(0x88);  /* VGMP */LCD_WR_DATA(0x88);  /* VGMN */LCD_WR_DATA(0x20);LCD_WR_REG(0xE0); /* Positive Gamma Control */LCD_WR_DATA(0x00);  /* P1 */LCD_WR_DATA(0x0A);  /* P2 */LCD_WR_DATA(0x12);  /* P3 */LCD_WR_DATA(0x10);  /* P4 */LCD_WR_DATA(0x0E);  /* P5 */LCD_WR_DATA(0x20);  /* P6 */LCD_WR_DATA(0xCC);  /* P7 */LCD_WR_DATA(0x07);  /* P8 */LCD_WR_DATA(0x06);  /* P9 */LCD_WR_DATA(0x0B);  /* P10 */LCD_WR_DATA(0x0E);  /* P11 */LCD_WR_DATA(0x0F);  /* P12 */LCD_WR_DATA(0x0D);  /* P13 */LCD_WR_DATA(0x15);  /* P14 */LCD_WR_DATA(0x10);  /* P15 */LCD_WR_DATA(0x00);  /* P16 */LCD_WR_REG(0xE1); /* Negative Gamma Correction */LCD_WR_DATA(0x00);  /* P1 */LCD_WR_DATA(0x0B);  /* P2 */LCD_WR_DATA(0x13);  /* P3 */LCD_WR_DATA(0x0D);  /* P4 */LCD_WR_DATA(0x0E);  /* P5 */LCD_WR_DATA(0x1B);  /* P6 */LCD_WR_DATA(0x71);  /* P7 */LCD_WR_DATA(0x06);  /* P8 */LCD_WR_DATA(0x06);  /* P9 */LCD_WR_DATA(0x0A);  /* P10 */LCD_WR_DATA(0x0F);  /* P11 */LCD_WR_DATA(0x0E);  /* P12 */LCD_WR_DATA(0x0F);  /* P13 */LCD_WR_DATA(0x15);  /* P14 */LCD_WR_DATA(0x0C);  /* P15 */LCD_WR_DATA(0x00);  /* P16 */LCD_WR_REG(0x2a);   LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x01);LCD_WR_DATA(0xdf);LCD_WR_REG(0x2b);   LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x03);LCD_WR_DATA(0x1f);LCD_WR_REG(0x3A); /* Pixel Format */LCD_WR_DATA(0x55);LCD_WR_REG(0x36); /* Memory Access Control */LCD_WR_DATA(0x00);  /* 02-180 */LCD_WR_REG(0x11);delay_ms(120);   LCD_WR_REG(0x29);  delay_ms(20);  LCD_WR_REG(0x2C);}else if (lcddev.id == 0X1963){LCD_WR_REG(0xE2);		//Set PLL with OSC = 10MHz (hardware),	Multiplier N = 35, 250MHz < VCO < 800MHz = OSC*(N+1), VCO = 300MHzLCD_WR_DATA(0x1D);		//参数1LCD_WR_DATA(0x02);		//参数2 Divider M = 2, PLL = 300/(M+1) = 100MHzLCD_WR_DATA(0x04);		//参数3 Validate M and N valuesdelay_us(100);LCD_WR_REG(0xE0);		// Start PLL commandLCD_WR_DATA(0x01);		// enable PLLdelay_ms(10);LCD_WR_REG(0xE0);		// Start PLL command againLCD_WR_DATA(0x03);		// now, use PLL output as system clockdelay_ms(12);LCD_WR_REG(0x01);		//软复位delay_ms(10);LCD_WR_REG(0xE6);		//设置像素频率,33MhzLCD_WR_DATA(0x2F);LCD_WR_DATA(0xFF);LCD_WR_DATA(0xFF);LCD_WR_REG(0xB0);		//设置LCD模式LCD_WR_DATA(0x20);		//24位模式LCD_WR_DATA(0x00);		//TFT 模式LCD_WR_DATA((SSD_HOR_RESOLUTION - 1) >> 8); //设置LCD水平像素LCD_WR_DATA(SSD_HOR_RESOLUTION - 1);LCD_WR_DATA((SSD_VER_RESOLUTION - 1) >> 8); //设置LCD垂直像素LCD_WR_DATA(SSD_VER_RESOLUTION - 1);LCD_WR_DATA(0x00);		//RGB序列LCD_WR_REG(0xB4);		//Set horizontal periodLCD_WR_DATA((SSD_HT - 1) >> 8);LCD_WR_DATA(SSD_HT - 1);LCD_WR_DATA(SSD_HPS >> 8);LCD_WR_DATA(SSD_HPS);LCD_WR_DATA(SSD_HOR_PULSE_WIDTH - 1);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_REG(0xB6);		//Set vertical periodLCD_WR_DATA((SSD_VT - 1) >> 8);LCD_WR_DATA(SSD_VT - 1);LCD_WR_DATA(SSD_VPS >> 8);LCD_WR_DATA(SSD_VPS);LCD_WR_DATA(SSD_VER_FRONT_PORCH - 1);LCD_WR_DATA(0x00);LCD_WR_DATA(0x00);LCD_WR_REG(0xF0);	//设置SSD1963与CPU接口为16bitLCD_WR_DATA(0x03);	//16-bit(565 format) data for 16bppLCD_WR_REG(0x29);	//开启显示//设置PWM输出  背光通过占空比可调LCD_WR_REG(0xD0);	//设置自动白平衡DBCLCD_WR_DATA(0x00);	//disableLCD_WR_REG(0xBE);	//配置PWM输出LCD_WR_DATA(0x05);	//1设置PWM频率LCD_WR_DATA(0xFE);	//2设置PWM占空比LCD_WR_DATA(0x01);	//3设置CLCD_WR_DATA(0x00);	//4设置DLCD_WR_DATA(0x00);	//5设置ELCD_WR_DATA(0x00);	//6设置FLCD_WR_REG(0xB8);	//设置GPIO配置LCD_WR_DATA(0x03);	//2个IO口设置成输出LCD_WR_DATA(0x01);	//GPIO使用正常的IO功能LCD_WR_REG(0xBA);LCD_WR_DATA(0X01);	//GPIO[1:0]=01,控制LCD方向LCD_SSD_BackLightSet(100);//背光设置为最亮}//初始化完成以后,提速if (lcddev.id == 0X9341 || lcddev.id == 0X5310 || lcddev.id == 0X5510 || lcddev.id == 0X1963 || lcddev.id == 0X7789|| lcddev.id == 0X7796 || lcddev.id == 0X9806) //如果是这几个IC,则设置WR时序为最快{//重新配置写时序控制寄存器的时序FMC_Bank1E->BWTR[0] &= ~(0XF << 0);	//地址建立时间(ADDSET)清零FMC_Bank1E->BWTR[0] &= ~(0XF << 8);	//数据保存时间清零FMC_Bank1E->BWTR[0] |= 5 << 0;	 	//地址建立时间(ADDSET)为5个HCLK =21nsFMC_Bank1E->BWTR[0] |= 5 << 8; 		//数据保存时间(DATAST)为4.6ns*4个HCLK=21ns}LCD_Display_Dir(0);		//默认为竖屏LCD_LED = 1;				//点亮背光LCD_Clear(WHITE);
}
//清屏函数
//color:要清屏的填充色
void LCD_Clear(u32 color)
{u32 index = 0;u32 totalpoint = lcddev.width;totalpoint *= lcddev.height; 			//得到总点数LCD_SetCursor(0x00, 0x0000);			//设置光标位置LCD_WriteRAM_Prepare();     		//开始写入GRAMfor (index = 0; index < totalpoint; index++){LCD->LCD_RAM = color;}
}
//在指定区域内填充单个颜色
//(sx,sy),(ex,ey):填充矩形对角坐标,区域大小为:(ex-sx+1)*(ey-sy+1)
//color:要填充的颜色
void LCD_Fill(u16 sx, u16 sy, u16 ex, u16 ey, u32 color)
{u16 i, j;u16 xlen = 0;xlen = ex - sx + 1;for (i = sy; i <= ey; i++){LCD_SetCursor(sx, i);      				//设置光标位置LCD_WriteRAM_Prepare();     			//开始写入GRAMfor (j = 0; j < xlen; j++)LCD->LCD_RAM = color;	//显示颜色}
}
//在指定区域内填充指定颜色块
//(sx,sy),(ex,ey):填充矩形对角坐标,区域大小为:(ex-sx+1)*(ey-sy+1)
//color:要填充的颜色
void LCD_Color_Fill(u16 sx, u16 sy, u16 ex, u16 ey, u16 *color)
{u16 height, width;u16 i, j;width = ex - sx + 1; 			//得到填充的宽度height = ey - sy + 1;			//高度for (i = 0; i < height; i++){LCD_SetCursor(sx, sy + i);   	//设置光标位置LCD_WriteRAM_Prepare();     //开始写入GRAMfor (j = 0; j < width; j++)LCD->LCD_RAM = color[i * width + j]; //写入数据}
}
//画线
//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;}}
}
//画矩形
//(x1,y1),(x2,y2):矩形的对角坐标
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 LCD_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 + a, y0 - b);        //5LCD_DrawPoint(x0 + b, y0 - a);        //0LCD_DrawPoint(x0 + b, y0 + a);        //4LCD_DrawPoint(x0 + a, y0 + b);        //6LCD_DrawPoint(x0 - a, y0 + b);        //1LCD_DrawPoint(x0 - b, y0 + a);LCD_DrawPoint(x0 - a, y0 - b);        //2LCD_DrawPoint(x0 - b, y0 - a);        //7a++;//使用Bresenham算法画圆if (di < 0)di += 4 * a + 6;else{di += 10 + 4 * (a - b);b--;}}
}
//在指定位置显示一个字符
//x,y:起始坐标
//num:要显示的字符:" "--->"~"
//size:字体大小 12/16/24/32
//mode:叠加方式(1)还是非叠加方式(0)
void LCD_ShowChar(u16 x, u16 y, u8 num, u8 size, u8 mode)
{u8 temp, t1, t;u16 y0 = y;u8 csize = (size / 8 + ((size % 8) ? 1 : 0)) * (size / 2);		//得到字体一个字符对应点阵集所占的字节数num = num - ' '; //得到偏移后的值(ASCII字库是从空格开始取模,所以-' '就是对应字符的字库)for (t = 0; t < csize; t++){if (size == 12)temp = asc2_1206[num][t]; 	 	//调用1206字体else if (size == 16)temp = asc2_1608[num][t];	//调用1608字体else if (size == 24)temp = asc2_2412[num][t];	//调用2412字体else if (size == 32)temp = asc2_3216[num][t];	//调用3216字体else return;								//没有的字库for (t1 = 0; t1 < 8; t1++){if (temp & 0x80)LCD_Fast_DrawPoint(x, y, POINT_COLOR);else if (mode == 0)LCD_Fast_DrawPoint(x, y, BACK_COLOR);temp <<= 1;y++;if (y >= lcddev.height)return;		//超区域了if ((y - y0) == size){y = y0;x++;if (x >= lcddev.width)return;	//超区域了break;}}}
}
//m^n函数
//返回值:m^n次方.
u32 LCD_Pow(u8 m, u8 n)
{u32 result = 1;while (n--)result *= m;return result;
}
//显示数字,高位为0,则不显示
//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 / LCD_Pow(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);}
}
//显示数字,高位为0,还是显示
//x,y:起点坐标
//num:数值(0~999999999);
//len:长度(即要显示的位数)
//size:字体大小
//mode:
//[7]:0,不填充;1,填充0.
//[6:1]:保留
//[0]:0,非叠加显示;1,叠加显示.
void LCD_ShowxNum(u16 x, u16 y, u32 num, u8 len, u8 size, u8 mode)
{u8 t, temp;u8 enshow = 0;for (t = 0; t < len; t++){temp = (num / LCD_Pow(10, len - t - 1)) % 10;if (enshow == 0 && t < (len - 1)){if (temp == 0){if (mode & 0X80)LCD_ShowChar(x + (size / 2)*t, y, '0', size, mode & 0X01);else LCD_ShowChar(x + (size / 2)*t, y, ' ', size, mode & 0X01);continue;}else enshow = 1;}LCD_ShowChar(x + (size / 2)*t, y, temp + '0', size, mode & 0X01);}
}
//显示字符串
//x,y:起点坐标
//width,height:区域大小
//size:字体大小
//*p:字符串起始地址
void LCD_ShowString(u16 x, u16 y, u16 width, u16 height, u8 size, u8 *p)
{u8 x0 = x;width += x;height += y;while ((*p <= '~') && (*p >= ' ')) //判断是不是非法字符!{if (x >= width){x = x0;y += size;}if (y >= height)break; //退出LCD_ShowChar(x, y, *p, size, 0);x += size / 2;p++;}
}

lcd.h

#ifndef  __lcd_H
#define  __lcd_H#include <stdlib.h>
#include <stdio.h>
#include "fmc.h"
#include "delay.h"
#include "sys.h"//LCD重要参数集
typedef struct  
{		 	 u16 width;			//LCD 宽度u16 height;			//LCD 高度u16 id;				//LCD IDu8  dir;			//横屏还是竖屏控制:0,竖屏;1,横屏。	u16	wramcmd;		//开始写gram指令u16 setxcmd;		//设置x坐标指令u16 setycmd;		//设置y坐标指令 
}_lcd_dev;//LCD参数
extern _lcd_dev lcddev;	//管理LCD重要参数
//LCD的画笔颜色和背景色	   
extern u32  POINT_COLOR;//默认红色    
extern u32  BACK_COLOR; //背景颜色.默认为白色//	 
//-----------------MCU屏 LCD端口定义---------------- 
#define	LCD_LED PBout(5) 	//LCD背光	PB5	    
//LCD地址结构体
typedef struct
{vu16 LCD_REG;vu16 LCD_RAM;
} LCD_TypeDef;
//使用NOR/SRAM的 Bank1.sector1,地址位HADDR[27,26]=00 A18作为数据命令区分线 
//注意设置时STM32内部会右移一位对其!  			    
#define LCD_BASE        ((u32)(0x60000000 | 0x0007FFFE))
#define LCD             ((LCD_TypeDef *) LCD_BASE)
////扫描方向定义
#define L2R_U2D  0 		//从左到右,从上到下
#define L2R_D2U  1 		//从左到右,从下到上
#define R2L_U2D  2 		//从右到左,从上到下
#define R2L_D2U  3 		//从右到左,从下到上#define U2D_L2R  4 		//从上到下,从左到右
#define U2D_R2L  5 		//从上到下,从右到左
#define D2U_L2R  6 		//从下到上,从左到右
#define D2U_R2L  7		//从下到上,从右到左	 #define DFT_SCAN_DIR  L2R_U2D  //默认的扫描方向//画笔颜色
#define WHITE         	 0xFFFF
#define BLACK         	 0x0000	  
#define BLUE         	 0x001F  
#define BRED             0XF81F
#define GRED 			 0XFFE0
#define GBLUE			 0X07FF
#define RED           	 0xF800
#define MAGENTA       	 0xF81F
#define GREEN         	 0x07E0
#define CYAN          	 0x7FFF
#define YELLOW        	 0xFFE0
#define BROWN 			 0XBC40 //棕色
#define BRRED 			 0XFC07 //棕红色
#define GRAY  			 0X8430 //灰色
//GUI颜色#define DARKBLUE      	 0X01CF	//深蓝色
#define LIGHTBLUE      	 0X7D7C	//浅蓝色  
#define GRAYBLUE       	 0X5458 //灰蓝色
//以上三色为PANEL的颜色 #define LIGHTGREEN     	 0X841F //浅绿色
//#define LIGHTGRAY        0XEF5B //浅灰色(PANNEL)
#define LGRAY 			 0XC618 //浅灰色(PANNEL),窗体背景色#define LGRAYBLUE        0XA651 //浅灰蓝色(中间层颜色)
#define LBBLUE           0X2B12 //浅棕蓝色(选择条目的反色)void LCD_Init(void);													   	//初始化
void LCD_DisplayOn(void);													//开显示
void LCD_DisplayOff(void);													//关显示
void LCD_Clear(u32 Color);	 												//清屏
void LCD_SetCursor(u16 Xpos, u16 Ypos);										//设置光标
void LCD_DrawPoint(u16 x,u16 y);											//画点
void LCD_Fast_DrawPoint(u16 x,u16 y,u32 color);								//快速画点
u32  LCD_ReadPoint(u16 x,u16 y); 											//读点 
void LCD_Draw_Circle(u16 x0,u16 y0,u8 r);						 			//画圆
void LCD_DrawLine(u16 x1, u16 y1, u16 x2, u16 y2);							//画线
void LCD_DrawRectangle(u16 x1, u16 y1, u16 x2, u16 y2);		   				//画矩形
void LCD_Fill(u16 sx,u16 sy,u16 ex,u16 ey,u32 color);		   				//填充单色
void LCD_Color_Fill(u16 sx,u16 sy,u16 ex,u16 ey,u16 *color);				//填充指定颜色
void LCD_ShowChar(u16 x,u16 y,u8 num,u8 size,u8 mode);						//显示一个字符
void LCD_ShowNum(u16 x,u16 y,u32 num,u8 len,u8 size);  						//显示一个数字
void LCD_ShowxNum(u16 x,u16 y,u32 num,u8 len,u8 size,u8 mode);				//显示 数字
void LCD_ShowString(u16 x,u16 y,u16 width,u16 height,u8 size,u8 *p);		//显示一个字符串,12/16字体void LCD_WriteReg(u16 LCD_Reg, u16 LCD_RegValue);
u16 LCD_ReadReg(u16 LCD_Reg);
void LCD_WriteRAM_Prepare(void);
void LCD_WriteRAM(u16 RGB_Code);
void LCD_SSD_BackLightSet(u8 pwm);							//SSD1963 背光控制
void LCD_Scan_Dir(u8 dir);									//设置屏扫描方向
void LCD_Display_Dir(u8 dir);								//设置屏幕显示方向
void LCD_Set_Window(u16 sx,u16 sy,u16 width,u16 height);	//设置窗口					   						   																			 
//LCD分辨率设置
#define SSD_HOR_RESOLUTION		800		//LCD水平分辨率
#define SSD_VER_RESOLUTION		480		//LCD垂直分辨率
//LCD驱动参数设置
#define SSD_HOR_PULSE_WIDTH		1		//水平脉宽
#define SSD_HOR_BACK_PORCH		46		//水平前廊
#define SSD_HOR_FRONT_PORCH		210		//水平后廊#define SSD_VER_PULSE_WIDTH		1		//垂直脉宽
#define SSD_VER_BACK_PORCH		23		//垂直前廊
#define SSD_VER_FRONT_PORCH		22		//垂直前廊
//如下几个参数,自动计算
#define SSD_HT	(SSD_HOR_RESOLUTION+SSD_HOR_BACK_PORCH+SSD_HOR_FRONT_PORCH)
#define SSD_HPS	(SSD_HOR_BACK_PORCH)
#define SSD_VT 	(SSD_VER_RESOLUTION+SSD_VER_BACK_PORCH+SSD_VER_FRONT_PORCH)
#define SSD_VPS (SSD_VER_BACK_PORCH)#endif

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/422252.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

如何做好网络安全

随着互联网技术的飞速发展&#xff0c;网站已成为企业对外展示、交流和服务的重要窗口。然而&#xff0c;随之而来的网站安全问题也日益凸显&#xff0c;给企业的业务发展和用户数据安全带来了巨大威胁。因此&#xff0c;高度重视网站安全已成为网络安全的首要任务。今天我们就…

使用ffmpeg在视频中绘制矩形区域

由于项目需要对视频中的人脸做定位跟踪&#xff0c; 我先使用了人脸识别算法&#xff0c;对视频中的每个帧识别人脸、通过人脸库比对&#xff0c;最终记录坐标等信息。 然后使用ffmpeg中的 drawbox 滤镜功能&#xff0c;选择性的绘制区域。从而实现人脸定位跟踪 1、drawbox …

用于协作代码开发的 10 大 GitHub 集成

GitHub 是开发人员的天堂。开发人员在分布式 GitHub 存储库中存储和管理其源代码,允许多个贡献者同时处理项目。这种协作行动将生产力提高了 22%,将修复漏洞的速度提高了 7 倍,并将入职时间缩短了 80%。 作为一个版本控制系统,它允许开发人员跟踪和审查更改、管理分支和合…

【Sceneform-EQR】通过sceneform-eqr实现一个视频播放器(使用安卓MediaPlayer实现视频播放)

在前一篇文档中介绍了如何在AR\三维场景创建几种背景 【Sceneform-EQR】scenefrom-eqr中的几种背景实现(不仅用于AR、三维场景&#xff0c;在图片、视频播放器中也适用) 本文将侧重介绍如何使用安卓MediaPlayer实现视频播放。 ↓↓↓↓↓↓↓↓↓↓↓↓ 以下正文 ↓↓↓↓↓↓…

李彦宏内部讲话曝光,谈大模型三大认知误区:智能体还是非共识

“外界对大模型有相当多的误解&#xff0c;”近日据媒体报道&#xff0c;李彦宏的一则内部讲话曝光。在最近一次和员工交流中&#xff0c;李彦宏谈及三个大模型认知误区&#xff0c;涵盖了大模型竞争、开源模型效率、智能体趋势等热点话题。 李彦宏认为未来大模型之间的差距可…

DWI扩散磁共振成像和结构连接组学指南

扩散磁共振成像和结构连接组学指南 引言流程概述扩散磁共振成像(dMRI)dMRI基础ADC&#xff08; apparent diffusion coefficient, 表观扩散系数&#xff09;MD&#xff08;mean diffusivity, 平均扩散率&#xff09;FA&#xff08; fractional anisotropy, 分数各向异性&#x…

“左侧文字横向”的QTabWidget

左侧用 QToolButton 组&#xff0c; 右侧用 QStackedWidget&#xff0c;信号槽绑定切换页面 可定制化高 QButtonGroup* btnGp new QButtonGroup(this);btnGp->addButton(ui->btn1, 0);btnGp->addButton(ui->btn2, 1);btnGp->addButton(ui->btn3, 2);connect…

MongoDB的Map-Reduce操作与聚合管道操作的两个实例相互转换

一、插入集合 comment 的文档的内容 二、题目要求 将集合 comment 中的文档进行聚合操作&#xff0c;即将字段 state为1的文档查询出来&#xff0c;然后按字段 nickname 进行分组,最后计算出每个评论者的评论条数。 三、mapReduce 操作代码 db.comment.mapReduce(// Map函数&…

linux搭建深度学习平台

linux搭建深度学习平台&#xff08;Ubuntu&#xff09; /home/guangyao/anaconda3 我服务器的anaconda地址 ~/anaconda3 1 首先就是打开浏览器&#xff0c;我实验室的是火狐&#xff0c;搜索anaconda下载&#xff0c;找到下载目录&#xff0c;cd进去&#xff0c; 2安装 bas…

鸿蒙界面开发——组件(6):属性字符串(StyledString)文本输入

属性字符串StyledString/MutableStyledString MutableStyledString继承于StyledString&#xff0c;以下统一简称StyledString。 是功能强大的标记对象&#xff0c;可用于字符或段落级别设置文本样式。 通过将StyledString附加到文本组件&#xff0c; 可以通过多种方式更改文本…

爆改YOLOv8|利用SCConv改进yolov8-即轻量又涨点

1&#xff0c;本文介绍 SCConv&#xff08;空间和通道重构卷积&#xff09;是一种高效的卷积模块&#xff0c;旨在优化卷积神经网络&#xff08;CNN&#xff09;的性能&#xff0c;通过减少空间和通道的冗余来降低计算资源的消耗。该模块由两个核心组件构成&#xff1a; 空间重…

ELK在Linux上部署教程

Docker Compose搭建ELK Elasticsearch默认使用mmapfs目录来存储索引。操作系统默认的mmap计数太低可能导致内存不足&#xff0c;我们可以使用下面这条命令来增加内存 sysctl -w vm.max_map_count262144创建Elasticsearch数据挂载路径 mkdir -p /echola/elasticsearch/data对…

【截图服务 +打包】pkg打包 puppeteer

目录 最后结论 windows打包成服务 定制executablePath 用程序来查找chrome.exe 代替上面的写配置文件 服务遇到的问题 使用java开一个线程启动 遇到的问题与解决 版本匹配问题 打出包后的运行报错问题 linux下的安装 安装n 库缺少 程序运行后的报错 制作 运行报…

IT前端好用的工具集

在线抠图网站 https://www.remove.bg/ 将iconfont转成css显示 https://transfonter.org/ 免费的在线图片压缩 https://tinypng.com/ JSON在线格式化工具 https://www.sojson.com/ 国内人工智能kimi.moonshot工具 https://kimi.moonshot.cn/chat/crft7a6sdv14grouufs0 自动…

当人工智能聊天机器人出现问题时

在快速发展的人工智能领域&#xff0c;出现了一项新的挑战。“人工智能私语者”正在通过说服行为良好的聊天机器人打破自己制定的规则来探索人工智能伦理的界限。 这些漏洞被称为即时注入或“越狱”&#xff0c;它们暴露了人工智能系统的漏洞&#xff0c;引发了人们对其安全性…

基于SpringBoot+Vue+MySQL的教学资源共享平台

系统展示 用户前台界面 管理员后台界面 系统背景 随着信息技术的迅猛发展&#xff0c;教育领域对高效、便捷的教学资源需求日益增长。传统教学模式已难以满足当前教育的多样化需求&#xff0c;特别是在资源共享与利用方面存在明显不足。因此&#xff0c;构建一个基于SpringBoot…

OPENAIGC开发者大赛企业组AI黑马奖 | 包你面-AI面试助手

在第二届拯救者杯OPENAIGC开发者大赛中&#xff0c;涌现出一批技术突出、创意卓越的作品。为了让这些优秀项目被更多人看到&#xff0c;我们特意开设了优秀作品报道专栏&#xff0c;旨在展示其独特之处和开发者的精彩故事。 无论您是技术专家还是爱好者&#xff0c;希望能带给您…

HashTable哈希表

概念 散列表(Hash Table)&#xff0c;又称哈希表。是一种数据结构&#xff0c;特点是:数据元素的关键字与其存储地址直接相关 在顺序结构以及树型结构中&#xff0c;数据元素的关键字与其存储位置没有对应的关系&#xff0c;因此在查找一个元素时&#xff0c;必须要经过关键码…

【Python篇】PyQt5 超详细教程——由入门到精通(序篇)

文章目录 PyQt5 超详细入门级教程前言序篇&#xff1a;1-3部分&#xff1a;PyQt5基础与常用控件第1部分&#xff1a;初识 PyQt5 和安装1.1 什么是 PyQt5&#xff1f;1.2 在 PyCharm 中安装 PyQt51.3 在 PyCharm 中编写第一个 PyQt5 应用程序1.4 代码详细解释1.5 在 PyCharm 中运…

《论面向服务架构设计及其应用》写作框架,软考高级系统架构设计师

论文真题 面向服务架构(Service-Oriented Architecture, SOA) 是一种应用框架,将日常的业务应用划分为单独的业务功能服务和流程,通过采用良好定义的接口和标准协议将这些服务关联起来。通过实施基于SOA的系统架构,用户可以构建、部署和整合服务,无需依赖应用程序及其运…