实验内容
通过 STM32 的 FSMC 接口来控制 TFTLCD 的显示。
TFTLCD简介
TFT-LCD 即薄膜晶体管液晶显示器。其英文全称为:Thin Film Transistor-Liquid Crystal Display。TFT-LCD 与无源 TN-LCD、STN-LCD 的简单矩阵不同,它在液晶显示屏的每一个象素上都设置有一个薄膜晶体管(TFT),可有效地克服非选通时的串扰,使显示液晶屏的静态特性与扫描线数无关,因此大大提高了图像质量。TFT-LCD 也被叫做真彩液晶显示器。
常见指令介绍:
使用流程:
FSMC简介
STM32的FSMC外设简介
STM32 FSMC/FMC原理保姆级讲解(一)
FSMC,即灵活的静态存储控制器,能够与同步或异步存储器和 16 位 PC 存储器卡连接, STM32 的 FSMC 接口支持包括SRAM、NAND FLASH、NOR FLASH 和PSRAM 等存储器。
STM32自带的FSMC功能,就是专门为这类存储器设计的,在STM32上,有一些引脚被专门设计成地址线,还有一些被专门设计成数据线,还有一些被设计成控制线,然后这些地址线和数据线对应着固定的地址,只要外部的DRAM等存储器将对应的数据线连接到STM32这些对应的引脚上,引脚功能设置为复用模式,通过配置FSMC ,你可以直接给上面那个固定的地址赋值 ,其他操作STM32都会自动给你完成,就可以把数据存储到SRAM中。
FSMC 的框图如图18.1.2.1 所示:
从上图我们可以看出,STM32 的FSMC 将外部设备分为 3 类:NOR/PSRAM 设备、NAND设备、PC 卡设备。他们共用地址数据总线等信号,他们具有不同的 CS 以区分不同的设备,比如本章我们用到的TFTLCD 就是用的FSMC_NE4 做片选,其实就是将TFTLCD 当成SRAM 来控制。
外部SRAM 的控制一般有:地址线(如A0 ~ A18)、数据线(如D0~ D15)、写信号(WE)、读信号(OE)、片选信号(CS),如果SRAM 支持字节控制,那么还有UB/LB 信号。而TFTLCD的信号包括:RS、D0~ D15、WR、RD、CS、RST 和 BL 等,其中真正在操作LCD 的时候需要用到的就只有:RS、D0~D15、WR、RD 和CS。其操作时序和 SRAM的控制完全类似,唯一不同就是 TFTLCD 有RS 信号,但是没有地址信号。
TFTLCD 通过 RS 信号来决定传送的数据是数据还是命令,本质上可以理解为一个地址信号,比如我们把RS 接在A0 上面,那么当FSMC 控制器写地址0 的时候,会使得A0 变为0,对TFTLCD 来说,就是写命令。而 FSMC 写地址 1 的时候,A0 将会变为1,对 TFTLCD 来说,就是写数据了。这样,就把数据和命令区分开了,他们其实就是对应 SRAM 操作的两个连续地址。当然RS 也可以接在其他地址线上,精英STM32 开发板是把RS 连接在A10 上面的。
对于NOR FLASH 控制器,主要是通过FSMC_BCRx、FSMC_BTRx 和 FSMC_BWTRx 寄存器设置(其中 x=1~4,对应 4 个区)。通过这 3 个寄存器,可以设置 FSMC 访问外部存储器的时序参数,拓宽了可选用的外部存储器的速度范围。FSMC 的NOR FLASH 控制器支持同步和异步突发两种访问方式。选用同步突发访问方式时,FSMC 将 HCLK(系统时钟)分频后,发送给外部存储器作为同步时钟信号 FSMC_CLK。此时需要的设置的时间参数有 2 个:
1,HCLK 与 FSMC_CLK 的分频系数(CLKDIV),可以为2~16 分频;
2,同步突发访问中获得第 1 个数据所需要的等待延迟(DATLAT)
对于异步突发访问方式,FSMC 主要设置 3 个时间参数:地址建立时间(ADDSET)、数据建立时间(DATAST)和地址保持时间(ADDHLD)。FSMC 综合了SRAM/ROM、PSRAM 和NOR Flash 产品的信号特点,定义了 4 种不同的异步时序模型。
这里,我们使用存储块1,STM32 的 FSMC 存储块1(Bank1)被分为 4 个区,每个区管理64M 字节空间,每个区都有独立的寄存器对所连接的存储器进行配置。Bank1 的 256M 字节空间由 28 根地址线(HADDR[27:0])寻址。其中 HADDR[25:0]来自外部存储器地址FSMC_A[25:0],而HADDR[26:27]对4 个区进行寻址。
当Bank1 接的是 16 位宽度存储器的时候:HADDR[25:1]→ FSMC_A[24:0]。
当Bank1 接的是 8 位宽度存储器的时候:HADDR[25:0]→ FSMC_A[25:0]。
不论外部接8 位/16 位宽设备,FSMC_A[0]永远接在外部设备地址A[0]。
FSMC寄存器
SRAM/NOR 闪存片选控制寄存器 FSMC_BCRx(x=1~4)
EXTMOD:扩展模式使能位,也就是是否允许读写不同的时序,很明显,我们本章需要读写不同的时序,故该位需要设置为 1。
WREN:写使能位。我们需要向 TFTLCD 写数据,故该位必须设置为 1。
MWID[1:0]:存储器数据总线宽度。00,表示 8 位数据模式;01 表示 16 位数据模式;10和11 保留。我们的TFTLCD 是 16 位数据线,所以设置WMID[1:0]=01。
MTYP[1:0]:存储器类型。00 表示SRAM、ROM;01 表示PSRAM;10 表示NOR FLASH;11保留。前面提到,我们把TFTLCD 当成SRAM 用,所以需要设置MTYP[1:0]=00。
MBKEN:存储块使能位。这个容易理解,我们需要用到该存储块控制 TFTLCD,当然要使能这个存储块了。
SRAM/NOR 闪存片选时序寄存器 FSMC_BTRx(x=1~4)
这个寄存器包含了每个存储器块的控制信息,可以用于 SRAM、ROM 和NOR 闪存存储器。如果 FSMC_BCRx 寄存器中设置了 EXTMOD 位,则有两个时序寄存器分别对应读(本寄存器)和写操作(FSMC_BWTRx 寄存器)。因为我们要求读写分开时序控制,所以 EXTMOD 是使能了的,也就是本寄存器是读操作时序寄存器,控制读操作的相关时序。
ACCMOD[1:0]:访问模式。00 表示访问模式 A;01 表示访问模式B;10 表示访问模式C;11 表示访问模式D,本章我们用到模式A,故设置为 00。
DATAST[7:0]:数据保持时间。0 为保留设置,其他设置则代表保持时间为: DATAST 个HCLK 时钟周期,最大为255 个HCLK 周期。对 ILI9341 来说,其实就是RD 低电平持续时间,一般为355ns。而一个HCLK 时钟周期为 13.8ns 左右(1/72Mhz),为了兼容其他屏,我们这里设置DATAST 为15,也就是16 个HCLK 周期,时间大约是234ns(未计算数据存储的2 个HCLK时间,对9341 来说超频了,但是实际上是可以正常使用的)。
ADDSET[3:0]:地址建立时间。其建立时间为:ADDSET 个HCLK 周期,最大为 15 个HCLK周期。对 ILI9341 来说,这里相当于 RD 高电平持续时间,为 90ns,本来这里我们应该设置和DATAST 一样,但是由于 STM32F103 FSMC 的性能问题,就算设置ADDSET 为0,RD 的高电平持续时间也达到了 190ns 以上,所有,我们这里可以设置 ADDSET 为较小的值,本章我们设置ADDSET 为1,即 2 个HCLK 周期,实际RD 高电平大于200ns。
SRAM/NOR 闪写时序寄存器 FSMC_BWTRx(x=1~4)
该寄存器在本章用作写操作时序控制寄存器,需要用到的设置同样是:ACCMOD、DATAST和ADDSET 这三个设置。这三个设置的方法同 FSMC_BTRx 一模一样,只是这里对应的是写操作的时序,ACCMOD 设置同FSMC_BTRx 一模一样,同样是选择模式A,另外DATAST 和ADDSET 则对应低电平和高电平持续时间,对ILI9341 来说,这两个时间只需要 15ns 就够了,比读操作快得多。所以我们这里设置 DATAST 为 3,即 4 个HCLK 周期,时间约为 55ns(因为9320 等控制器,这个时间要求比较长,要50ns)。然后 ADDSET(也存在性能问题)设置为 0,即1 个HCLK 周期,实际WR 高电平时间大于 100ns。
FSMC_BCRx 和 FSMC_BTRx,组合成**BTCR[8]**寄存器组,他们的对应关系如下:
BTCR[0]对应FSMC_BCR1,
BTCR[1]对应 FSMC_BTR1
BTCR[2]对应FSMC_BCR2,
BTCR[3]对应 FSMC_BTR2,
BTCR[4]对应FSMC_BCR3,
BTCR[5]对应 FSMC_BTR3,
BTCR[6]对应FSMC_BCR4,
BTCR[7]对应 FSMC_BTR4
FSMC_BWTRx 则组合成BWTR[7],他们的对应关系如下:
BWTR[0]对应 FSMC_BWTR1,
BWTR[2]对应 FSMC_BWTR2,
BWTR[4]对应 FSMC_BWTR3,
BWTR[6]对应 FSMC_BWTR4,
BWTR[1]、BWTR[3],BWTR[5]保留,没有用到。
FSMC初始化函数
初始化主要就是初始化上文的三个寄存器FSMC_BCRx,FSMC_BTRx, FSMC_BWTRx。
FSMC_NORSRAMInit();//初始化NOR和SRAM
FSMC_NANDInit();
FSMC_PCCARDInit();
void FSMC_NORSRAMInit(FSMC_NORSRAMInitTypeDef* FSMC_NORSRAMInitStruct);
FSMC_NORSRAMInitTypeDef:
typedef struct
{
uint32_t FSMC_Bank;//设置使用到的存储块标号和区号
uint32_t FSMC_DataAddressMux;//设置地址/数据复用使能,若设置为使能,那么地址的低 16位和数据将共用数据总线,仅对 NOR 和PSRAM 有效
uint32_t FSMC_MemoryType;//设置存储器类型
uint32_t FSMC_MemoryDataWidth;//设置数据宽度
uint32_t FSMC_BurstAccessMode;
uint32_t FSMC_AsynchronousWait;
uint32_t FSMC_WaitSignalPolarity;
uint32_t FSMC_WrapMode;
uint32_t FSMC_WaitSignalActive;
uint32_t FSMC_WriteOperation;//设置写使能
uint32_t FSMC_WaitSignal;
uint32_t FSMC_ExtendedMode;//设置扩展模式使能位,也就是是否允许读写不同的时序
uint32_t FSMC_WriteBurst;
FSMC_NORSRAMTimingInitTypeDef* FSMC_ReadWriteTimingStruct;//读时序
FSMC_NORSRAMTimingInitTypeDef* FSMC_WriteTimingStruct;//写时序
}FSMC_NORSRAMInitTypeDef;
FSMC_NORSRAMTimingInitTypeDef:
typedef struct
{
uint32_t FSMC_AddressSetupTime;
uint32_t FSMC_AddressHoldTime;
uint32_t FSMC_DataSetupTime;
uint32_t FSMC_BusTurnAroundDuration;
uint32_t FSMC_CLKDivision;
uint32_t FSMC_DataLatency;
uint32_t FSMC_AccessMode;
}FSMC_NORSRAMTimingInitTypeDef;
FSMC 使能函数
void FSMC_NORSRAMCmd(uint32_t FSMC_Bank, FunctionalState NewState);
void FSMC_NANDCmd(uint32_t FSMC_Bank, FunctionalState NewState);
void FSMC_PCCARDCmd(FunctionalState NewState);
lcd.h
#ifndef __LCD_H
#define __LCD_H
#include "sys.h"
#include "stdlib.h"
//LCD重要参数集
typedef struct
{
u16 width; //LCD 宽度
u16 height; //LCD 高度
u16 id; //LCD ID
u8 dir; //横屏还是竖屏控制:0,竖屏;1,横屏。
u16 wramcmd; //开始写gram指令
u16 setxcmd; //设置x坐标指令
u16 setycmd; //设置y坐标指令
} _lcd_dev;
//LCD参数
extern _lcd_dev lcddev; //管理LCD重要参数
//LCD的画笔颜色和背景色
extern u16 POINT_COLOR; //默认红色
extern u16 BACK_COLOR; //背景颜色.默认为白色
//-----------------LCD端口定义----------------
#define LCD_LED PBout(0) //LCD背光 PB0
//LCD地址结构体
typedef struct
{
vu16 LCD_REG;
vu16 LCD_RAM;
} LCD_TypeDef;
//使用NOR/SRAM的 Bank1.sector4,地址位HADDR[27,26]=11 A10作为数据命令区分线
//注意设置时STM32内部会右移一位对其!
#define LCD_BASE ((u32)(0x6C000000 | 0x000007FE))
#define LCD ((LCD_TypeDef *) LCD_BASE)//将这个地址强制为结构体LCD_TypeDef地址,LCD_REG对应RS=0(命令),LCD_RAM对应RS=1(数据)
//
//扫描方向定义
#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 LGRAY 0XC618 //浅灰色(PANNEL),窗体背景色
#define LGRAYBLUE 0XA651 //浅灰蓝色(中间层颜色)
#define LBBLUE 0X2B12 //浅棕蓝色(选择条目的反色)
void LCD_Init(void); //初始化
void LCD_DisplayOn(void); //开显示
void LCD_DisplayOff(void); //关显示
void LCD_Clear(u16 Color); //清屏
void LCD_SetCursor(u16 Xpos, u16 Ypos); //设置光标
void LCD_DrawPoint(u16 x, u16 y); //画点
void LCD_Fast_DrawPoint(u16 x, u16 y, u16 color); //快速画点
u16 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, u16 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分辨率设置
//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
lcd.c
#include "lcd.h"
#include "stdlib.h"
#include "font.h"
#include "usart.h"
#include "delay.h"
//LCD的画笔颜色和背景色
u16 POINT_COLOR=0x0000; //画笔颜色
u16 BACK_COLOR=0xFFFF; //背景色
//管理LCD重要参数
//默认为竖屏
_lcd_dev lcddev;
//写寄存器函数
//regval:寄存器值
void LCD_WR_REG(u16 regval)
{
LCD->LCD_REG=regval; //写入要写的寄存器序号,写命令
}
//写LCD数据
//data:要写入的值
void LCD_WR_DATA(u16 data)
{
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:坐标
//返回值:此点的颜色
u16 LCD_ReadPoint(u16 x, u16 y)
{
u16 r, g, b;
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)发送读GRAM指令
{
LCD_WR_REG(0X2E);
}
r = LCD_RD_DATA(); //假读
if (lcddev.id == 0X1963) //对1963来说,是真读
{
return r; //1963直接读就可以
}
r = LCD_RD_DATA(); //实际坐标颜色
//9341/5310/5510/7789 要分2次读出
b = LCD_RD_DATA();
g = r & 0XFF; //对于 9341/5310/5510/7789, 第一次读取的是RG的值,R在前,G在后,各占8位
g <<= 8;
return (((r >> 11) << 11) | ((g >> 10) << 5) | (b >> 11)); // 9341/5310/5510/7789 需要公式转换一下
}
//LCD开启显示
void LCD_DisplayOn(void)
{
if (lcddev.id == 0X5510) //5510开启显示指令
{
LCD_WR_REG(0X2900); //开启显示
}
else //9341/5310/1963/7789 等发送开启显示指令
{
LCD_WR_REG(0X29); //开启显示
}
}
//LCD关闭显示
void LCD_DisplayOff(void)
{
if (lcddev.id == 0X5510) //5510关闭显示指令
{
LCD_WR_REG(0X2800); //关闭显示
}
else //9341/5310/1963/7789 等发送关闭显示指令
{
LCD_WR_REG(0X28); //关闭显示
}
}
//设置光标位置
//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等设置坐标
{
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的自动扫描方向
//dir:0~7,代表8个方向(具体定义见lcd.h)
//9341/5310/5510/1963/7789等IC已经实际测试
//注意:其他函数可能会受到此函数设置的影响(尤其是9341),
//所以,一般设置为L2R_U2D即可,如果设置为其他扫描方式,可能导致显示不正常.
void LCD_Scan_Dir(u8 dir)
{
u16 regval = 0;
u16 dirreg = 0;
u16 temp;
//横屏时,对1963不改变扫描方向, 其他IC改变扫描方向!竖屏时1963改变方向, 其他IC不改变扫描方向
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;
}
if (lcddev.id == 0X5510)dirreg = 0X3600;
else dirreg = 0X36;
if (lcddev.id == 0X9341 || lcddev.id == 0X7789) //9341 & 7789 要设置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(); //开始写入GRAM
LCD->LCD_RAM=POINT_COLOR;
}
//快速画点
//x,y:坐标
//color:颜色
void LCD_Fast_DrawPoint(u16 x, u16 y, u16 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设置C
LCD_WR_DATA(0xFF); //4设置D
LCD_WR_DATA(0x00); //5设置E
LCD_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; //设置宽度480
lcddev.height = 800; //设置高度800
}
else //其他IC, 包括: 9341 / 5310 / 7789等IC
{
lcddev.wramcmd = 0X2C;
lcddev.setxcmd = 0X2A;
lcddev.setycmd = 0X2B;
}
if (lcddev.id == 0X5310) //如果是5310 则表示是 320*480分辨率
{
lcddev.width = 320;
lcddev.height = 480;
}
}
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.wramcmd = 0X2C; //设置写入GRAM的指令
lcddev.setxcmd = 0X2A; //设置写X坐标指令
lcddev.setycmd = 0X2B; //设置写Y坐标指令
lcddev.width = 800; //设置宽度800
lcddev.height = 480; //设置高度480
}
else //其他IC, 包括: 9341 / 5310 / 7789等IC
{
lcddev.wramcmd = 0X2C;
lcddev.setxcmd = 0X2A;
lcddev.setycmd = 0X2B;
}
if (lcddev.id == 0X5310) //如果是5310 则表示是 320*480分辨率
{
lcddev.width = 480;
lcddev.height = 320;
}
}
LCD_Scan_Dir(DFT_SCAN_DIR); //默认扫描方向
}
//设置窗口,并自动设置画点坐标到窗口左上角(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横屏 等 设置窗口
{
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);
}
}
//初始化lcd
//该初始化函数可以初始化各种ILI93XX液晶,但是其他函数是基于ILI9320的!!!
//在其他型号的驱动芯片上没有测试!
void LCD_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
FSMC_NORSRAMTimingInitTypeDef readWriteTiming;
FSMC_NORSRAMTimingInitTypeDef writeTiming;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC,ENABLE); //使能FSMC时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOD|RCC_APB2Periph_GPIOE|RCC_APB2Periph_GPIOG,ENABLE); //使能PORTB,D,E,G以及AFIO复用功能时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; //PB0 推挽输出 背光
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
//PORTD复用推挽输出
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_14|GPIO_Pin_15; //PORTD复用推挽输出
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
//PORTE复用推挽输出
GPIO_InitStructure.GPIO_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; //PORTE复用推挽输出
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOE, &GPIO_InitStructure);
//PORTG12复用推挽输出 P0RTG0-->RS
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_12; //PORTD复用推挽输出
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOG, &GPIO_InitStructure);
readWriteTiming.FSMC_AddressSetupTime = 0x01; //地址建立时间(ADDSET)为2个HCLK 1/36M=27ns
readWriteTiming.FSMC_AddressHoldTime = 0x00; //地址保持时间(ADDHLD)模式A未用到
readWriteTiming.FSMC_DataSetupTime = 0x0f; //数据保存时间为16个HCLK,因为液晶驱动IC的读数据的时候,速度不能太快,尤其对1289这个IC。
readWriteTiming.FSMC_BusTurnAroundDuration = 0x00;
readWriteTiming.FSMC_CLKDivision = 0x00;
readWriteTiming.FSMC_DataLatency = 0x00;
readWriteTiming.FSMC_AccessMode = FSMC_AccessMode_A; //模式A
writeTiming.FSMC_AddressSetupTime = 0x00; //地址建立时间(ADDSET)为1个HCLK
writeTiming.FSMC_AddressHoldTime = 0x00; //地址保持时间(ADDHLD)模式A未用到
writeTiming.FSMC_DataSetupTime = 0x03; //数据保存时间为4个HCLK
writeTiming.FSMC_BusTurnAroundDuration = 0x00;
writeTiming.FSMC_CLKDivision = 0x00;
writeTiming.FSMC_DataLatency = 0x00;
writeTiming.FSMC_AccessMode = FSMC_AccessMode_A; //模式A
FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM4; //这里我们使用NE4,也就对应BTCR[6],[7]。
FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; //不复用数据地址
FSMC_NORSRAMInitStructure.FSMC_MemoryType =FSMC_MemoryType_SRAM; //FSMC_MemoryType_SRAM; SRAM
FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; //存储器数据宽度为16bit
FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode =FSMC_BurstAccessMode_Disable; //FSMC_BurstAccessMode_Disable;
FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait=FSMC_AsynchronousWait_Disable;
FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; //存储器写使能
FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Enable; //读写使用不同的时序
FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &readWriteTiming; //读写时序
FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &writeTiming; //写时序
FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); //初始化FSMC配置
FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM4, ENABLE); //使能BANK1
delay_ms(50); // delay 50 ms
//尝试9341 ID的读取
LCD_WR_REG(0XD3);
lcddev.id = LCD_RD_DATA(); //dummy read
lcddev.id = LCD_RD_DATA(); //读到0X00
lcddev.id = LCD_RD_DATA(); //读取0X93
lcddev.id <<= 8;
lcddev.id |= LCD_RD_DATA(); //读取0X41
if (lcddev.id != 0X9341) //不是 9341 , 尝试看看是不是 ST7789
{
LCD_WR_REG(0X04);
lcddev.id = LCD_RD_DATA(); //dummy read
lcddev.id = LCD_RD_DATA(); //读到0X85
lcddev.id = LCD_RD_DATA(); //读取0X85
lcddev.id <<= 8;
lcddev.id |= LCD_RD_DATA(); //读取0X52
if (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 read
lcddev.id = LCD_RD_DATA(); //读回0X01
lcddev.id = LCD_RD_DATA(); //读回0X53
lcddev.id <<= 8;
lcddev.id |= LCD_RD_DATA(); //这里读回0X10
if (lcddev.id != 0X5310) //也不是NT35310,尝试看看是不是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(); //读回0X55
lcddev.id <<= 8;
LCD_WR_REG(0xC501); //读取ID低8位
lcddev.id |= LCD_RD_DATA(); //读回0X10
delay_ms(5);
if (lcddev.id != 0X5510) //也不是NT5510,尝试看看是不是SSD1963
{
LCD_WR_REG(0XA1);
lcddev.id = LCD_RD_DATA();
lcddev.id = LCD_RD_DATA(); //读回0X57
lcddev.id <<= 8;
lcddev.id |= LCD_RD_DATA(); //读回0X61
if (lcddev.id == 0X5761)lcddev.id = 0X1963; //SSD1963读回的ID是5761H,为方便区分,我们强制设置为1963
}
}
}
}
printf(" LCD ID:%x\r\n", lcddev.id); //打印LCD ID
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 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 (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); //vcom
LCD_WR_DATA(0x32); //30
LCD_WR_REG(0xC0);
LCD_WR_DATA(0x0C);
LCD_WR_REG(0xC2);
LCD_WR_DATA(0x01);
LCD_WR_REG(0xC3); //vrh
LCD_WR_DATA(0x10); //17 0D
LCD_WR_REG(0xC4); //vdv
LCD_WR_DATA(0x20); //20
LCD_WR_REG(0xC6);
LCD_WR_DATA(0x0f);
LCD_WR_REG(0xD0);
LCD_WR_DATA(0xA4);
LCD_WR_DATA(0xA1);
LCD_WR_REG(0xE0); //Set Gamma
LCD_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 Gamma
LCD_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); //5f
LCD_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); //66
LCD_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.2V
LCD_WriteReg(0xB000, 0x0D);
LCD_WriteReg(0xB001, 0x0D);
LCD_WriteReg(0xB002, 0x0D);
//AVDD ratio
LCD_WriteReg(0xB600, 0x34);
LCD_WriteReg(0xB601, 0x34);
LCD_WriteReg(0xB602, 0x34);
//AVEE -5.2V
LCD_WriteReg(0xB100, 0x0D);
LCD_WriteReg(0xB101, 0x0D);
LCD_WriteReg(0xB102, 0x0D);
//AVEE ratio
LCD_WriteReg(0xB700, 0x34);
LCD_WriteReg(0xB701, 0x34);
LCD_WriteReg(0xB702, 0x34);
//VCL -2.5V
LCD_WriteReg(0xB200, 0x00);
LCD_WriteReg(0xB201, 0x00);
LCD_WriteReg(0xB202, 0x00);
//VCL ratio
LCD_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 ratio
LCD_WriteReg(0xB900, 0x34);
LCD_WriteReg(0xB901, 0x34);
LCD_WriteReg(0xB902, 0x34);
//VGL_REG -10V
LCD_WriteReg(0xB500, 0x08);
LCD_WriteReg(0xB501, 0x08);
LCD_WriteReg(0xB502, 0x08);
LCD_WriteReg(0xC200, 0x03);
//VGLX ratio
LCD_WriteReg(0xBA00, 0x24);
LCD_WriteReg(0xBA01, 0x24);
LCD_WriteReg(0xBA02, 0x24);
//VGMP/VGSP 4.5V/0V
LCD_WriteReg(0xBC00, 0x00);
LCD_WriteReg(0xBC01, 0x78);
LCD_WriteReg(0xBC02, 0x00);
//VGMN/VGSN -4.5V/0V
LCD_WriteReg(0xBD00, 0x00);
LCD_WriteReg(0xBD01, 0x78);
LCD_WriteReg(0xBD02, 0x00);
//VCOM
LCD_WriteReg(0xBE00, 0x00);
LCD_WriteReg(0xBE01, 0x64);
//Gamma Setting
LCD_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 enable
LCD_WriteReg(0xF000, 0x55);
LCD_WriteReg(0xF001, 0xAA);
LCD_WriteReg(0xF002, 0x52);
LCD_WriteReg(0xF003, 0x08);
LCD_WriteReg(0xF004, 0x00);
//Display control
LCD_WriteReg(0xB100, 0xCC);
LCD_WriteReg(0xB101, 0x00);
//Source hold time
LCD_WriteReg(0xB600, 0x05);
//Gate EQ control
LCD_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-delay
LCD_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/pixel
LCD_WR_REG(0x1100);
delay_us(120);
LCD_WR_REG(0x2900);
}
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 = 300MHz
LCD_WR_DATA(0x1D); //参数1
LCD_WR_DATA(0x02); //参数2 Divider M = 2, PLL = 300/(M+1) = 100MHz
LCD_WR_DATA(0x04); //参数3 Validate M and N values
delay_us(100);
LCD_WR_REG(0xE0); // Start PLL command
LCD_WR_DATA(0x01); // enable PLL
delay_ms(10);
LCD_WR_REG(0xE0); // Start PLL command again
LCD_WR_DATA(0x03); // now, use PLL output as system clock
delay_ms(12);
LCD_WR_REG(0x01); //软复位
delay_ms(10);
LCD_WR_REG(0xE6); //设置像素频率,33Mhz
LCD_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 period
LCD_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 period
LCD_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接口为16bit
LCD_WR_DATA(0x03); //16-bit(565 format) data for 16bpp
LCD_WR_REG(0x29); //开启显示
//设置PWM输出 背光通过占空比可调
LCD_WR_REG(0xD0); //设置自动白平衡DBC
LCD_WR_DATA(0x00); //disable
LCD_WR_REG(0xBE); //配置PWM输出
LCD_WR_DATA(0x05); //1设置PWM频率
LCD_WR_DATA(0xFE); //2设置PWM占空比
LCD_WR_DATA(0x01); //3设置C
LCD_WR_DATA(0x00); //4设置D
LCD_WR_DATA(0x00); //5设置E
LCD_WR_DATA(0x00); //6设置F
LCD_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);//背光设置为最亮
}
LCD_Display_Dir(0); //默认为竖屏
LCD_LED = 1; //点亮背光
LCD_Clear(WHITE);
}
//清屏函数
//color:要清屏的填充色
void LCD_Clear(u16 color)
{
u32 index = 0;
u32 totalpoint = lcddev.width;
totalpoint *= lcddev.height; //得到总点数
LCD_SetCursor(0x00, 0x0000); //设置光标位置
LCD_WriteRAM_Prepare(); //开始写入GRAM
for (index = 0; index < totalpoint; index++)
{
LCD->LCD_RAM=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;
xlen = ex - sx + 1;
for (i = sy; i <= ey; i++)
{
LCD_SetCursor(sx, i); //设置光标位置
LCD_WriteRAM_Prepare(); //开始写入GRAM
for (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(); //开始写入GRAM
for (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); //5
LCD_DrawPoint(x0 + b, y0 - a); //0
LCD_DrawPoint(x0 + b, y0 + a); //4
LCD_DrawPoint(x0 + a, y0 + b); //6
LCD_DrawPoint(x0 - a, y0 + b); //1
LCD_DrawPoint(x0 - b, y0 + a);
LCD_DrawPoint(x0 - a, y0 - b); //2
LCD_DrawPoint(x0 - b, y0 - a); //7
a++;
//使用Bresenham算法画圆
if (di < 0)di += 4 * a + 6;
else
{
di += 10 + 4 * (a - b);
b--;
}
}
}
//在指定位置显示一个字符
//x,y:起始坐标
//num:要显示的字符:" "--->"~"
//size:字体大小 12/16/24
//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 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++;
}
}