• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

stm32CubeIDE FMC 驱动LCD8080

武飞扬头像
zhengyad123
帮助1

一,TFT屏硬件接口

学新通

16位,80并口。

学新通
学新通

二,FMC介绍。

FSMC(Flexible Static Memory Controller),译为灵活的静态存储控制器。STM32F1 系列芯片使用 FSMC 外设来管理扩展的存储器,它可以用于驱动包括 SRAM、NOR FLASH 以及 NAND FLSAH 类型的存储器,不能驱动如 SDRAM 这种动态的存储器而在 STM32F429 系列的控制器中,它具有 FMC 外设,支持控制 SDRAM 存储器。

由于 FSMC 外设可以用于控制扩展的外部存储器,而 MCU 对液晶屏的操作实际上就是把显示数据写入到显存中,与控制存储器非常类似,且 8080 接口的通讯时序完全可以使用 FSMC 外设产生,因而非常适合使用 FSMC 控制液晶屏。

学新通
学新通

/** FMC GPIO Configuration

PE7 ------> FMC_D4

PE8 ------> FMC_D5

PE9 ------> FMC_D6

PE10 ------> FMC_D7

PE11 ------> FMC_D8

PE12 ------> FMC_D9

PE13 ------> FMC_D10

PE14 ------> FMC_D11

PE15 ------> FMC_D12

PD8 ------> FMC_D13

PD9 ------> FMC_D14

PD10 ------> FMC_D15

PD13 ------> FMC_A18

PD14 ------> FMC_D0

PD15 ------> FMC_D1

PD0 ------> FMC_D2

PD1 ------> FMC_D3

PD4 ------> FMC_NOE

PD5 ------> FMC_NWE

PD7 ------> FMC_NE1

*/

三,STM32CubeIDE设置

设置FMC之前,先配置GPIO引脚,不然可能不能配置FMC,可能吧。

学新通
学新通
学新通

四,时序

参考文章

学新通

五,程序。

参考原子开发板。

lcd.h

  1.  
    #ifndef __LCD_H
  2.  
    #define __LCD_H
  3.  
    #include "sys.h"
  4.  
    #include "stdlib.h"
  5.  
    //
  6.  
    //本程序只供学习使用,未经作者许可,不得用于其它任何用途
  7.  
    //ALIENTEK STM32开发板
  8.  
    //2.8寸/3.5寸/4.3寸/7寸 TFT液晶驱动
  9.  
    //支持驱动IC型号包括:ILI9341/NT35310/NT35510/SSD1963等
  10.  
    //正点原子@ALIENTEK
  11.  
    //技术论坛:www.openedv.com
  12.  
    //创建日期:2015/12/10
  13.  
    //版本:V1.5
  14.  
    //版权所有,盗版必究。
  15.  
    //Copyright(C) 广州市星翼电子科技有限公司 2014-2024
  16.  
    //All rights reserved
  17.  
    //********************************************************************************
  18.  
    //升级说明
  19.  
    //V1.2 20170623
  20.  
    //简化了LCD_Init函数部分代码
  21.  
    //V1.3 20211111
  22.  
    //1,新增对ST7789驱动IC的支持
  23.  
    //V1.4 20211208
  24.  
    //修改NT5510 ID读取方式,改为先发送秘钥,然后读取C500和C501,从而获取正确的ID(0X5510)
  25.  
    //V1.5 20211222
  26.  
    //解决因NT5510 ID读取(发送C501指令)导致SSD1963误触发软件复位进而读取不到ID问题,加延时解决
  27.  
    //
  28.  
     
  29.  
    //LCD重要参数集
  30.  
    typedef struct
  31.  
    {
  32.  
    u16 width; //LCD 宽度
  33.  
    u16 height; //LCD 高度
  34.  
    u16 id; //LCD ID
  35.  
    u8 dir; //横屏还是竖屏控制:0,竖屏;1,横屏。
  36.  
    u16 wramcmd; //开始写gram指令
  37.  
    u16 setxcmd; //设置x坐标指令
  38.  
    u16 setycmd; //设置y坐标指令
  39.  
    }_lcd_dev;
  40.  
     
  41.  
    //LCD参数
  42.  
    extern _lcd_dev lcddev; //管理LCD重要参数
  43.  
    //LCD的画笔颜色和背景色
  44.  
    extern u32 POINT_COLOR;//默认红色
  45.  
    extern u32 BACK_COLOR; //背景颜色.默认为白色
  46.  
     
  47.  
    //LCD MPU保护参数
  48.  
    #define LCD_REGION_NUMBER MPU_REGION_NUMBER0 //LCD使用region0
  49.  
    #define LCD_ADDRESS_START (0X60000000) //LCD区的首地址
  50.  
    #define LCD_REGION_SIZE MPU_REGION_SIZE_256MB //LCD区大小
  51.  
     
  52.  
    //
  53.  
    //-----------------MCU屏 LCD端口定义----------------
  54.  
    //LCD背光 PB5
  55.  
    #define LCD_LED(n) (n?HAL_GPIO_WritePin(GPIOB,GPIO_PIN_5,GPIO_PIN_SET):HAL_GPIO_WritePin(GPIOB,GPIO_PIN_5,GPIO_PIN_RESET))
  56.  
    //LCD地址结构体
  57.  
    typedef struct
  58.  
    {
  59.  
    vu16 LCD_REG;
  60.  
    vu16 LCD_RAM;
  61.  
    } LCD_TypeDef;
  62.  
     
  63.  
    //使用NOR/SRAM的 Bank1.sector4,地址位HADDR[27,26]=11 A18作为数据命令区分线
  64.  
    //注意设置时STM32内部会右移一位对其!
  65.  
    #define LCD_BASE ((u32)(0x60000000 | 0x0007FFFE))
  66.  
    #define LCD ((LCD_TypeDef *) LCD_BASE)
  67.  
    //
  68.  
     
  69.  
    //扫描方向定义
  70.  
    #define L2R_U2D 0 //从左到右,从上到下
  71.  
    #define L2R_D2U 1 //从左到右,从下到上
  72.  
    #define R2L_U2D 2 //从右到左,从上到下
  73.  
    #define R2L_D2U 3 //从右到左,从下到上
  74.  
     
  75.  
    #define U2D_L2R 4 //从上到下,从左到右
  76.  
    #define U2D_R2L 5 //从上到下,从右到左
  77.  
    #define D2U_L2R 6 //从下到上,从左到右
  78.  
    #define D2U_R2L 7 //从下到上,从右到左
  79.  
     
  80.  
    #define DFT_SCAN_DIR L2R_U2D //默认的扫描方向
  81.  
     
  82.  
    //画笔颜色
  83.  
    #define WHITE 0xFFFF
  84.  
    #define BLACK 0x0000
  85.  
    #define BLUE 0x001F
  86.  
    #define BRED 0XF81F
  87.  
    #define GRED 0XFFE0
  88.  
    #define GBLUE 0X07FF
  89.  
    #define RED 0xF800
  90.  
    #define MAGENTA 0xF81F
  91.  
    #define GREEN 0x07E0
  92.  
    #define CYAN 0x7FFF
  93.  
    #define YELLOW 0xFFE0
  94.  
    #define BROWN 0XBC40 //棕色
  95.  
    #define BRRED 0XFC07 //棕红色
  96.  
    #define GRAY 0X8430 //灰色
  97.  
    //GUI颜色
  98.  
     
  99.  
    #define DARKBLUE 0X01CF //深蓝色
  100.  
    #define LIGHTBLUE 0X7D7C //浅蓝色
  101.  
    #define GRAYBLUE 0X5458 //灰蓝色
  102.  
    //以上三色为PANEL的颜色
  103.  
     
  104.  
    #define LIGHTGREEN 0X841F //浅绿色
  105.  
    //#define LIGHTGRAY 0XEF5B //浅灰色(PANNEL)
  106.  
    #define LGRAY 0XC618 //浅灰色(PANNEL),窗体背景色
  107.  
     
  108.  
    #define LGRAYBLUE 0XA651 //浅灰蓝色(中间层颜色)
  109.  
    #define LBBLUE 0X2B12 //浅棕蓝色(选择条目的反色)
  110.  
     
  111.  
    void LCD_Init(void); //初始化
  112.  
    void LCD_DisplayOn(void); //开显示
  113.  
    void LCD_DisplayOff(void); //关显示
  114.  
    void LCD_Clear(u32 Color); //清屏
  115.  
    void LCD_SetCursor(u16 Xpos, u16 Ypos); //设置光标
  116.  
    void LCD_DrawPoint(u16 x,u16 y); //画点
  117.  
    void LCD_Fast_DrawPoint(u16 x,u16 y,u32 color); //快速画点
  118.  
    u32 LCD_ReadPoint(u16 x,u16 y); //读点
  119.  
    void LCD_Draw_Circle(u16 x0,u16 y0,u8 r); //画圆
  120.  
    void LCD_DrawLine(u16 x1, u16 y1, u16 x2, u16 y2); //画线
  121.  
    void LCD_DrawRectangle(u16 x1, u16 y1, u16 x2, u16 y2); //画矩形
  122.  
    void LCD_Fill(u16 sx,u16 sy,u16 ex,u16 ey,u32 color); //填充单色
  123.  
    void LCD_Color_Fill(u16 sx,u16 sy,u16 ex,u16 ey,u16 *color); //填充指定颜色
  124.  
    void LCD_ShowChar(u16 x,u16 y,u8 num,u8 size,u8 mode); //显示一个字符
  125.  
    void LCD_ShowNum(u16 x,u16 y,u32 num,u8 len,u8 size); //显示一个数字
  126.  
    void LCD_ShowxNum(u16 x,u16 y,u32 num,u8 len,u8 size,u8 mode); //显示 数字
  127.  
    void LCD_ShowString(u16 x,u16 y,u16 width,u16 height,u8 size,u8 *p); //显示一个字符串,12/16字体
  128.  
     
  129.  
    void LCD_WriteReg(u16 LCD_Reg, u16 LCD_RegValue);
  130.  
    u16 LCD_ReadReg(u16 LCD_Reg);
  131.  
    void LCD_WriteRAM_Prepare(void);
  132.  
    void LCD_WriteRAM(u16 RGB_Code);
  133.  
    void LCD_SSD_BackLightSet(u8 pwm); //SSD1963 背光控制
  134.  
    void LCD_Scan_Dir(u8 dir); //设置屏扫描方向
  135.  
    void LCD_Display_Dir(u8 dir); //设置屏幕显示方向
  136.  
    void LCD_Set_Window(u16 sx,u16 sy,u16 width,u16 height); //设置窗口
  137.  
    //LCD分辨率设置
  138.  
    #define SSD_HOR_RESOLUTION 800 //LCD水平分辨率
  139.  
    #define SSD_VER_RESOLUTION 480 //LCD垂直分辨率
  140.  
    //LCD驱动参数设置
  141.  
    #define SSD_HOR_PULSE_WIDTH 1 //水平脉宽
  142.  
    #define SSD_HOR_BACK_PORCH 46 //水平前廊
  143.  
    #define SSD_HOR_FRONT_PORCH 210 //水平后廊
  144.  
     
  145.  
    #define SSD_VER_PULSE_WIDTH 1 //垂直脉宽
  146.  
    #define SSD_VER_BACK_PORCH 23 //垂直前廊
  147.  
    #define SSD_VER_FRONT_PORCH 22 //垂直前廊
  148.  
    //如下几个参数,自动计算
  149.  
    #define SSD_HT (SSD_HOR_RESOLUTION SSD_HOR_BACK_PORCH SSD_HOR_FRONT_PORCH)
  150.  
    #define SSD_HPS (SSD_HOR_BACK_PORCH)
  151.  
    #define SSD_VT (SSD_VER_RESOLUTION SSD_VER_BACK_PORCH SSD_VER_FRONT_PORCH)
  152.  
    #define SSD_VPS (SSD_VER_BACK_PORCH)
  153.  
     
  154.  
    #endif
  155.  
     
  156.  
     
  157.  
     
  158.  
     
  159.  
     
学新通

lcd.c

  1.  
    #include "lcd.h"
  2.  
    #include "stdlib.h"
  3.  
    #include "font.h"
  4.  
    #include "usart.h"
  5.  
    #include "delay.h"
  6.  
    //
  7.  
    //本程序只供学习使用,未经作者许可,不得用于其它任何用途
  8.  
    //ALIENTEK STM32开发板
  9.  
    //2.8寸/3.5寸/4.3寸/7寸 TFT液晶驱动
  10.  
    //支持驱动IC型号包括:ILI9341/NT35310/NT35510/SSD1963等
  11.  
    //正点原子@ALIENTEK
  12.  
    //技术论坛:www.openedv.com
  13.  
    //创建日期:2015/12/10
  14.  
    //版本:V1.5
  15.  
    //版权所有,盗版必究。
  16.  
    //Copyright(C) 广州市星翼电子科技有限公司 2014-2024
  17.  
    //All rights reserved
  18.  
    //
  19.  
    //升级说明
  20.  
    //V1.1 20170625
  21.  
    //简化了LCD_Init函数部分代码
  22.  
    //V1.2 20211111
  23.  
    //1,新增对ST7789驱动IC的支持
  24.  
    //V1.3 20211208
  25.  
    //修改NT5510 ID读取方式,改为先发送秘钥,然后读取C500和C501,从而获取正确的ID(0X5510)
  26.  
    //V1.4 20211222
  27.  
    //解决因NT5510 ID读取(发送C501指令)导致SSD1963误触发软件复位进而读取不到ID问题,加延时解决
  28.  
    //
  29.  
     
  30.  
    SRAM_HandleTypeDef SRAM_Handler; //SRAM句柄(用于控制LCD)
  31.  
    //LCD的画笔颜色和背景色
  32.  
    u32 POINT_COLOR=0xFF000000; //画笔颜色
  33.  
    u32 BACK_COLOR =0xFFFFFFFF; //背景色
  34.  
     
  35.  
    //管理LCD重要参数
  36.  
    //默认为竖屏
  37.  
    _lcd_dev lcddev;
  38.  
     
  39.  
    //写寄存器函数
  40.  
    //regval:寄存器值
  41.  
    void LCD_WR_REG(vu16 regval)
  42.  
    {
  43.  
    regval=regval; //使用-O2优化的时候,必须插入的延时
  44.  
    LCD->LCD_REG=regval;//写入要写的寄存器序号
  45.  
    }
  46.  
    //写LCD数据
  47.  
    //data:要写入的值
  48.  
    void LCD_WR_DATA(vu16 data)
  49.  
    {
  50.  
    data=data; //使用-O2优化的时候,必须插入的延时
  51.  
    LCD->LCD_RAM=data;
  52.  
    }
  53.  
    //读LCD数据
  54.  
    //返回值:读到的值
  55.  
    u16 LCD_RD_DATA(void)
  56.  
    {
  57.  
    vu16 ram; //防止被优化
  58.  
    ram=LCD->LCD_RAM;
  59.  
    return ram;
  60.  
    }
  61.  
    //写寄存器
  62.  
    //LCD_Reg:寄存器地址
  63.  
    //LCD_RegValue:要写入的数据
  64.  
    void LCD_WriteReg(u16 LCD_Reg,u16 LCD_RegValue)
  65.  
    {
  66.  
    LCD->LCD_REG = LCD_Reg; //写入要写的寄存器序号
  67.  
    LCD->LCD_RAM = LCD_RegValue;//写入数据
  68.  
    }
  69.  
    //读寄存器
  70.  
    //LCD_Reg:寄存器地址
  71.  
    //返回值:读到的数据
  72.  
    u16 LCD_ReadReg(u16 LCD_Reg)
  73.  
    {
  74.  
    LCD_WR_REG(LCD_Reg); //写入要读的寄存器序号
  75.  
    delay_us(5);
  76.  
    return LCD_RD_DATA(); //返回读到的值
  77.  
    }
  78.  
    //开始写GRAM
  79.  
    void LCD_WriteRAM_Prepare(void)
  80.  
    {
  81.  
    LCD->LCD_REG=lcddev.wramcmd;
  82.  
    }
  83.  
    //LCD写GRAM
  84.  
    //RGB_Code:颜色值
  85.  
    void LCD_WriteRAM(u16 RGB_Code)
  86.  
    {
  87.  
    LCD->LCD_RAM = RGB_Code;//写十六位GRAM
  88.  
    }
  89.  
    //从ILI93xx读出的数据为GBR格式,而我们写入的时候为RGB格式。
  90.  
    //通过该函数转换
  91.  
    //c:GBR格式的颜色值
  92.  
    //返回值:RGB格式的颜色值
  93.  
    u16 LCD_BGR2RGB(u16 c)
  94.  
    {
  95.  
    u16 r,g,b,rgb;
  96.  
    b=(c>>0)&0x1f;
  97.  
    g=(c>>5)&0x3f;
  98.  
    r=(c>>11)&0x1f;
  99.  
    rgb=(b<<11) (g<<5) (r<<0);
  100.  
    return(rgb);
  101.  
    }
  102.  
    //当mdk -O1时间优化时需要设置
  103.  
    //延时i
  104.  
    void opt_delay(u8 i)
  105.  
    {
  106.  
    while(i--);
  107.  
    }
  108.  
    //读取个某点的颜色值
  109.  
    //x,y:坐标
  110.  
    //返回值:此点的颜色
  111.  
    u32 LCD_ReadPoint(u16 x,u16 y)
  112.  
    {
  113.  
    u16 r=0,g=0,b=0;
  114.  
    if(x>=lcddev.width||y>=lcddev.height)return 0; //超过了范围,直接返回
  115.  
    LCD_SetCursor(x,y);
  116.  
    if(lcddev.id==0X9341||lcddev.id==0X5310||lcddev.id==0X1963||lcddev.id==0x7789)LCD_WR_REG(0X2E);//9341/3510/1963/7789 发送读GRAM指令
  117.  
    else if(lcddev.id==0X5510)LCD_WR_REG(0X2E00); //5510 发送读GRAM指令
  118.  
    r=LCD_RD_DATA(); //dummy Read
  119.  
    if(lcddev.id==0X1963)return r; //1963直接读就可以
  120.  
    opt_delay(2);
  121.  
    r=LCD_RD_DATA(); //实际坐标颜色
  122.  
    //9341/NT35310/NT35510要分2次读出
  123.  
    opt_delay(2);
  124.  
    b=LCD_RD_DATA();
  125.  
    g=r&0XFF; //对于9341/5310/5510,第一次读取的是RG的值,R在前,G在后,各占8位
  126.  
    g<<=8;
  127.  
    return (((r>>11)<<11)|((g>>10)<<5)|(b>>11)); //ILI9341/NT35310/NT35510需要公式转换一下
  128.  
    }
  129.  
    //LCD开启显示
  130.  
    void LCD_DisplayOn(void)
  131.  
    {
  132.  
    if(lcddev.id==0X9341||lcddev.id==0X5310||lcddev.id==0X1963||lcddev.id==0x7789)LCD_WR_REG(0X29); //开启显示
  133.  
    else if(lcddev.id==0X5510)LCD_WR_REG(0X2900); //开启显示
  134.  
    }
  135.  
    //LCD关闭显示
  136.  
    void LCD_DisplayOff(void)
  137.  
    {
  138.  
    if(lcddev.id==0X9341||lcddev.id==0X5310||lcddev.id==0X1963||lcddev.id==0x7789)LCD_WR_REG(0X28); //关闭显示
  139.  
    else if(lcddev.id==0X5510)LCD_WR_REG(0X2800); //关闭显示
  140.  
    }
  141.  
    //设置光标位置(对RGB屏无效)
  142.  
    //Xpos:横坐标
  143.  
    //Ypos:纵坐标
  144.  
    void LCD_SetCursor(u16 Xpos, u16 Ypos)
  145.  
    {
  146.  
    if(lcddev.id==0X9341||lcddev.id==0X5310||lcddev.id==0x7789)
  147.  
    {
  148.  
    LCD_WR_REG(lcddev.setxcmd);
  149.  
    LCD_WR_DATA(Xpos>>8);LCD_WR_DATA(Xpos&0XFF);
  150.  
    LCD_WR_REG(lcddev.setycmd);
  151.  
    LCD_WR_DATA(Ypos>>8);LCD_WR_DATA(Ypos&0XFF);
  152.  
    }else if(lcddev.id==0X1963)
  153.  
    {
  154.  
    if(lcddev.dir==0)//x坐标需要变换
  155.  
    {
  156.  
    Xpos=lcddev.width-1-Xpos;
  157.  
    LCD_WR_REG(lcddev.setxcmd);
  158.  
    LCD_WR_DATA(0);LCD_WR_DATA(0);
  159.  
    LCD_WR_DATA(Xpos>>8);LCD_WR_DATA(Xpos&0XFF);
  160.  
    }else
  161.  
    {
  162.  
    LCD_WR_REG(lcddev.setxcmd);
  163.  
    LCD_WR_DATA(Xpos>>8);LCD_WR_DATA(Xpos&0XFF);
  164.  
    LCD_WR_DATA((lcddev.width-1)>>8);LCD_WR_DATA((lcddev.width-1)&0XFF);
  165.  
    }
  166.  
    LCD_WR_REG(lcddev.setycmd);
  167.  
    LCD_WR_DATA(Ypos>>8);LCD_WR_DATA(Ypos&0XFF);
  168.  
    LCD_WR_DATA((lcddev.height-1)>>8);LCD_WR_DATA((lcddev.height-1)&0XFF);
  169.  
     
  170.  
    }else if(lcddev.id==0X5510)
  171.  
    {
  172.  
    LCD_WR_REG(lcddev.setxcmd);LCD_WR_DATA(Xpos>>8);
  173.  
    LCD_WR_REG(lcddev.setxcmd 1);LCD_WR_DATA(Xpos&0XFF);
  174.  
    LCD_WR_REG(lcddev.setycmd);LCD_WR_DATA(Ypos>>8);
  175.  
    LCD_WR_REG(lcddev.setycmd 1);LCD_WR_DATA(Ypos&0XFF);
  176.  
    }
  177.  
    }
  178.  
    //设置LCD的自动扫描方向(对RGB屏无效)
  179.  
    //注意:其他函数可能会受到此函数设置的影响(尤其是9341),
  180.  
    //所以,一般设置为L2R_U2D即可,如果设置为其他扫描方式,可能导致显示不正常.
  181.  
    //dir:0~7,代表8个方向(具体定义见lcd.h)
  182.  
    //9341/5310/5510/1963等IC已经实际测试
  183.  
    void LCD_Scan_Dir(u8 dir)
  184.  
    {
  185.  
    u16 regval=0;
  186.  
    u16 dirreg=0;
  187.  
    u16 temp;
  188.  
    if((lcddev.dir==1&&lcddev.id!=0X1963)||(lcddev.dir==0&&lcddev.id==0X1963))//横屏时,对1963不改变扫描方向!竖屏时1963改变方向
  189.  
    {
  190.  
    switch(dir)//方向转换
  191.  
    {
  192.  
    case 0:dir=6;break;
  193.  
    case 1:dir=7;break;
  194.  
    case 2:dir=4;break;
  195.  
    case 3:dir=5;break;
  196.  
    case 4:dir=1;break;
  197.  
    case 5:dir=0;break;
  198.  
    case 6:dir=3;break;
  199.  
    case 7:dir=2;break;
  200.  
    }
  201.  
    }
  202.  
    if(lcddev.id==0x9341||lcddev.id==0X5310||lcddev.id==0X5510||lcddev.id==0X1963||lcddev.id==0x7789)//9341/5310/5510/1963/7789,特殊处理
  203.  
    {
  204.  
    switch(dir)
  205.  
    {
  206.  
    case L2R_U2D://从左到右,从上到下
  207.  
    regval|=(0<<7)|(0<<6)|(0<<5);
  208.  
    break;
  209.  
    case L2R_D2U://从左到右,从下到上
  210.  
    regval|=(1<<7)|(0<<6)|(0<<5);
  211.  
    break;
  212.  
    case R2L_U2D://从右到左,从上到下
  213.  
    regval|=(0<<7)|(1<<6)|(0<<5);
  214.  
    break;
  215.  
    case R2L_D2U://从右到左,从下到上
  216.  
    regval|=(1<<7)|(1<<6)|(0<<5);
  217.  
    break;
  218.  
    case U2D_L2R://从上到下,从左到右
  219.  
    regval|=(0<<7)|(0<<6)|(1<<5);
  220.  
    break;
  221.  
    case U2D_R2L://从上到下,从右到左
  222.  
    regval|=(0<<7)|(1<<6)|(1<<5);
  223.  
    break;
  224.  
    case D2U_L2R://从下到上,从左到右
  225.  
    regval|=(1<<7)|(0<<6)|(1<<5);
  226.  
    break;
  227.  
    case D2U_R2L://从下到上,从右到左
  228.  
    regval|=(1<<7)|(1<<6)|(1<<5);
  229.  
    break;
  230.  
    }
  231.  
    if(lcddev.id==0X5510)dirreg=0X3600;
  232.  
    else dirreg=0X36;
  233.  
    if((lcddev.id!=0X5310)&&(lcddev.id!=0X5510)&&(lcddev.id!=0X1963))regval|=0X08;//5310/5510/1963不需要BGR
  234.  
    LCD_WriteReg(dirreg,regval);
  235.  
    if(lcddev.id!=0X1963)//1963不做坐标处理
  236.  
    {
  237.  
    if(regval&0X20)
  238.  
    {
  239.  
    if(lcddev.width<lcddev.height)//交换X,Y
  240.  
    {
  241.  
    temp=lcddev.width;
  242.  
    lcddev.width=lcddev.height;
  243.  
    lcddev.height=temp;
  244.  
    }
  245.  
    }else
  246.  
    {
  247.  
    if(lcddev.width>lcddev.height)//交换X,Y
  248.  
    {
  249.  
    temp=lcddev.width;
  250.  
    lcddev.width=lcddev.height;
  251.  
    lcddev.height=temp;
  252.  
    }
  253.  
    }
  254.  
    }
  255.  
    if(lcddev.id==0X5510)
  256.  
    {
  257.  
    LCD_WR_REG(lcddev.setxcmd);LCD_WR_DATA(0);
  258.  
    LCD_WR_REG(lcddev.setxcmd 1);LCD_WR_DATA(0);
  259.  
    LCD_WR_REG(lcddev.setxcmd 2);LCD_WR_DATA((lcddev.width-1)>>8);
  260.  
    LCD_WR_REG(lcddev.setxcmd 3);LCD_WR_DATA((lcddev.width-1)&0XFF);
  261.  
    LCD_WR_REG(lcddev.setycmd);LCD_WR_DATA(0);
  262.  
    LCD_WR_REG(lcddev.setycmd 1);LCD_WR_DATA(0);
  263.  
    LCD_WR_REG(lcddev.setycmd 2);LCD_WR_DATA((lcddev.height-1)>>8);
  264.  
    LCD_WR_REG(lcddev.setycmd 3);LCD_WR_DATA((lcddev.height-1)&0XFF);
  265.  
    }else
  266.  
    {
  267.  
    LCD_WR_REG(lcddev.setxcmd);
  268.  
    LCD_WR_DATA(0);LCD_WR_DATA(0);
  269.  
    LCD_WR_DATA((lcddev.width-1)>>8);LCD_WR_DATA((lcddev.width-1)&0XFF);
  270.  
    LCD_WR_REG(lcddev.setycmd);
  271.  
    LCD_WR_DATA(0);LCD_WR_DATA(0);
  272.  
    LCD_WR_DATA((lcddev.height-1)>>8);LCD_WR_DATA((lcddev.height-1)&0XFF);
  273.  
    }
  274.  
    }
  275.  
    }
  276.  
    //画点
  277.  
    //x,y:坐标
  278.  
    //POINT_COLOR:此点的颜色
  279.  
    void LCD_DrawPoint(u16 x,u16 y)
  280.  
    {
  281.  
    LCD_SetCursor(x,y); //设置光标位置
  282.  
    LCD_WriteRAM_Prepare(); //开始写入GRAM
  283.  
    LCD->LCD_RAM=POINT_COLOR;
  284.  
    }
  285.  
    //快速画点
  286.  
    //x,y:坐标
  287.  
    //color:颜色
  288.  
    void LCD_Fast_DrawPoint(u16 x,u16 y,u32 color)
  289.  
    {
  290.  
    if(lcddev.id==0X9341||lcddev.id==0X5310||lcddev.id==0x7789)
  291.  
    {
  292.  
    LCD_WR_REG(lcddev.setxcmd);
  293.  
    LCD_WR_DATA(x>>8);LCD_WR_DATA(x&0XFF);
  294.  
    LCD_WR_REG(lcddev.setycmd);
  295.  
    LCD_WR_DATA(y>>8);LCD_WR_DATA(y&0XFF);
  296.  
    }else if(lcddev.id==0X5510)
  297.  
    {
  298.  
    LCD_WR_REG(lcddev.setxcmd);LCD_WR_DATA(x>>8);
  299.  
    LCD_WR_REG(lcddev.setxcmd 1);LCD_WR_DATA(x&0XFF);
  300.  
    LCD_WR_REG(lcddev.setycmd);LCD_WR_DATA(y>>8);
  301.  
    LCD_WR_REG(lcddev.setycmd 1);LCD_WR_DATA(y&0XFF);
  302.  
    }else if(lcddev.id==0X1963)
  303.  
    {
  304.  
    if(lcddev.dir==0)x=lcddev.width-1-x;
  305.  
    LCD_WR_REG(lcddev.setxcmd);
  306.  
    LCD_WR_DATA(x>>8);LCD_WR_DATA(x&0XFF);
  307.  
    LCD_WR_DATA(x>>8);LCD_WR_DATA(x&0XFF);
  308.  
    LCD_WR_REG(lcddev.setycmd);
  309.  
    LCD_WR_DATA(y>>8);LCD_WR_DATA(y&0XFF);
  310.  
    LCD_WR_DATA(y>>8);LCD_WR_DATA(y&0XFF);
  311.  
    }
  312.  
    LCD->LCD_REG=lcddev.wramcmd;
  313.  
    LCD->LCD_RAM=color;
  314.  
    }
  315.  
    //SSD1963 背光设置
  316.  
    //pwm:背光等级,0~100.越大越亮.
  317.  
    void LCD_SSD_BackLightSet(u8 pwm)
  318.  
    {
  319.  
    LCD_WR_REG(0xBE); //配置PWM输出
  320.  
    LCD_WR_DATA(0x05); //1设置PWM频率
  321.  
    LCD_WR_DATA(pwm*2.55);//2设置PWM占空比
  322.  
    LCD_WR_DATA(0x01); //3设置C
  323.  
    LCD_WR_DATA(0xFF); //4设置D
  324.  
    LCD_WR_DATA(0x00); //5设置E
  325.  
    LCD_WR_DATA(0x00); //6设置F
  326.  
    }
  327.  
     
  328.  
    //设置LCD显示方向
  329.  
    //dir:0,竖屏;1,横屏
  330.  
    void LCD_Display_Dir(u8 dir)
  331.  
    {
  332.  
    lcddev.dir=dir; //横屏/竖屏
  333.  
    if(dir==0) //竖屏
  334.  
    {
  335.  
    lcddev.width=240;
  336.  
    lcddev.height=320;
  337.  
    if(lcddev.id==0X9341||lcddev.id==0X5310||lcddev.id==0x7789)
  338.  
    {
  339.  
    lcddev.wramcmd=0X2C;
  340.  
    lcddev.setxcmd=0X2A;
  341.  
    lcddev.setycmd=0X2B;
  342.  
    if(lcddev.id==0X5310)
  343.  
    {
  344.  
    lcddev.width=320;
  345.  
    lcddev.height=480;
  346.  
    }
  347.  
    }else if(lcddev.id==0x5510)
  348.  
    {
  349.  
    lcddev.wramcmd=0X2C00;
  350.  
    lcddev.setxcmd=0X2A00;
  351.  
    lcddev.setycmd=0X2B00;
  352.  
    lcddev.width=480;
  353.  
    lcddev.height=800;
  354.  
    }else if(lcddev.id==0X1963)
  355.  
    {
  356.  
    lcddev.wramcmd=0X2C; //设置写入GRAM的指令
  357.  
    lcddev.setxcmd=0X2B; //设置写X坐标指令
  358.  
    lcddev.setycmd=0X2A; //设置写Y坐标指令
  359.  
    lcddev.width=480; //设置宽度480
  360.  
    lcddev.height=800; //设置高度800
  361.  
    }
  362.  
    }else //横屏
  363.  
    {
  364.  
    lcddev.width=320;
  365.  
    lcddev.height=240;
  366.  
    if(lcddev.id==0X9341||lcddev.id==0X5310||lcddev.id==0x7789)
  367.  
    {
  368.  
    lcddev.wramcmd=0X2C;
  369.  
    lcddev.setxcmd=0X2A;
  370.  
    lcddev.setycmd=0X2B;
  371.  
    }else if(lcddev.id==0x5510)
  372.  
    {
  373.  
    lcddev.wramcmd=0X2C00;
  374.  
    lcddev.setxcmd=0X2A00;
  375.  
    lcddev.setycmd=0X2B00;
  376.  
    lcddev.width=800;
  377.  
    lcddev.height=480;
  378.  
    }else if(lcddev.id==0X1963)
  379.  
    {
  380.  
    lcddev.wramcmd=0X2C; //设置写入GRAM的指令
  381.  
    lcddev.setxcmd=0X2A; //设置写X坐标指令
  382.  
    lcddev.setycmd=0X2B; //设置写Y坐标指令
  383.  
    lcddev.width=800; //设置宽度800
  384.  
    lcddev.height=480; //设置高度480
  385.  
    }
  386.  
    if(lcddev.id==0X5310)
  387.  
    {
  388.  
    lcddev.width=480;
  389.  
    lcddev.height=320;
  390.  
    }
  391.  
    }
  392.  
    LCD_Scan_Dir(DFT_SCAN_DIR); //默认扫描方向
  393.  
    }
  394.  
    //设置窗口(对RGB屏无效),并自动设置画点坐标到窗口左上角(sx,sy).
  395.  
    //sx,sy:窗口起始坐标(左上角)
  396.  
    //width,height:窗口宽度和高度,必须大于0!!
  397.  
    //窗体大小:width*height.
  398.  
    void LCD_Set_Window(u16 sx,u16 sy,u16 width,u16 height)
  399.  
    {
  400.  
    u16 twidth,theight;
  401.  
    twidth=sx width-1;
  402.  
    theight=sy height-1;
  403.  
    if(lcddev.id==0X9341||lcddev.id==0X5310||(lcddev.dir==1&&lcddev.id==0X1963))
  404.  
    {
  405.  
    LCD_WR_REG(lcddev.setxcmd);
  406.  
    LCD_WR_DATA(sx>>8);
  407.  
    LCD_WR_DATA(sx&0XFF);
  408.  
    LCD_WR_DATA(twidth>>8);
  409.  
    LCD_WR_DATA(twidth&0XFF);
  410.  
    LCD_WR_REG(lcddev.setycmd);
  411.  
    LCD_WR_DATA(sy>>8);
  412.  
    LCD_WR_DATA(sy&0XFF);
  413.  
    LCD_WR_DATA(theight>>8);
  414.  
    LCD_WR_DATA(theight&0XFF);
  415.  
    }else if(lcddev.id==0X1963)//1963竖屏特殊处理
  416.  
    {
  417.  
    sx=lcddev.width-width-sx;
  418.  
    height=sy height-1;
  419.  
    LCD_WR_REG(lcddev.setxcmd);
  420.  
    LCD_WR_DATA(sx>>8);
  421.  
    LCD_WR_DATA(sx&0XFF);
  422.  
    LCD_WR_DATA((sx width-1)>>8);
  423.  
    LCD_WR_DATA((sx width-1)&0XFF);
  424.  
    LCD_WR_REG(lcddev.setycmd);
  425.  
    LCD_WR_DATA(sy>>8);
  426.  
    LCD_WR_DATA(sy&0XFF);
  427.  
    LCD_WR_DATA(height>>8);
  428.  
    LCD_WR_DATA(height&0XFF);
  429.  
    }else if(lcddev.id==0X5510)
  430.  
    {
  431.  
    LCD_WR_REG(lcddev.setxcmd);LCD_WR_DATA(sx>>8);
  432.  
    LCD_WR_REG(lcddev.setxcmd 1);LCD_WR_DATA(sx&0XFF);
  433.  
    LCD_WR_REG(lcddev.setxcmd 2);LCD_WR_DATA(twidth>>8);
  434.  
    LCD_WR_REG(lcddev.setxcmd 3);LCD_WR_DATA(twidth&0XFF);
  435.  
    LCD_WR_REG(lcddev.setycmd);LCD_WR_DATA(sy>>8);
  436.  
    LCD_WR_REG(lcddev.setycmd 1);LCD_WR_DATA(sy&0XFF);
  437.  
    LCD_WR_REG(lcddev.setycmd 2);LCD_WR_DATA(theight>>8);
  438.  
    LCD_WR_REG(lcddev.setycmd 3);LCD_WR_DATA(theight&0XFF);
  439.  
    }
  440.  
    }
  441.  
     
  442.  
    //配置MPU的region,外部SRAM区配置为透写模式
  443.  
    void LCD_MPU_Config(void)
  444.  
    {
  445.  
    MPU_Region_InitTypeDef MPU_Initure;
  446.  
     
  447.  
    HAL_MPU_Disable(); //配置MPU之前先关闭MPU,配置完成以后在使能MPU
  448.  
    //外部SRAM为region0,大小为2MB,此区域可读写
  449.  
    MPU_Initure.Enable=MPU_REGION_ENABLE; //使能region
  450.  
    MPU_Initure.Number=LCD_REGION_NUMBER; //设置region,外部SRAM使用的region0
  451.  
    MPU_Initure.BaseAddress=LCD_ADDRESS_START; //region基地址
  452.  
    MPU_Initure.Size=LCD_REGION_SIZE; //region大小
  453.  
    MPU_Initure.SubRegionDisable=0X00;
  454.  
    MPU_Initure.TypeExtField=MPU_TEX_LEVEL0;
  455.  
    MPU_Initure.AccessPermission=MPU_REGION_FULL_ACCESS; //此region可读写
  456.  
    MPU_Initure.DisableExec=MPU_INSTRUCTION_ACCESS_ENABLE; //允许读取此区域中的指令
  457.  
    MPU_Initure.IsShareable=MPU_ACCESS_NOT_SHAREABLE;
  458.  
    MPU_Initure.IsCacheable=MPU_ACCESS_NOT_CACHEABLE;
  459.  
    MPU_Initure.IsBufferable=MPU_ACCESS_BUFFERABLE;
  460.  
    HAL_MPU_ConfigRegion(&MPU_Initure);
  461.  
    HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT); //开启MPU
  462.  
    }
  463.  
    //SRAM底层驱动,时钟使能,引脚分配
  464.  
    //此函数会被HAL_SRAM_Init()调用
  465.  
    //hsram:SRAM句柄
  466.  
    void HAL_SRAM_MspInit(SRAM_HandleTypeDef *hsram)
  467.  
    {
  468.  
    GPIO_InitTypeDef GPIO_Initure;
  469.  
     
  470.  
    __HAL_RCC_FMC_CLK_ENABLE(); //使能FMC时钟
  471.  
    __HAL_RCC_GPIOD_CLK_ENABLE(); //使能GPIOD时钟
  472.  
    __HAL_RCC_GPIOE_CLK_ENABLE(); //使能GPIOE时钟
  473.  
     
  474.  
    //初始化PD0,1,4,5,7,8,9,10,13,14,15
  475.  
    GPIO_Initure.Pin=GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_7|GPIO_PIN_8|\
  476.  
    GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
  477.  
    GPIO_Initure.Mode=GPIO_MODE_AF_PP; //复用
  478.  
    GPIO_Initure.Pull=GPIO_PULLUP; //上拉
  479.  
    GPIO_Initure.Speed=GPIO_SPEED_HIGH; //高速
  480.  
    GPIO_Initure.Alternate=GPIO_AF12_FMC; //复用为FMC
  481.  
    HAL_GPIO_Init(GPIOD,&GPIO_Initure);
  482.  
     
  483.  
    //初始化PE7,8,9,10,11,12,13,14,15
  484.  
    GPIO_Initure.Pin=GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|\
  485.  
    GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
  486.  
    HAL_GPIO_Init(GPIOE,&GPIO_Initure);
  487.  
    }
  488.  
     
  489.  
    //初始化lcd
  490.  
    //该初始化函数可以初始化各种型号的LCD(详见本.c文件最前面的描述)
  491.  
    void LCD_Init(void)
  492.  
    {
  493.  
    GPIO_InitTypeDef GPIO_Initure;
  494.  
    FMC_NORSRAM_TimingTypeDef FSMC_ReadWriteTim;
  495.  
    FMC_NORSRAM_TimingTypeDef FSMC_WriteTim;
  496.  
     
  497.  
    __HAL_RCC_GPIOB_CLK_ENABLE(); //开启GPIOB时钟
  498.  
    GPIO_Initure.Pin=GPIO_PIN_5; //PB5,背光控制
  499.  
    GPIO_Initure.Mode=GPIO_MODE_OUTPUT_PP; //推挽输出
  500.  
    GPIO_Initure.Pull=GPIO_PULLUP; //上拉
  501.  
    GPIO_Initure.Speed=GPIO_SPEED_HIGH; //高速
  502.  
    HAL_GPIO_Init(GPIOB,&GPIO_Initure);
  503.  
     
  504.  
    LCD_MPU_Config(); //使能MPU保护LCD区域
  505.  
    SRAM_Handler.Instance=FMC_NORSRAM_DEVICE;
  506.  
    SRAM_Handler.Extended=FMC_NORSRAM_EXTENDED_DEVICE;
  507.  
     
  508.  
    SRAM_Handler.Init.NSBank=FMC_NORSRAM_BANK1; //使用NE1
  509.  
    SRAM_Handler.Init.DataAddressMux=FMC_DATA_ADDRESS_MUX_DISABLE; //不复用数据线
  510.  
    SRAM_Handler.Init.MemoryType=FMC_MEMORY_TYPE_SRAM; //SRAM
  511.  
    SRAM_Handler.Init.MemoryDataWidth=FMC_NORSRAM_MEM_BUS_WIDTH_16; //16位数据宽度
  512.  
    SRAM_Handler.Init.WriteOperation=FMC_WRITE_OPERATION_ENABLE; //存储器写使能
  513.  
    SRAM_Handler.Init.ExtendedMode=FMC_EXTENDED_MODE_ENABLE; //读写使用不同的时序
  514.  
     
  515.  
    //FSMC读时序控制寄存器
  516.  
    FSMC_ReadWriteTim.AddressSetupTime=15; //地址建立时间(ADDSET)为15个HCLK 1/216M=4.6ns*15=69ns
  517.  
    FSMC_ReadWriteTim.AddressHoldTime=0x00;
  518.  
    FSMC_ReadWriteTim.DataSetupTime=80; //数据保存时间(DATAST)为85个HCLK =4.6*80=368ns
  519.  
    FSMC_ReadWriteTim.AccessMode=FMC_ACCESS_MODE_A; //模式A
  520.  
    //FSMC写时序控制寄存器
  521.  
    FSMC_WriteTim.AddressSetupTime=15; //地址建立时间(ADDSET)为15个HCLK=69ns
  522.  
    FSMC_WriteTim.AddressHoldTime=0x00;
  523.  
    FSMC_WriteTim.DataSetupTime=15; //数据保存时间(DATAST)为4.6ns*15个HCLK=69ns
  524.  
    FSMC_WriteTim.AccessMode=FMC_ACCESS_MODE_A; //模式A
  525.  
    HAL_SRAM_Init(&SRAM_Handler,&FSMC_ReadWriteTim,&FSMC_WriteTim);
  526.  
    delay_ms(50); // delay 50 ms
  527.  
     
  528.  
    //尝试9341 ID的读取
  529.  
    LCD_WR_REG(0XD3);
  530.  
    lcddev.id=LCD_RD_DATA(); //dummy read
  531.  
    lcddev.id=LCD_RD_DATA(); //读到0X00
  532.  
    lcddev.id=LCD_RD_DATA(); //读取93
  533.  
    lcddev.id<<=8;
  534.  
    lcddev.id|=LCD_RD_DATA(); //读取41
  535.  
    if(lcddev.id!=0X9341) //非9341,尝试看看是不是NT35310
  536.  
    {
  537.  
    LCD_WR_REG(0X04);
  538.  
    lcddev.id = LCD_RD_DATA(); //dummy read
  539.  
    lcddev.id = LCD_RD_DATA(); //读到0X85
  540.  
    lcddev.id = LCD_RD_DATA(); //读取0X85
  541.  
    lcddev.id <<= 8;
  542.  
    lcddev.id |= LCD_RD_DATA(); //读取0X52
  543.  
     
  544.  
    if (lcddev.id == 0X8552) //将8552的ID转换成7789
  545.  
    {
  546.  
    lcddev.id = 0x7789;
  547.  
    }
  548.  
     
  549.  
    if (lcddev.id != 0x7789) //也不是ST7789, 尝试是不是 NT35310
  550.  
    {
  551.  
    LCD_WR_REG(0XD4);
  552.  
    lcddev.id=LCD_RD_DATA();//dummy read
  553.  
    lcddev.id=LCD_RD_DATA();//读回0X01
  554.  
    lcddev.id=LCD_RD_DATA();//读回0X53
  555.  
    lcddev.id<<=8;
  556.  
     
  557.  
    lcddev.id|=LCD_RD_DATA(); //这里读回0X10
  558.  
    if(lcddev.id!=0X5310) //也不是NT35310,尝试看看是不是NT35510
  559.  
    {
  560.  
    //发送秘钥(厂家提供,照搬即可)
  561.  
    LCD_WriteReg(0xF000, 0x0055);
  562.  
    LCD_WriteReg(0xF001, 0x00AA);
  563.  
    LCD_WriteReg(0xF002, 0x0052);
  564.  
    LCD_WriteReg(0xF003, 0x0008);
  565.  
    LCD_WriteReg(0xF004, 0x0001);
  566.  
     
  567.  
    LCD_WR_REG(0xC500); //读取ID高8位
  568.  
    lcddev.id = LCD_RD_DATA(); //读回0X55
  569.  
    lcddev.id <<= 8;
  570.  
     
  571.  
    LCD_WR_REG(0xC501); //读取ID低8位
  572.  
    lcddev.id |= LCD_RD_DATA(); //读回0X10
  573.  
    delay_ms(5); //兼容1963驱动
  574.  
     
  575.  
    if(lcddev.id==0x8000)lcddev.id=0x5510;//NT35510读回的ID是8000H,为方便区分,我们强制设置为5510
  576.  
    if(lcddev.id!=0X5510) //也不是NT5510,尝试看看是不是SSD1963
  577.  
    {
  578.  
    LCD_WR_REG(0XA1);
  579.  
    lcddev.id=LCD_RD_DATA();
  580.  
    lcddev.id=LCD_RD_DATA(); //读回0X57
  581.  
    lcddev.id<<=8;
  582.  
    lcddev.id|=LCD_RD_DATA(); //读回0X61
  583.  
    if(lcddev.id==0X5761)lcddev.id=0X1963;//SSD1963读回的ID是5761H,为方便区分,我们强制设置为1963
  584.  
    }
  585.  
    }
  586.  
    }
  587.  
    }
  588.  
    printf(" LCD ID:%x\r\n",lcddev.id); //打印LCD ID
  589.  
    if(lcddev.id==0X9341) //9341初始化
  590.  
    {
  591.  
    LCD_WR_REG(0xCF);
  592.  
    LCD_WR_DATA(0x00);
  593.  
    LCD_WR_DATA(0xC1);
  594.  
    LCD_WR_DATA(0X30);
  595.  
    LCD_WR_REG(0xED);
  596.  
    LCD_WR_DATA(0x64);
  597.  
    LCD_WR_DATA(0x03);
  598.  
    LCD_WR_DATA(0X12);
  599.  
    LCD_WR_DATA(0X81);
  600.  
    LCD_WR_REG(0xE8);
  601.  
    LCD_WR_DATA(0x85);
  602.  
    LCD_WR_DATA(0x10);
  603.  
    LCD_WR_DATA(0x7A);
  604.  
    LCD_WR_REG(0xCB);
  605.  
    LCD_WR_DATA(0x39);
  606.  
    LCD_WR_DATA(0x2C);
  607.  
    LCD_WR_DATA(0x00);
  608.  
    LCD_WR_DATA(0x34);
  609.  
    LCD_WR_DATA(0x02);
  610.  
    LCD_WR_REG(0xF7);
  611.  
    LCD_WR_DATA(0x20);
  612.  
    LCD_WR_REG(0xEA);
  613.  
    LCD_WR_DATA(0x00);
  614.  
    LCD_WR_DATA(0x00);
  615.  
    LCD_WR_REG(0xC0); //Power control
  616.  
    LCD_WR_DATA(0x1B); //VRH[5:0]
  617.  
    LCD_WR_REG(0xC1); //Power control
  618.  
    LCD_WR_DATA(0x01); //SAP[2:0];BT[3:0]
  619.  
    LCD_WR_REG(0xC5); //VCM control
  620.  
    LCD_WR_DATA(0x30); //3F
  621.  
    LCD_WR_DATA(0x30); //3C
  622.  
    LCD_WR_REG(0xC7); //VCM control2
  623.  
    LCD_WR_DATA(0XB7);
  624.  
    LCD_WR_REG(0x36); // Memory Access Control
  625.  
    LCD_WR_DATA(0x48);
  626.  
    LCD_WR_REG(0x3A);
  627.  
    LCD_WR_DATA(0x55);
  628.  
    LCD_WR_REG(0xB1);
  629.  
    LCD_WR_DATA(0x00);
  630.  
    LCD_WR_DATA(0x1A);
  631.  
    LCD_WR_REG(0xB6); // Display Function Control
  632.  
    LCD_WR_DATA(0x0A);
  633.  
    LCD_WR_DATA(0xA2);
  634.  
    LCD_WR_REG(0xF2); // 3Gamma Function Disable
  635.  
    LCD_WR_DATA(0x00);
  636.  
    LCD_WR_REG(0x26); //Gamma curve selected
  637.  
    LCD_WR_DATA(0x01);
  638.  
    LCD_WR_REG(0xE0); //Set Gamma
  639.  
    LCD_WR_DATA(0x0F);
  640.  
    LCD_WR_DATA(0x2A);
  641.  
    LCD_WR_DATA(0x28);
  642.  
    LCD_WR_DATA(0x08);
  643.  
    LCD_WR_DATA(0x0E);
  644.  
    LCD_WR_DATA(0x08);
  645.  
    LCD_WR_DATA(0x54);
  646.  
    LCD_WR_DATA(0XA9);
  647.  
    LCD_WR_DATA(0x43);
  648.  
    LCD_WR_DATA(0x0A);
  649.  
    LCD_WR_DATA(0x0F);
  650.  
    LCD_WR_DATA(0x00);
  651.  
    LCD_WR_DATA(0x00);
  652.  
    LCD_WR_DATA(0x00);
  653.  
    LCD_WR_DATA(0x00);
  654.  
    LCD_WR_REG(0XE1); //Set Gamma
  655.  
    LCD_WR_DATA(0x00);
  656.  
    LCD_WR_DATA(0x15);
  657.  
    LCD_WR_DATA(0x17);
  658.  
    LCD_WR_DATA(0x07);
  659.  
    LCD_WR_DATA(0x11);
  660.  
    LCD_WR_DATA(0x06);
  661.  
    LCD_WR_DATA(0x2B);
  662.  
    LCD_WR_DATA(0x56);
  663.  
    LCD_WR_DATA(0x3C);
  664.  
    LCD_WR_DATA(0x05);
  665.  
    LCD_WR_DATA(0x10);
  666.  
    LCD_WR_DATA(0x0F);
  667.  
    LCD_WR_DATA(0x3F);
  668.  
    LCD_WR_DATA(0x3F);
  669.  
    LCD_WR_DATA(0x0F);
  670.  
    LCD_WR_REG(0x2B);
  671.  
    LCD_WR_DATA(0x00);
  672.  
    LCD_WR_DATA(0x00);
  673.  
    LCD_WR_DATA(0x01);
  674.  
    LCD_WR_DATA(0x3f);
  675.  
    LCD_WR_REG(0x2A);
  676.  
    LCD_WR_DATA(0x00);
  677.  
    LCD_WR_DATA(0x00);
  678.  
    LCD_WR_DATA(0x00);
  679.  
    LCD_WR_DATA(0xef);
  680.  
    LCD_WR_REG(0x11); //Exit Sleep
  681.  
    delay_ms(120);
  682.  
    LCD_WR_REG(0x29); //display on
  683.  
    }
  684.  
    else if(lcddev.id==0x7789) //7789初始化
  685.  
    {
  686.  
    LCD_WR_REG(0x11);
  687.  
     
  688.  
    delay_ms(120);
  689.  
     
  690.  
    LCD_WR_REG(0x36);
  691.  
    LCD_WR_DATA(0x00);
  692.  
     
  693.  
     
  694.  
    LCD_WR_REG(0x3A);
  695.  
    LCD_WR_DATA(0X05);
  696.  
     
  697.  
    LCD_WR_REG(0xB2);
  698.  
    LCD_WR_DATA(0x0C);
  699.  
    LCD_WR_DATA(0x0C);
  700.  
    LCD_WR_DATA(0x00);
  701.  
    LCD_WR_DATA(0x33);
  702.  
    LCD_WR_DATA(0x33);
  703.  
     
  704.  
    LCD_WR_REG(0xB7);
  705.  
    LCD_WR_DATA(0x35);
  706.  
     
  707.  
    LCD_WR_REG(0xBB); //vcom
  708.  
    LCD_WR_DATA(0x32); //30
  709.  
     
  710.  
    LCD_WR_REG(0xC0);
  711.  
    LCD_WR_DATA(0x0C);
  712.  
     
  713.  
    LCD_WR_REG(0xC2);
  714.  
    LCD_WR_DATA(0x01);
  715.  
     
  716.  
    LCD_WR_REG(0xC3); //vrh
  717.  
    LCD_WR_DATA(0x10); //17 0D
  718.  
     
  719.  
    LCD_WR_REG(0xC4); //vdv
  720.  
    LCD_WR_DATA(0x20); //20
  721.  
     
  722.  
    LCD_WR_REG(0xC6);
  723.  
    LCD_WR_DATA(0x0f);
  724.  
     
  725.  
    LCD_WR_REG(0xD0);
  726.  
    LCD_WR_DATA(0xA4);
  727.  
    LCD_WR_DATA(0xA1);
  728.  
     
  729.  
    LCD_WR_REG(0xE0); //Set Gamma
  730.  
    LCD_WR_DATA(0xd0);
  731.  
    LCD_WR_DATA(0x00);
  732.  
    LCD_WR_DATA(0x02);
  733.  
    LCD_WR_DATA(0x07);
  734.  
    LCD_WR_DATA(0x0a);
  735.  
    LCD_WR_DATA(0x28);
  736.  
    LCD_WR_DATA(0x32);
  737.  
    LCD_WR_DATA(0X44);
  738.  
    LCD_WR_DATA(0x42);
  739.  
    LCD_WR_DATA(0x06);
  740.  
    LCD_WR_DATA(0x0e);
  741.  
    LCD_WR_DATA(0x12);
  742.  
    LCD_WR_DATA(0x14);
  743.  
    LCD_WR_DATA(0x17);
  744.  
     
  745.  
     
  746.  
    LCD_WR_REG(0XE1); //Set Gamma
  747.  
    LCD_WR_DATA(0xd0);
  748.  
    LCD_WR_DATA(0x00);
  749.  
    LCD_WR_DATA(0x02);
  750.  
    LCD_WR_DATA(0x07);
  751.  
    LCD_WR_DATA(0x0a);
  752.  
    LCD_WR_DATA(0x28);
  753.  
    LCD_WR_DATA(0x31);
  754.  
    LCD_WR_DATA(0x54);
  755.  
    LCD_WR_DATA(0x47);
  756.  
    LCD_WR_DATA(0x0e);
  757.  
    LCD_WR_DATA(0x1c);
  758.  
    LCD_WR_DATA(0x17);
  759.  
    LCD_WR_DATA(0x1b);
  760.  
    LCD_WR_DATA(0x1e);
  761.  
     
  762.  
    LCD_WR_REG(0x2A);
  763.  
    LCD_WR_DATA(0x00);
  764.  
    LCD_WR_DATA(0x00);
  765.  
    LCD_WR_DATA(0x00);
  766.  
    LCD_WR_DATA(0xef);
  767.  
     
  768.  
    LCD_WR_REG(0x2B);
  769.  
    LCD_WR_DATA(0x00);
  770.  
    LCD_WR_DATA(0x00);
  771.  
    LCD_WR_DATA(0x01);
  772.  
    LCD_WR_DATA(0x3f);
  773.  
     
  774.  
    LCD_WR_REG(0x29); //display on
  775.  
    }
  776.  
    else if(lcddev.id==0x5310)
  777.  
    {
  778.  
    LCD_WR_REG(0xED);
  779.  
    LCD_WR_DATA(0x01);
  780.  
    LCD_WR_DATA(0xFE);
  781.  
     
  782.  
    LCD_WR_REG(0xEE);
  783.  
    LCD_WR_DATA(0xDE);
  784.  
    LCD_WR_DATA(0x21);
  785.  
     
  786.  
    LCD_WR_REG(0xF1);
  787.  
    LCD_WR_DATA(0x01);
  788.  
    LCD_WR_REG(0xDF);
  789.  
    LCD_WR_DATA(0x10);
  790.  
     
  791.  
    //VCOMvoltage//
  792.  
    LCD_WR_REG(0xC4);
  793.  
    LCD_WR_DATA(0x8F); //5f
  794.  
     
  795.  
    LCD_WR_REG(0xC6);
  796.  
    LCD_WR_DATA(0x00);
  797.  
    LCD_WR_DATA(0xE2);
  798.  
    LCD_WR_DATA(0xE2);
  799.  
    LCD_WR_DATA(0xE2);
  800.  
    LCD_WR_REG(0xBF);
  801.  
    LCD_WR_DATA(0xAA);
  802.  
     
  803.  
    LCD_WR_REG(0xB0);
  804.  
    LCD_WR_DATA(0x0D);
  805.  
    LCD_WR_DATA(0x00);
  806.  
    LCD_WR_DATA(0x0D);
  807.  
    LCD_WR_DATA(0x00);
  808.  
    LCD_WR_DATA(0x11);
  809.  
    LCD_WR_DATA(0x00);
  810.  
    LCD_WR_DATA(0x19);
  811.  
    LCD_WR_DATA(0x00);
  812.  
    LCD_WR_DATA(0x21);
  813.  
    LCD_WR_DATA(0x00);
  814.  
    LCD_WR_DATA(0x2D);
  815.  
    LCD_WR_DATA(0x00);
  816.  
    LCD_WR_DATA(0x3D);
  817.  
    LCD_WR_DATA(0x00);
  818.  
    LCD_WR_DATA(0x5D);
  819.  
    LCD_WR_DATA(0x00);
  820.  
    LCD_WR_DATA(0x5D);
  821.  
    LCD_WR_DATA(0x00);
  822.  
     
  823.  
    LCD_WR_REG(0xB1);
  824.  
    LCD_WR_DATA(0x80);
  825.  
    LCD_WR_DATA(0x00);
  826.  
    LCD_WR_DATA(0x8B);
  827.  
    LCD_WR_DATA(0x00);
  828.  
    LCD_WR_DATA(0x96);
  829.  
    LCD_WR_DATA(0x00);
  830.  
     
  831.  
    LCD_WR_REG(0xB2);
  832.  
    LCD_WR_DATA(0x00);
  833.  
    LCD_WR_DATA(0x00);
  834.  
    LCD_WR_DATA(0x02);
  835.  
    LCD_WR_DATA(0x00);
  836.  
    LCD_WR_DATA(0x03);
  837.  
    LCD_WR_DATA(0x00);
  838.  
     
  839.  
    LCD_WR_REG(0xB3);
  840.  
    LCD_WR_DATA(0x00);
  841.  
    LCD_WR_DATA(0x00);
  842.  
    LCD_WR_DATA(0x00);
  843.  
    LCD_WR_DATA(0x00);
  844.  
    LCD_WR_DATA(0x00);
  845.  
    LCD_WR_DATA(0x00);
  846.  
    LCD_WR_DATA(0x00);
  847.  
    LCD_WR_DATA(0x00);
  848.  
    LCD_WR_DATA(0x00);
  849.  
    LCD_WR_DATA(0x00);
  850.  
    LCD_WR_DATA(0x00);
  851.  
    LCD_WR_DATA(0x00);
  852.  
    LCD_WR_DATA(0x00);
  853.  
    LCD_WR_DATA(0x00);
  854.  
    LCD_WR_DATA(0x00);
  855.  
    LCD_WR_DATA(0x00);
  856.  
    LCD_WR_DATA(0x00);
  857.  
    LCD_WR_DATA(0x00);
  858.  
    LCD_WR_DATA(0x00);
  859.  
    LCD_WR_DATA(0x00);
  860.  
    LCD_WR_DATA(0x00);
  861.  
    LCD_WR_DATA(0x00);
  862.  
    LCD_WR_DATA(0x00);
  863.  
    LCD_WR_DATA(0x00);
  864.  
     
  865.  
    LCD_WR_REG(0xB4);
  866.  
    LCD_WR_DATA(0x8B);
  867.  
    LCD_WR_DATA(0x00);
  868.  
    LCD_WR_DATA(0x96);
  869.  
    LCD_WR_DATA(0x00);
  870.  
    LCD_WR_DATA(0xA1);
  871.  
    LCD_WR_DATA(0x00);
  872.  
     
  873.  
    LCD_WR_REG(0xB5);
  874.  
    LCD_WR_DATA(0x02);
  875.  
    LCD_WR_DATA(0x00);
  876.  
    LCD_WR_DATA(0x03);
  877.  
    LCD_WR_DATA(0x00);
  878.  
    LCD_WR_DATA(0x04);
  879.  
    LCD_WR_DATA(0x00);
  880.  
     
  881.  
    LCD_WR_REG(0xB6);
  882.  
    LCD_WR_DATA(0x00);
  883.  
    LCD_WR_DATA(0x00);
  884.  
     
  885.  
    LCD_WR_REG(0xB7);
  886.  
    LCD_WR_DATA(0x00);
  887.  
    LCD_WR_DATA(0x00);
  888.  
    LCD_WR_DATA(0x3F);
  889.  
    LCD_WR_DATA(0x00);
  890.  
    LCD_WR_DATA(0x5E);
  891.  
    LCD_WR_DATA(0x00);
  892.  
    LCD_WR_DATA(0x64);
  893.  
    LCD_WR_DATA(0x00);
  894.  
    LCD_WR_DATA(0x8C);
  895.  
    LCD_WR_DATA(0x00);
  896.  
    LCD_WR_DATA(0xAC);
  897.  
    LCD_WR_DATA(0x00);
  898.  
    LCD_WR_DATA(0xDC);
  899.  
    LCD_WR_DATA(0x00);
  900.  
    LCD_WR_DATA(0x70);
  901.  
    LCD_WR_DATA(0x00);
  902.  
    LCD_WR_DATA(0x90);
  903.  
    LCD_WR_DATA(0x00);
  904.  
    LCD_WR_DATA(0xEB);
  905.  
    LCD_WR_DATA(0x00);
  906.  
    LCD_WR_DATA(0xDC);
  907.  
    LCD_WR_DATA(0x00);
  908.  
     
  909.  
    LCD_WR_REG(0xB8);
  910.  
    LCD_WR_DATA(0x00);
  911.  
    LCD_WR_DATA(0x00);
  912.  
    LCD_WR_DATA(0x00);
  913.  
    LCD_WR_DATA(0x00);
  914.  
    LCD_WR_DATA(0x00);
  915.  
    LCD_WR_DATA(0x00);
  916.  
    LCD_WR_DATA(0x00);
  917.  
    LCD_WR_DATA(0x00);
  918.  
     
  919.  
    LCD_WR_REG(0xBA);
  920.  
    LCD_WR_DATA(0x24);
  921.  
    LCD_WR_DATA(0x00);
  922.  
    LCD_WR_DATA(0x00);
  923.  
    LCD_WR_DATA(0x00);
  924.  
     
  925.  
    LCD_WR_REG(0xC1);
  926.  
    LCD_WR_DATA(0x20);
  927.  
    LCD_WR_DATA(0x00);
  928.  
    LCD_WR_DATA(0x54);
  929.  
    LCD_WR_DATA(0x00);
  930.  
    LCD_WR_DATA(0xFF);
  931.  
    LCD_WR_DATA(0x00);
  932.  
     
  933.  
    LCD_WR_REG(0xC2);
  934.  
    LCD_WR_DATA(0x0A);
  935.  
    LCD_WR_DATA(0x00);
  936.  
    LCD_WR_DATA(0x04);
  937.  
    LCD_WR_DATA(0x00);
  938.  
     
  939.  
    LCD_WR_REG(0xC3);
  940.  
    LCD_WR_DATA(0x3C);
  941.  
    LCD_WR_DATA(0x00);
  942.  
    LCD_WR_DATA(0x3A);
  943.  
    LCD_WR_DATA(0x00);
  944.  
    LCD_WR_DATA(0x39);
  945.  
    LCD_WR_DATA(0x00);
  946.  
    LCD_WR_DATA(0x37);
  947.  
    LCD_WR_DATA(0x00);
  948.  
    LCD_WR_DATA(0x3C);
  949.  
    LCD_WR_DATA(0x00);
  950.  
    LCD_WR_DATA(0x36);
  951.  
    LCD_WR_DATA(0x00);
  952.  
    LCD_WR_DATA(0x32);
  953.  
    LCD_WR_DATA(0x00);
  954.  
    LCD_WR_DATA(0x2F);
  955.  
    LCD_WR_DATA(0x00);
  956.  
    LCD_WR_DATA(0x2C);
  957.  
    LCD_WR_DATA(0x00);
  958.  
    LCD_WR_DATA(0x29);
  959.  
    LCD_WR_DATA(0x00);
  960.  
    LCD_WR_DATA(0x26);
  961.  
    LCD_WR_DATA(0x00);
  962.  
    LCD_WR_DATA(0x24);
  963.  
    LCD_WR_DATA(0x00);
  964.  
    LCD_WR_DATA(0x24);
  965.  
    LCD_WR_DATA(0x00);
  966.  
    LCD_WR_DATA(0x23);
  967.  
    LCD_WR_DATA(0x00);
  968.  
    LCD_WR_DATA(0x3C);
  969.  
    LCD_WR_DATA(0x00);
  970.  
    LCD_WR_DATA(0x36);
  971.  
    LCD_WR_DATA(0x00);
  972.  
    LCD_WR_DATA(0x32);
  973.  
    LCD_WR_DATA(0x00);
  974.  
    LCD_WR_DATA(0x2F);
  975.  
    LCD_WR_DATA(0x00);
  976.  
    LCD_WR_DATA(0x2C);
  977.  
    LCD_WR_DATA(0x00);
  978.  
    LCD_WR_DATA(0x29);
  979.  
    LCD_WR_DATA(0x00);
  980.  
    LCD_WR_DATA(0x26);
  981.  
    LCD_WR_DATA(0x00);
  982.  
    LCD_WR_DATA(0x24);
  983.  
    LCD_WR_DATA(0x00);
  984.  
    LCD_WR_DATA(0x24);
  985.  
    LCD_WR_DATA(0x00);
  986.  
    LCD_WR_DATA(0x23);
  987.  
    LCD_WR_DATA(0x00);
  988.  
     
  989.  
    LCD_WR_REG(0xC4);
  990.  
    LCD_WR_DATA(0x62);
  991.  
    LCD_WR_DATA(0x00);
  992.  
    LCD_WR_DATA(0x05);
  993.  
    LCD_WR_DATA(0x00);
  994.  
    LCD_WR_DATA(0x84);
  995.  
    LCD_WR_DATA(0x00);
  996.  
    LCD_WR_DATA(0xF0);
  997.  
    LCD_WR_DATA(0x00);
  998.  
    LCD_WR_DATA(0x18);
  999.  
    LCD_WR_DATA(0x00);
  1000.  
    LCD_WR_DATA(0xA4);
  1001.  
    LCD_WR_DATA(0x00);
  1002.  
    LCD_WR_DATA(0x18);
  1003.  
    LCD_WR_DATA(0x00);
  1004.  
    LCD_WR_DATA(0x50);
  1005.  
    LCD_WR_DATA(0x00);
  1006.  
    LCD_WR_DATA(0x0C);
  1007.  
    LCD_WR_DATA(0x00);
  1008.  
    LCD_WR_DATA(0x17);
  1009.  
    LCD_WR_DATA(0x00);
  1010.  
    LCD_WR_DATA(0x95);
  1011.  
    LCD_WR_DATA(0x00);
  1012.  
    LCD_WR_DATA(0xF3);
  1013.  
    LCD_WR_DATA(0x00);
  1014.  
    LCD_WR_DATA(0xE6);
  1015.  
    LCD_WR_DATA(0x00);
  1016.  
     
  1017.  
    LCD_WR_REG(0xC5);
  1018.  
    LCD_WR_DATA(0x32);
  1019.  
    LCD_WR_DATA(0x00);
  1020.  
    LCD_WR_DATA(0x44);
  1021.  
    LCD_WR_DATA(0x00);
  1022.  
    LCD_WR_DATA(0x65);
  1023.  
    LCD_WR_DATA(0x00);
  1024.  
    LCD_WR_DATA(0x76);
  1025.  
    LCD_WR_DATA(0x00);
  1026.  
    LCD_WR_DATA(0x88);
  1027.  
    LCD_WR_DATA(0x00);
  1028.  
     
  1029.  
    LCD_WR_REG(0xC6);
  1030.  
    LCD_WR_DATA(0x20);
  1031.  
    LCD_WR_DATA(0x00);
  1032.  
    LCD_WR_DATA(0x17);
  1033.  
    LCD_WR_DATA(0x00);
  1034.  
    LCD_WR_DATA(0x01);
  1035.  
    LCD_WR_DATA(0x00);
  1036.  
     
  1037.  
    LCD_WR_REG(0xC7);
  1038.  
    LCD_WR_DATA(0x00);
  1039.  
    LCD_WR_DATA(0x00);
  1040.  
    LCD_WR_DATA(0x00);
  1041.  
    LCD_WR_DATA(0x00);
  1042.  
     
  1043.  
    LCD_WR_REG(0xC8);
  1044.  
    LCD_WR_DATA(0x00);
  1045.  
    LCD_WR_DATA(0x00);
  1046.  
    LCD_WR_DATA(0x00);
  1047.  
    LCD_WR_DATA(0x00);
  1048.  
     
  1049.  
    LCD_WR_REG(0xC9);
  1050.  
    LCD_WR_DATA(0x00);
  1051.  
    LCD_WR_DATA(0x00);
  1052.  
    LCD_WR_DATA(0x00);
  1053.  
    LCD_WR_DATA(0x00);
  1054.  
    LCD_WR_DATA(0x00);
  1055.  
    LCD_WR_DATA(0x00);
  1056.  
    LCD_WR_DATA(0x00);
  1057.  
    LCD_WR_DATA(0x00);
  1058.  
    LCD_WR_DATA(0x00);
  1059.  
    LCD_WR_DATA(0x00);
  1060.  
    LCD_WR_DATA(0x00);
  1061.  
    LCD_WR_DATA(0x00);
  1062.  
    LCD_WR_DATA(0x00);
  1063.  
    LCD_WR_DATA(0x00);
  1064.  
    LCD_WR_DATA(0x00);
  1065.  
    LCD_WR_DATA(0x00);
  1066.  
     
  1067.  
    LCD_WR_REG(0xE0);
  1068.  
    LCD_WR_DATA(0x16);
  1069.  
    LCD_WR_DATA(0x00);
  1070.  
    LCD_WR_DATA(0x1C);
  1071.  
    LCD_WR_DATA(0x00);
  1072.  
    LCD_WR_DATA(0x21);
  1073.  
    LCD_WR_DATA(0x00);
  1074.  
    LCD_WR_DATA(0x36);
  1075.  
    LCD_WR_DATA(0x00);
  1076.  
    LCD_WR_DATA(0x46);
  1077.  
    LCD_WR_DATA(0x00);
  1078.  
    LCD_WR_DATA(0x52);
  1079.  
    LCD_WR_DATA(0x00);
  1080.  
    LCD_WR_DATA(0x64);
  1081.  
    LCD_WR_DATA(0x00);
  1082.  
    LCD_WR_DATA(0x7A);
  1083.  
    LCD_WR_DATA(0x00);
  1084.  
    LCD_WR_DATA(0x8B);
  1085.  
    LCD_WR_DATA(0x00);
  1086.  
    LCD_WR_DATA(0x99);
  1087.  
    LCD_WR_DATA(0x00);
  1088.  
    LCD_WR_DATA(0xA8);
  1089.  
    LCD_WR_DATA(0x00);
  1090.  
    LCD_WR_DATA(0xB9);
  1091.  
    LCD_WR_DATA(0x00);
  1092.  
    LCD_WR_DATA(0xC4);
  1093.  
    LCD_WR_DATA(0x00);
  1094.  
    LCD_WR_DATA(0xCA);
  1095.  
    LCD_WR_DATA(0x00);
  1096.  
    LCD_WR_DATA(0xD2);
  1097.  
    LCD_WR_DATA(0x00);
  1098.  
    LCD_WR_DATA(0xD9);
  1099.  
    LCD_WR_DATA(0x00);
  1100.  
    LCD_WR_DATA(0xE0);
  1101.  
    LCD_WR_DATA(0x00);
  1102.  
    LCD_WR_DATA(0xF3);
  1103.  
    LCD_WR_DATA(0x00);
  1104.  
     
  1105.  
    LCD_WR_REG(0xE1);
  1106.  
    LCD_WR_DATA(0x16);
  1107.  
    LCD_WR_DATA(0x00);
  1108.  
    LCD_WR_DATA(0x1C);
  1109.  
    LCD_WR_DATA(0x00);
  1110.  
    LCD_WR_DATA(0x22);
  1111.  
    LCD_WR_DATA(0x00);
  1112.  
    LCD_WR_DATA(0x36);
  1113.  
    LCD_WR_DATA(0x00);
  1114.  
    LCD_WR_DATA(0x45);
  1115.  
    LCD_WR_DATA(0x00);
  1116.  
    LCD_WR_DATA(0x52);
  1117.  
    LCD_WR_DATA(0x00);
  1118.  
    LCD_WR_DATA(0x64);
  1119.  
    LCD_WR_DATA(0x00);
  1120.  
    LCD_WR_DATA(0x7A);
  1121.  
    LCD_WR_DATA(0x00);
  1122.  
    LCD_WR_DATA(0x8B);
  1123.  
    LCD_WR_DATA(0x00);
  1124.  
    LCD_WR_DATA(0x99);
  1125.  
    LCD_WR_DATA(0x00);
  1126.  
    LCD_WR_DATA(0xA8);
  1127.  
    LCD_WR_DATA(0x00);
  1128.  
    LCD_WR_DATA(0xB9);
  1129.  
    LCD_WR_DATA(0x00);
  1130.  
    LCD_WR_DATA(0xC4);
  1131.  
    LCD_WR_DATA(0x00);
  1132.  
    LCD_WR_DATA(0xCA);
  1133.  
    LCD_WR_DATA(0x00);
  1134.  
    LCD_WR_DATA(0xD2);
  1135.  
    LCD_WR_DATA(0x00);
  1136.  
    LCD_WR_DATA(0xD8);
  1137.  
    LCD_WR_DATA(0x00);
  1138.  
    LCD_WR_DATA(0xE0);
  1139.  
    LCD_WR_DATA(0x00);
  1140.  
    LCD_WR_DATA(0xF3);
  1141.  
    LCD_WR_DATA(0x00);
  1142.  
     
  1143.  
    LCD_WR_REG(0xE2);
  1144.  
    LCD_WR_DATA(0x05);
  1145.  
    LCD_WR_DATA(0x00);
  1146.  
    LCD_WR_DATA(0x0B);
  1147.  
    LCD_WR_DATA(0x00);
  1148.  
    LCD_WR_DATA(0x1B);
  1149.  
    LCD_WR_DATA(0x00);
  1150.  
    LCD_WR_DATA(0x34);
  1151.  
    LCD_WR_DATA(0x00);
  1152.  
    LCD_WR_DATA(0x44);
  1153.  
    LCD_WR_DATA(0x00);
  1154.  
    LCD_WR_DATA(0x4F);
  1155.  
    LCD_WR_DATA(0x00);
  1156.  
    LCD_WR_DATA(0x61);
  1157.  
    LCD_WR_DATA(0x00);
  1158.  
    LCD_WR_DATA(0x79);
  1159.  
    LCD_WR_DATA(0x00);
  1160.  
    LCD_WR_DATA(0x88);
  1161.  
    LCD_WR_DATA(0x00);
  1162.  
    LCD_WR_DATA(0x97);
  1163.  
    LCD_WR_DATA(0x00);
  1164.  
    LCD_WR_DATA(0xA6);
  1165.  
    LCD_WR_DATA(0x00);
  1166.  
    LCD_WR_DATA(0xB7);
  1167.  
    LCD_WR_DATA(0x00);
  1168.  
    LCD_WR_DATA(0xC2);
  1169.  
    LCD_WR_DATA(0x00);
  1170.  
    LCD_WR_DATA(0xC7);
  1171.  
    LCD_WR_DATA(0x00);
  1172.  
    LCD_WR_DATA(0xD1);
  1173.  
    LCD_WR_DATA(0x00);
  1174.  
    LCD_WR_DATA(0xD6);
  1175.  
    LCD_WR_DATA(0x00);
  1176.  
    LCD_WR_DATA(0xDD);
  1177.  
    LCD_WR_DATA(0x00);
  1178.  
    LCD_WR_DATA(0xF3);
  1179.  
    LCD_WR_DATA(0x00);
  1180.  
    LCD_WR_REG(0xE3);
  1181.  
    LCD_WR_DATA(0x05);
  1182.  
    LCD_WR_DATA(0x00);
  1183.  
    LCD_WR_DATA(0xA);
  1184.  
    LCD_WR_DATA(0x00);
  1185.  
    LCD_WR_DATA(0x1C);
  1186.  
    LCD_WR_DATA(0x00);
  1187.  
    LCD_WR_DATA(0x33);
  1188.  
    LCD_WR_DATA(0x00);
  1189.  
    LCD_WR_DATA(0x44);
  1190.  
    LCD_WR_DATA(0x00);
  1191.  
    LCD_WR_DATA(0x50);
  1192.  
    LCD_WR_DATA(0x00);
  1193.  
    LCD_WR_DATA(0x62);
  1194.  
    LCD_WR_DATA(0x00);
  1195.  
    LCD_WR_DATA(0x78);
  1196.  
    LCD_WR_DATA(0x00);
  1197.  
    LCD_WR_DATA(0x88);
  1198.  
    LCD_WR_DATA(0x00);
  1199.  
    LCD_WR_DATA(0x97);
  1200.  
    LCD_WR_DATA(0x00);
  1201.  
    LCD_WR_DATA(0xA6);
  1202.  
    LCD_WR_DATA(0x00);
  1203.  
    LCD_WR_DATA(0xB7);
  1204.  
    LCD_WR_DATA(0x00);
  1205.  
    LCD_WR_DATA(0xC2);
  1206.  
    LCD_WR_DATA(0x00);
  1207.  
    LCD_WR_DATA(0xC7);
  1208.  
    LCD_WR_DATA(0x00);
  1209.  
    LCD_WR_DATA(0xD1);
  1210.  
    LCD_WR_DATA(0x00);
  1211.  
    LCD_WR_DATA(0xD5);
  1212.  
    LCD_WR_DATA(0x00);
  1213.  
    LCD_WR_DATA(0xDD);
  1214.  
    LCD_WR_DATA(0x00);
  1215.  
    LCD_WR_DATA(0xF3);
  1216.  
    LCD_WR_DATA(0x00);
  1217.  
     
  1218.  
    LCD_WR_REG(0xE4);
  1219.  
    LCD_WR_DATA(0x01);
  1220.  
    LCD_WR_DATA(0x00);
  1221.  
    LCD_WR_DATA(0x01);
  1222.  
    LCD_WR_DATA(0x00);
  1223.  
    LCD_WR_DATA(0x02);
  1224.  
    LCD_WR_DATA(0x00);
  1225.  
    LCD_WR_DATA(0x2A);
  1226.  
    LCD_WR_DATA(0x00);
  1227.  
    LCD_WR_DATA(0x3C);
  1228.  
    LCD_WR_DATA(0x00);
  1229.  
    LCD_WR_DATA(0x4B);
  1230.  
    LCD_WR_DATA(0x00);
  1231.  
    LCD_WR_DATA(0x5D);
  1232.  
    LCD_WR_DATA(0x00);
  1233.  
    LCD_WR_DATA(0x74);
  1234.  
    LCD_WR_DATA(0x00);
  1235.  
    LCD_WR_DATA(0x84);
  1236.  
    LCD_WR_DATA(0x00);
  1237.  
    LCD_WR_DATA(0x93);
  1238.  
    LCD_WR_DATA(0x00);
  1239.  
    LCD_WR_DATA(0xA2);
  1240.  
    LCD_WR_DATA(0x00);
  1241.  
    LCD_WR_DATA(0xB3);
  1242.  
    LCD_WR_DATA(0x00);
  1243.  
    LCD_WR_DATA(0xBE);
  1244.  
    LCD_WR_DATA(0x00);
  1245.  
    LCD_WR_DATA(0xC4);
  1246.  
    LCD_WR_DATA(0x00);
  1247.  
    LCD_WR_DATA(0xCD);
  1248.  
    LCD_WR_DATA(0x00);
  1249.  
    LCD_WR_DATA(0xD3);
  1250.  
    LCD_WR_DATA(0x00);
  1251.  
    LCD_WR_DATA(0xDD);
  1252.  
    LCD_WR_DATA(0x00);
  1253.  
    LCD_WR_DATA(0xF3);
  1254.  
    LCD_WR_DATA(0x00);
  1255.  
    LCD_WR_REG(0xE5);
  1256.  
    LCD_WR_DATA(0x00);
  1257.  
    LCD_WR_DATA(0x00);
  1258.  
    LCD_WR_DATA(0x00);
  1259.  
    LCD_WR_DATA(0x00);
  1260.  
    LCD_WR_DATA(0x02);
  1261.  
    LCD_WR_DATA(0x00);
  1262.  
    LCD_WR_DATA(0x29);
  1263.  
    LCD_WR_DATA(0x00);
  1264.  
    LCD_WR_DATA(0x3C);
  1265.  
    LCD_WR_DATA(0x00);
  1266.  
    LCD_WR_DATA(0x4B);
  1267.  
    LCD_WR_DATA(0x00);
  1268.  
    LCD_WR_DATA(0x5D);
  1269.  
    LCD_WR_DATA(0x00);
  1270.  
    LCD_WR_DATA(0x74);
  1271.  
    LCD_WR_DATA(0x00);
  1272.  
    LCD_WR_DATA(0x84);
  1273.  
    LCD_WR_DATA(0x00);
  1274.  
    LCD_WR_DATA(0x93);
  1275.  
    LCD_WR_DATA(0x00);
  1276.  
    LCD_WR_DATA(0xA2);
  1277.  
    LCD_WR_DATA(0x00);
  1278.  
    LCD_WR_DATA(0xB3);
  1279.  
    LCD_WR_DATA(0x00);
  1280.  
    LCD_WR_DATA(0xBE);
  1281.  
    LCD_WR_DATA(0x00);
  1282.  
    LCD_WR_DATA(0xC4);
  1283.  
    LCD_WR_DATA(0x00);
  1284.  
    LCD_WR_DATA(0xCD);
  1285.  
    LCD_WR_DATA(0x00);
  1286.  
    LCD_WR_DATA(0xD3);
  1287.  
    LCD_WR_DATA(0x00);
  1288.  
    LCD_WR_DATA(0xDC);
  1289.  
    LCD_WR_DATA(0x00);
  1290.  
    LCD_WR_DATA(0xF3);
  1291.  
    LCD_WR_DATA(0x00);
  1292.  
     
  1293.  
    LCD_WR_REG(0xE6);
  1294.  
    LCD_WR_DATA(0x11);
  1295.  
    LCD_WR_DATA(0x00);
  1296.  
    LCD_WR_DATA(0x34);
  1297.  
    LCD_WR_DATA(0x00);
  1298.  
    LCD_WR_DATA(0x56);
  1299.  
    LCD_WR_DATA(0x00);
  1300.  
    LCD_WR_DATA(0x76);
  1301.  
    LCD_WR_DATA(0x00);
  1302.  
    LCD_WR_DATA(0x77);
  1303.  
    LCD_WR_DATA(0x00);
  1304.  
    LCD_WR_DATA(0x66);
  1305.  
    LCD_WR_DATA(0x00);
  1306.  
    LCD_WR_DATA(0x88);
  1307.  
    LCD_WR_DATA(0x00);
  1308.  
    LCD_WR_DATA(0x99);
  1309.  
    LCD_WR_DATA(0x00);
  1310.  
    LCD_WR_DATA(0xBB);
  1311.  
    LCD_WR_DATA(0x00);
  1312.  
    LCD_WR_DATA(0x99);
  1313.  
    LCD_WR_DATA(0x00);
  1314.  
    LCD_WR_DATA(0x66);
  1315.  
    LCD_WR_DATA(0x00);
  1316.  
    LCD_WR_DATA(0x55);
  1317.  
    LCD_WR_DATA(0x00);
  1318.  
    LCD_WR_DATA(0x55);
  1319.  
    LCD_WR_DATA(0x00);
  1320.  
    LCD_WR_DATA(0x45);
  1321.  
    LCD_WR_DATA(0x00);
  1322.  
    LCD_WR_DATA(0x43);
  1323.  
    LCD_WR_DATA(0x00);
  1324.  
    LCD_WR_DATA(0x44);
  1325.  
    LCD_WR_DATA(0x00);
  1326.  
     
  1327.  
    LCD_WR_REG(0xE7);
  1328.  
    LCD_WR_DATA(0x32);
  1329.  
    LCD_WR_DATA(0x00);
  1330.  
    LCD_WR_DATA(0x55);
  1331.  
    LCD_WR_DATA(0x00);
  1332.  
    LCD_WR_DATA(0x76);
  1333.  
    LCD_WR_DATA(0x00);
  1334.  
    LCD_WR_DATA(0x66);
  1335.  
    LCD_WR_DATA(0x00);
  1336.  
    LCD_WR_DATA(0x67);
  1337.  
    LCD_WR_DATA(0x00);
  1338.  
    LCD_WR_DATA(0x67);
  1339.  
    LCD_WR_DATA(0x00);
  1340.  
    LCD_WR_DATA(0x87);
  1341.  
    LCD_WR_DATA(0x00);
  1342.  
    LCD_WR_DATA(0x99);
  1343.  
    LCD_WR_DATA(0x00);
  1344.  
    LCD_WR_DATA(0xBB);
  1345.  
    LCD_WR_DATA(0x00);
  1346.  
    LCD_WR_DATA(0x99);
  1347.  
    LCD_WR_DATA(0x00);
  1348.  
    LCD_WR_DATA(0x77);
  1349.  
    LCD_WR_DATA(0x00);
  1350.  
    LCD_WR_DATA(0x44);
  1351.  
    LCD_WR_DATA(0x00);
  1352.  
    LCD_WR_DATA(0x56);
  1353.  
    LCD_WR_DATA(0x00);
  1354.  
    LCD_WR_DATA(0x23);
  1355.  
    LCD_WR_DATA(0x00);
  1356.  
    LCD_WR_DATA(0x33);
  1357.  
    LCD_WR_DATA(0x00);
  1358.  
    LCD_WR_DATA(0x45);
  1359.  
    LCD_WR_DATA(0x00);
  1360.  
     
  1361.  
    LCD_WR_REG(0xE8);
  1362.  
    LCD_WR_DATA(0x00);
  1363.  
    LCD_WR_DATA(0x00);
  1364.  
    LCD_WR_DATA(0x99);
  1365.  
    LCD_WR_DATA(0x00);
  1366.  
    LCD_WR_DATA(0x87);
  1367.  
    LCD_WR_DATA(0x00);
  1368.  
    LCD_WR_DATA(0x88);
  1369.  
    LCD_WR_DATA(0x00);
  1370.  
    LCD_WR_DATA(0x77);
  1371.  
    LCD_WR_DATA(0x00);
  1372.  
    LCD_WR_DATA(0x66);
  1373.  
    LCD_WR_DATA(0x00);
  1374.  
    LCD_WR_DATA(0x88);
  1375.  
    LCD_WR_DATA(0x00);
  1376.  
    LCD_WR_DATA(0xAA);
  1377.  
    LCD_WR_DATA(0x00);
  1378.  
    LCD_WR_DATA(0xBB);
  1379.  
    LCD_WR_DATA(0x00);
  1380.  
    LCD_WR_DATA(0x99);
  1381.  
    LCD_WR_DATA(0x00);
  1382.  
    LCD_WR_DATA(0x66);
  1383.  
    LCD_WR_DATA(0x00);
  1384.  
    LCD_WR_DATA(0x55);
  1385.  
    LCD_WR_DATA(0x00);
  1386.  
    LCD_WR_DATA(0x55);
  1387.  
    LCD_WR_DATA(0x00);
  1388.  
    LCD_WR_DATA(0x44);
  1389.  
    LCD_WR_DATA(0x00);
  1390.  
    LCD_WR_DATA(0x44);
  1391.  
    LCD_WR_DATA(0x00);
  1392.  
    LCD_WR_DATA(0x55);
  1393.  
    LCD_WR_DATA(0x00);
  1394.  
     
  1395.  
    LCD_WR_REG(0xE9);
  1396.  
    LCD_WR_DATA(0xAA);
  1397.  
    LCD_WR_DATA(0x00);
  1398.  
    LCD_WR_DATA(0x00);
  1399.  
    LCD_WR_DATA(0x00);
  1400.  
     
  1401.  
    LCD_WR_REG(0x00);
  1402.  
    LCD_WR_DATA(0xAA);
  1403.  
     
  1404.  
    LCD_WR_REG(0xCF);
  1405.  
    LCD_WR_DATA(0x00);
  1406.  
    LCD_WR_DATA(0x00);
  1407.  
    LCD_WR_DATA(0x00);
  1408.  
    LCD_WR_DATA(0x00);
  1409.  
    LCD_WR_DATA(0x00);
  1410.  
    LCD_WR_DATA(0x00);
  1411.  
    LCD_WR_DATA(0x00);
  1412.  
    LCD_WR_DATA(0x00);
  1413.  
    LCD_WR_DATA(0x00);
  1414.  
    LCD_WR_DATA(0x00);
  1415.  
    LCD_WR_DATA(0x00);
  1416.  
    LCD_WR_DATA(0x00);
  1417.  
    LCD_WR_DATA(0x00);
  1418.  
    LCD_WR_DATA(0x00);
  1419.  
    LCD_WR_DATA(0x00);
  1420.  
    LCD_WR_DATA(0x00);
  1421.  
    LCD_WR_DATA(0x00);
  1422.  
     
  1423.  
    LCD_WR_REG(0xF0);
  1424.  
    LCD_WR_DATA(0x00);
  1425.  
    LCD_WR_DATA(0x50);
  1426.  
    LCD_WR_DATA(0x00);
  1427.  
    LCD_WR_DATA(0x00);
  1428.  
    LCD_WR_DATA(0x00);
  1429.  
     
  1430.  
    LCD_WR_REG(0xF3);
  1431.  
    LCD_WR_DATA(0x00);
  1432.  
     
  1433.  
    LCD_WR_REG(0xF9);
  1434.  
    LCD_WR_DATA(0x06);
  1435.  
    LCD_WR_DATA(0x10);
  1436.  
    LCD_WR_DATA(0x29);
  1437.  
    LCD_WR_DATA(0x00);
  1438.  
     
  1439.  
    LCD_WR_REG(0x3A);
  1440.  
    LCD_WR_DATA(0x55); //66
  1441.  
     
  1442.  
    LCD_WR_REG(0x11);
  1443.  
    delay_ms(100);
  1444.  
    LCD_WR_REG(0x29);
  1445.  
    LCD_WR_REG(0x35);
  1446.  
    LCD_WR_DATA(0x00);
  1447.  
     
  1448.  
    LCD_WR_REG(0x51);
  1449.  
    LCD_WR_DATA(0xFF);
  1450.  
    LCD_WR_REG(0x53);
  1451.  
    LCD_WR_DATA(0x2C);
  1452.  
    LCD_WR_REG(0x55);
  1453.  
    LCD_WR_DATA(0x82);
  1454.  
    LCD_WR_REG(0x2c);
  1455.  
    }else if(lcddev.id==0x5510)
  1456.  
    {
  1457.  
    LCD_WriteReg(0xF000,0x55);
  1458.  
    LCD_WriteReg(0xF001,0xAA);
  1459.  
    LCD_WriteReg(0xF002,0x52);
  1460.  
    LCD_WriteReg(0xF003,0x08);
  1461.  
    LCD_WriteReg(0xF004,0x01);
  1462.  
    //AVDD Set AVDD 5.2V
  1463.  
    LCD_WriteReg(0xB000,0x0D);
  1464.  
    LCD_WriteReg(0xB001,0x0D);
  1465.  
    LCD_WriteReg(0xB002,0x0D);
  1466.  
    //AVDD ratio
  1467.  
    LCD_WriteReg(0xB600,0x34);
  1468.  
    LCD_WriteReg(0xB601,0x34);
  1469.  
    LCD_WriteReg(0xB602,0x34);
  1470.  
    //AVEE -5.2V
  1471.  
    LCD_WriteReg(0xB100,0x0D);
  1472.  
    LCD_WriteReg(0xB101,0x0D);
  1473.  
    LCD_WriteReg(0xB102,0x0D);
  1474.  
    //AVEE ratio
  1475.  
    LCD_WriteReg(0xB700,0x34);
  1476.  
    LCD_WriteReg(0xB701,0x34);
  1477.  
    LCD_WriteReg(0xB702,0x34);
  1478.  
    //VCL -2.5V
  1479.  
    LCD_WriteReg(0xB200,0x00);
  1480.  
    LCD_WriteReg(0xB201,0x00);
  1481.  
    LCD_WriteReg(0xB202,0x00);
  1482.  
    //VCL ratio
  1483.  
    LCD_WriteReg(0xB800,0x24);
  1484.  
    LCD_WriteReg(0xB801,0x24);
  1485.  
    LCD_WriteReg(0xB802,0x24);
  1486.  
    //VGH 15V (Free pump)
  1487.  
    LCD_WriteReg(0xBF00,0x01);
  1488.  
    LCD_WriteReg(0xB300,0x0F);
  1489.  
    LCD_WriteReg(0xB301,0x0F);
  1490.  
    LCD_WriteReg(0xB302,0x0F);
  1491.  
    //VGH ratio
  1492.  
    LCD_WriteReg(0xB900,0x34);
  1493.  
    LCD_WriteReg(0xB901,0x34);
  1494.  
    LCD_WriteReg(0xB902,0x34);
  1495.  
    //VGL_REG -10V
  1496.  
    LCD_WriteReg(0xB500,0x08);
  1497.  
    LCD_WriteReg(0xB501,0x08);
  1498.  
    LCD_WriteReg(0xB502,0x08);
  1499.  
    LCD_WriteReg(0xC200,0x03);
  1500.  
    //VGLX ratio
  1501.  
    LCD_WriteReg(0xBA00,0x24);
  1502.  
    LCD_WriteReg(0xBA01,0x24);
  1503.  
    LCD_WriteReg(0xBA02,0x24);
  1504.  
    //VGMP/VGSP 4.5V/0V
  1505.  
    LCD_WriteReg(0xBC00,0x00);
  1506.  
    LCD_WriteReg(0xBC01,0x78);
  1507.  
    LCD_WriteReg(0xBC02,0x00);
  1508.  
    //VGMN/VGSN -4.5V/0V
  1509.  
    LCD_WriteReg(0xBD00,0x00);
  1510.  
    LCD_WriteReg(0xBD01,0x78);
  1511.  
    LCD_WriteReg(0xBD02,0x00);
  1512.  
    //VCOM
  1513.  
    LCD_WriteReg(0xBE00,0x00);
  1514.  
    LCD_WriteReg(0xBE01,0x64);
  1515.  
    //Gamma Setting
  1516.  
    LCD_WriteReg(0xD100,0x00);
  1517.  
    LCD_WriteReg(0xD101,0x33);
  1518.  
    LCD_WriteReg(0xD102,0x00);
  1519.  
    LCD_WriteReg(0xD103,0x34);
  1520.  
    LCD_WriteReg(0xD104,0x00);
  1521.  
    LCD_WriteReg(0xD105,0x3A);
  1522.  
    LCD_WriteReg(0xD106,0x00);
  1523.  
    LCD_WriteReg(0xD107,0x4A);
  1524.  
    LCD_WriteReg(0xD108,0x00);
  1525.  
    LCD_WriteReg(0xD109,0x5C);
  1526.  
    LCD_WriteReg(0xD10A,0x00);
  1527.  
    LCD_WriteReg(0xD10B,0x81);
  1528.  
    LCD_WriteReg(0xD10C,0x00);
  1529.  
    LCD_WriteReg(0xD10D,0xA6);
  1530.  
    LCD_WriteReg(0xD10E,0x00);
  1531.  
    LCD_WriteReg(0xD10F,0xE5);
  1532.  
    LCD_WriteReg(0xD110,0x01);
  1533.  
    LCD_WriteReg(0xD111,0x13);
  1534.  
    LCD_WriteReg(0xD112,0x01);
  1535.  
    LCD_WriteReg(0xD113,0x54);
  1536.  
    LCD_WriteReg(0xD114,0x01);
  1537.  
    LCD_WriteReg(0xD115,0x82);
  1538.  
    LCD_WriteReg(0xD116,0x01);
  1539.  
    LCD_WriteReg(0xD117,0xCA);
  1540.  
    LCD_WriteReg(0xD118,0x02);
  1541.  
    LCD_WriteReg(0xD119,0x00);
  1542.  
    LCD_WriteReg(0xD11A,0x02);
  1543.  
    LCD_WriteReg(0xD11B,0x01);
  1544.  
    LCD_WriteReg(0xD11C,0x02);
  1545.  
    LCD_WriteReg(0xD11D,0x34);
  1546.  
    LCD_WriteReg(0xD11E,0x02);
  1547.  
    LCD_WriteReg(0xD11F,0x67);
  1548.  
    LCD_WriteReg(0xD120,0x02);
  1549.  
    LCD_WriteReg(0xD121,0x84);
  1550.  
    LCD_WriteReg(0xD122,0x02);
  1551.  
    LCD_WriteReg(0xD123,0xA4);
  1552.  
    LCD_WriteReg(0xD124,0x02);
  1553.  
    LCD_WriteReg(0xD125,0xB7);
  1554.  
    LCD_WriteReg(0xD126,0x02);
  1555.  
    LCD_WriteReg(0xD127,0xCF);
  1556.  
    LCD_WriteReg(0xD128,0x02);
  1557.  
    LCD_WriteReg(0xD129,0xDE);
  1558.  
    LCD_WriteReg(0xD12A,0x02);
  1559.  
    LCD_WriteReg(0xD12B,0xF2);
  1560.  
    LCD_WriteReg(0xD12C,0x02);
  1561.  
    LCD_WriteReg(0xD12D,0xFE);
  1562.  
    LCD_WriteReg(0xD12E,0x03);
  1563.  
    LCD_WriteReg(0xD12F,0x10);
  1564.  
    LCD_WriteReg(0xD130,0x03);
  1565.  
    LCD_WriteReg(0xD131,0x33);
  1566.  
    LCD_WriteReg(0xD132,0x03);
  1567.  
    LCD_WriteReg(0xD133,0x6D);
  1568.  
    LCD_WriteReg(0xD200,0x00);
  1569.  
    LCD_WriteReg(0xD201,0x33);
  1570.  
    LCD_WriteReg(0xD202,0x00);
  1571.  
    LCD_WriteReg(0xD203,0x34);
  1572.  
    LCD_WriteReg(0xD204,0x00);
  1573.  
    LCD_WriteReg(0xD205,0x3A);
  1574.  
    LCD_WriteReg(0xD206,0x00);
  1575.  
    LCD_WriteReg(0xD207,0x4A);
  1576.  
    LCD_WriteReg(0xD208,0x00);
  1577.  
    LCD_WriteReg(0xD209,0x5C);
  1578.  
    LCD_WriteReg(0xD20A,0x00);
  1579.  
     
  1580.  
    LCD_WriteReg(0xD20B,0x81);
  1581.  
    LCD_WriteReg(0xD20C,0x00);
  1582.  
    LCD_WriteReg(0xD20D,0xA6);
  1583.  
    LCD_WriteReg(0xD20E,0x00);
  1584.  
    LCD_WriteReg(0xD20F,0xE5);
  1585.  
    LCD_WriteReg(0xD210,0x01);
  1586.  
    LCD_WriteReg(0xD211,0x13);
  1587.  
    LCD_WriteReg(0xD212,0x01);
  1588.  
    LCD_WriteReg(0xD213,0x54);
  1589.  
    LCD_WriteReg(0xD214,0x01);
  1590.  
    LCD_WriteReg(0xD215,0x82);
  1591.  
    LCD_WriteReg(0xD216,0x01);
  1592.  
    LCD_WriteReg(0xD217,0xCA);
  1593.  
    LCD_WriteReg(0xD218,0x02);
  1594.  
    LCD_WriteReg(0xD219,0x00);
  1595.  
    LCD_WriteReg(0xD21A,0x02);
  1596.  
    LCD_WriteReg(0xD21B,0x01);
  1597.  
    LCD_WriteReg(0xD21C,0x02);
  1598.  
    LCD_WriteReg(0xD21D,0x34);
  1599.  
    LCD_WriteReg(0xD21E,0x02);
  1600.  
    LCD_WriteReg(0xD21F,0x67);
  1601.  
    LCD_WriteReg(0xD220,0x02);
  1602.  
    LCD_WriteReg(0xD221,0x84);
  1603.  
    LCD_WriteReg(0xD222,0x02);
  1604.  
    LCD_WriteReg(0xD223,0xA4);
  1605.  
    LCD_WriteReg(0xD224,0x02);
  1606.  
    LCD_WriteReg(0xD225,0xB7);
  1607.  
    LCD_WriteReg(0xD226,0x02);
  1608.  
    LCD_WriteReg(0xD227,0xCF);
  1609.  
    LCD_WriteReg(0xD228,0x02);
  1610.  
    LCD_WriteReg(0xD229,0xDE);
  1611.  
    LCD_WriteReg(0xD22A,0x02);
  1612.  
    LCD_WriteReg(0xD22B,0xF2);
  1613.  
    LCD_WriteReg(0xD22C,0x02);
  1614.  
    LCD_WriteReg(0xD22D,0xFE);
  1615.  
    LCD_WriteReg(0xD22E,0x03);
  1616.  
    LCD_WriteReg(0xD22F,0x10);
  1617.  
    LCD_WriteReg(0xD230,0x03);
  1618.  
    LCD_WriteReg(0xD231,0x33);
  1619.  
    LCD_WriteReg(0xD232,0x03);
  1620.  
    LCD_WriteReg(0xD233,0x6D);
  1621.  
    LCD_WriteReg(0xD300,0x00);
  1622.  
    LCD_WriteReg(0xD301,0x33);
  1623.  
    LCD_WriteReg(0xD302,0x00);
  1624.  
    LCD_WriteReg(0xD303,0x34);
  1625.  
    LCD_WriteReg(0xD304,0x00);
  1626.  
    LCD_WriteReg(0xD305,0x3A);
  1627.  
    LCD_WriteReg(0xD306,0x00);
  1628.  
    LCD_WriteReg(0xD307,0x4A);
  1629.  
    LCD_WriteReg(0xD308,0x00);
  1630.  
    LCD_WriteReg(0xD309,0x5C);
  1631.  
    LCD_WriteReg(0xD30A,0x00);
  1632.  
     
  1633.  
    LCD_WriteReg(0xD30B,0x81);
  1634.  
    LCD_WriteReg(0xD30C,0x00);
  1635.  
    LCD_WriteReg(0xD30D,0xA6);
  1636.  
    LCD_WriteReg(0xD30E,0x00);
  1637.  
    LCD_WriteReg(0xD30F,0xE5);
  1638.  
    LCD_WriteReg(0xD310,0x01);
  1639.  
    LCD_WriteReg(0xD311,0x13);
  1640.  
    LCD_WriteReg(0xD312,0x01);
  1641.  
    LCD_WriteReg(0xD313,0x54);
  1642.  
    LCD_WriteReg(0xD314,0x01);
  1643.  
    LCD_WriteReg(0xD315,0x82);
  1644.  
    LCD_WriteReg(0xD316,0x01);
  1645.  
    LCD_WriteReg(0xD317,0xCA);
  1646.  
    LCD_WriteReg(0xD318,0x02);
  1647.  
    LCD_WriteReg(0xD319,0x00);
  1648.  
    LCD_WriteReg(0xD31A,0x02);
  1649.  
    LCD_WriteReg(0xD31B,0x01);
  1650.  
    LCD_WriteReg(0xD31C,0x02);
  1651.  
    LCD_WriteReg(0xD31D,0x34);
  1652.  
    LCD_WriteReg(0xD31E,0x02);
  1653.  
    LCD_WriteReg(0xD31F,0x67);
  1654.  
    LCD_WriteReg(0xD320,0x02);
  1655.  
    LCD_WriteReg(0xD321,0x84);
  1656.  
    LCD_WriteReg(0xD322,0x02);
  1657.  
    LCD_WriteReg(0xD323,0xA4);
  1658.  
    LCD_WriteReg(0xD324,0x02);
  1659.  
    LCD_WriteReg(0xD325,0xB7);
  1660.  
    LCD_WriteReg(0xD326,0x02);
  1661.  
    LCD_WriteReg(0xD327,0xCF);
  1662.  
    LCD_WriteReg(0xD328,0x02);
  1663.  
    LCD_WriteReg(0xD329,0xDE);
  1664.  
    LCD_WriteReg(0xD32A,0x02);
  1665.  
    LCD_WriteReg(0xD32B,0xF2);
  1666.  
    LCD_WriteReg(0xD32C,0x02);
  1667.  
    LCD_WriteReg(0xD32D,0xFE);
  1668.  
    LCD_WriteReg(0xD32E,0x03);
  1669.  
    LCD_WriteReg(0xD32F,0x10);
  1670.  
    LCD_WriteReg(0xD330,0x03);
  1671.  
    LCD_WriteReg(0xD331,0x33);
  1672.  
    LCD_WriteReg(0xD332,0x03);
  1673.  
    LCD_WriteReg(0xD333,0x6D);
  1674.  
    LCD_WriteReg(0xD400,0x00);
  1675.  
    LCD_WriteReg(0xD401,0x33);
  1676.  
    LCD_WriteReg(0xD402,0x00);
  1677.  
    LCD_WriteReg(0xD403,0x34);
  1678.  
    LCD_WriteReg(0xD404,0x00);
  1679.  
    LCD_WriteReg(0xD405,0x3A);
  1680.  
    LCD_WriteReg(0xD406,0x00);
  1681.  
    LCD_WriteReg(0xD407,0x4A);
  1682.  
    LCD_WriteReg(0xD408,0x00);
  1683.  
    LCD_WriteReg(0xD409,0x5C);
  1684.  
    LCD_WriteReg(0xD40A,0x00);
  1685.  
    LCD_WriteReg(0xD40B,0x81);
  1686.  
     
  1687.  
    LCD_WriteReg(0xD40C,0x00);
  1688.  
    LCD_WriteReg(0xD40D,0xA6);
  1689.  
    LCD_WriteReg(0xD40E,0x00);
  1690.  
    LCD_WriteReg(0xD40F,0xE5);
  1691.  
    LCD_WriteReg(0xD410,0x01);
  1692.  
    LCD_WriteReg(0xD411,0x13);
  1693.  
    LCD_WriteReg(0xD412,0x01);
  1694.  
    LCD_WriteReg(0xD413,0x54);
  1695.  
    LCD_WriteReg(0xD414,0x01);
  1696.  
    LCD_WriteReg(0xD415,0x82);
  1697.  
    LCD_WriteReg(0xD416,0x01);
  1698.  
    LCD_WriteReg(0xD417,0xCA);
  1699.  
    LCD_WriteReg(0xD418,0x02);
  1700.  
    LCD_WriteReg(0xD419,0x00);
  1701.  
    LCD_WriteReg(0xD41A,0x02);
  1702.  
    LCD_WriteReg(0xD41B,0x01);
  1703.  
    LCD_WriteReg(0xD41C,0x02);
  1704.  
    LCD_WriteReg(0xD41D,0x34);
  1705.  
    LCD_WriteReg(0xD41E,0x02);
  1706.  
    LCD_WriteReg(0xD41F,0x67);
  1707.  
    LCD_WriteReg(0xD420,0x02);
  1708.  
    LCD_WriteReg(0xD421,0x84);
  1709.  
    LCD_WriteReg(0xD422,0x02);
  1710.  
    LCD_WriteReg(0xD423,0xA4);
  1711.  
    LCD_WriteReg(0xD424,0x02);
  1712.  
    LCD_WriteReg(0xD425,0xB7);
  1713.  
    LCD_WriteReg(0xD426,0x02);
  1714.  
    LCD_WriteReg(0xD427,0xCF);
  1715.  
    LCD_WriteReg(0xD428,0x02);
  1716.  
    LCD_WriteReg(0xD429,0xDE);
  1717.  
    LCD_WriteReg(0xD42A,0x02);
  1718.  
    LCD_WriteReg(0xD42B,0xF2);
  1719.  
    LCD_WriteReg(0xD42C,0x02);
  1720.  
    LCD_WriteReg(0xD42D,0xFE);
  1721.  
    LCD_WriteReg(0xD42E,0x03);
  1722.  
    LCD_WriteReg(0xD42F,0x10);
  1723.  
    LCD_WriteReg(0xD430,0x03);
  1724.  
    LCD_WriteReg(0xD431,0x33);
  1725.  
    LCD_WriteReg(0xD432,0x03);
  1726.  
    LCD_WriteReg(0xD433,0x6D);
  1727.  
    LCD_WriteReg(0xD500,0x00);
  1728.  
    LCD_WriteReg(0xD501,0x33);
  1729.  
    LCD_WriteReg(0xD502,0x00);
  1730.  
    LCD_WriteReg(0xD503,0x34);
  1731.  
    LCD_WriteReg(0xD504,0x00);
  1732.  
    LCD_WriteReg(0xD505,0x3A);
  1733.  
    LCD_WriteReg(0xD506,0x00);
  1734.  
    LCD_WriteReg(0xD507,0x4A);
  1735.  
    LCD_WriteReg(0xD508,0x00);
  1736.  
    LCD_WriteReg(0xD509,0x5C);
  1737.  
    LCD_WriteReg(0xD50A,0x00);
  1738.  
    LCD_WriteReg(0xD50B,0x81);
  1739.  
     
  1740.  
    LCD_WriteReg(0xD50C,0x00);
  1741.  
    LCD_WriteReg(0xD50D,0xA6);
  1742.  
    LCD_WriteReg(0xD50E,0x00);
  1743.  
    LCD_WriteReg(0xD50F,0xE5);
  1744.  
    LCD_WriteReg(0xD510,0x01);
  1745.  
    LCD_WriteReg(0xD511,0x13);
  1746.  
    LCD_WriteReg(0xD512,0x01);
  1747.  
    LCD_WriteReg(0xD513,0x54);
  1748.  
    LCD_WriteReg(0xD514,0x01);
  1749.  
    LCD_WriteReg(0xD515,0x82);
  1750.  
    LCD_WriteReg(0xD516,0x01);
  1751.  
    LCD_WriteReg(0xD517,0xCA);
  1752.  
    LCD_WriteReg(0xD518,0x02);
  1753.  
    LCD_WriteReg(0xD519,0x00);
  1754.  
    LCD_WriteReg(0xD51A,0x02);
  1755.  
    LCD_WriteReg(0xD51B,0x01);
  1756.  
    LCD_WriteReg(0xD51C,0x02);
  1757.  
    LCD_WriteReg(0xD51D,0x34);
  1758.  
    LCD_WriteReg(0xD51E,0x02);
  1759.  
    LCD_WriteReg(0xD51F,0x67);
  1760.  
    LCD_WriteReg(0xD520,0x02);
  1761.  
    LCD_WriteReg(0xD521,0x84);
  1762.  
    LCD_WriteReg(0xD522,0x02);
  1763.  
    LCD_WriteReg(0xD523,0xA4);
  1764.  
    LCD_WriteReg(0xD524,0x02);
  1765.  
    LCD_WriteReg(0xD525,0xB7);
  1766.  
    LCD_WriteReg(0xD526,0x02);
  1767.  
    LCD_WriteReg(0xD527,0xCF);
  1768.  
    LCD_WriteReg(0xD528,0x02);
  1769.  
    LCD_WriteReg(0xD529,0xDE);
  1770.  
    LCD_WriteReg(0xD52A,0x02);
  1771.  
    LCD_WriteReg(0xD52B,0xF2);
  1772.  
    LCD_WriteReg(0xD52C,0x02);
  1773.  
    LCD_WriteReg(0xD52D,0xFE);
  1774.  
    LCD_WriteReg(0xD52E,0x03);
  1775.  
    LCD_WriteReg(0xD52F,0x10);
  1776.  
    LCD_WriteReg(0xD530,0x03);
  1777.  
    LCD_WriteReg(0xD531,0x33);
  1778.  
    LCD_WriteReg(0xD532,0x03);
  1779.  
    LCD_WriteReg(0xD533,0x6D);
  1780.  
    LCD_WriteReg(0xD600,0x00);
  1781.  
    LCD_WriteReg(0xD601,0x33);
  1782.  
    LCD_WriteReg(0xD602,0x00);
  1783.  
    LCD_WriteReg(0xD603,0x34);
  1784.  
    LCD_WriteReg(0xD604,0x00);
  1785.  
    LCD_WriteReg(0xD605,0x3A);
  1786.  
    LCD_WriteReg(0xD606,0x00);
  1787.  
    LCD_WriteReg(0xD607,0x4A);
  1788.  
    LCD_WriteReg(0xD608,0x00);
  1789.  
    LCD_WriteReg(0xD609,0x5C);
  1790.  
    LCD_WriteReg(0xD60A,0x00);
  1791.  
    LCD_WriteReg(0xD60B,0x81);
  1792.  
     
  1793.  
    LCD_WriteReg(0xD60C,0x00);
  1794.  
    LCD_WriteReg(0xD60D,0xA6);
  1795.  
    LCD_WriteReg(0xD60E,0x00);
  1796.  
    LCD_WriteReg(0xD60F,0xE5);
  1797.  
    LCD_WriteReg(0xD610,0x01);
  1798.  
    LCD_WriteReg(0xD611,0x13);
  1799.  
    LCD_WriteReg(0xD612,0x01);
  1800.  
    LCD_WriteReg(0xD613,0x54);
  1801.  
    LCD_WriteReg(0xD614,0x01);
  1802.  
    LCD_WriteReg(0xD615,0x82);
  1803.  
    LCD_WriteReg(0xD616,0x01);
  1804.  
    LCD_WriteReg(0xD617,0xCA);
  1805.  
    LCD_WriteReg(0xD618,0x02);
  1806.  
    LCD_WriteReg(0xD619,0x00);
  1807.  
    LCD_WriteReg(0xD61A,0x02);
  1808.  
    LCD_WriteReg(0xD61B,0x01);
  1809.  
    LCD_WriteReg(0xD61C,0x02);
  1810.  
    LCD_WriteReg(0xD61D,0x34);
  1811.  
    LCD_WriteReg(0xD61E,0x02);
  1812.  
    LCD_WriteReg(0xD61F,0x67);
  1813.  
    LCD_WriteReg(0xD620,0x02);
  1814.  
    LCD_WriteReg(0xD621,0x84);
  1815.  
    LCD_WriteReg(0xD622,0x02);
  1816.  
    LCD_WriteReg(0xD623,0xA4);
  1817.  
    LCD_WriteReg(0xD624,0x02);
  1818.  
    LCD_WriteReg(0xD625,0xB7);
  1819.  
    LCD_WriteReg(0xD626,0x02);
  1820.  
    LCD_WriteReg(0xD627,0xCF);
  1821.  
    LCD_WriteReg(0xD628,0x02);
  1822.  
    LCD_WriteReg(0xD629,0xDE);
  1823.  
    LCD_WriteReg(0xD62A,0x02);
  1824.  
    LCD_WriteReg(0xD62B,0xF2);
  1825.  
    LCD_WriteReg(0xD62C,0x02);
  1826.  
    LCD_WriteReg(0xD62D,0xFE);
  1827.  
    LCD_WriteReg(0xD62E,0x03);
  1828.  
    LCD_WriteReg(0xD62F,0x10);
  1829.  
    LCD_WriteReg(0xD630,0x03);
  1830.  
    LCD_WriteReg(0xD631,0x33);
  1831.  
    LCD_WriteReg(0xD632,0x03);
  1832.  
    LCD_WriteReg(0xD633,0x6D);
  1833.  
    //LV2 Page 0 enable
  1834.  
    LCD_WriteReg(0xF000,0x55);
  1835.  
    LCD_WriteReg(0xF001,0xAA);
  1836.  
    LCD_WriteReg(0xF002,0x52);
  1837.  
    LCD_WriteReg(0xF003,0x08);
  1838.  
    LCD_WriteReg(0xF004,0x00);
  1839.  
    //Display control
  1840.  
    LCD_WriteReg(0xB100, 0xCC);
  1841.  
    LCD_WriteReg(0xB101, 0x00);
  1842.  
    //Source hold time
  1843.  
    LCD_WriteReg(0xB600,0x05);
  1844.  
    //Gate EQ control
  1845.  
    LCD_WriteReg(0xB700,0x70);
  1846.  
    LCD_WriteReg(0xB701,0x70);
  1847.  
    //Source EQ control (Mode 2)
  1848.  
    LCD_WriteReg(0xB800,0x01);
  1849.  
    LCD_WriteReg(0xB801,0x03);
  1850.  
    LCD_WriteReg(0xB802,0x03);
  1851.  
    LCD_WriteReg(0xB803,0x03);
  1852.  
    //Inversion mode (2-dot)
  1853.  
    LCD_WriteReg(0xBC00,0x02);
  1854.  
    LCD_WriteReg(0xBC01,0x00);
  1855.  
    LCD_WriteReg(0xBC02,0x00);
  1856.  
    //Timing control 4H w/ 4-delay
  1857.  
    LCD_WriteReg(0xC900,0xD0);
  1858.  
    LCD_WriteReg(0xC901,0x02);
  1859.  
    LCD_WriteReg(0xC902,0x50);
  1860.  
    LCD_WriteReg(0xC903,0x50);
  1861.  
    LCD_WriteReg(0xC904,0x50);
  1862.  
    LCD_WriteReg(0x3500,0x00);
  1863.  
    LCD_WriteReg(0x3A00,0x55); //16-bit/pixel
  1864.  
    LCD_WR_REG(0x1100);
  1865.  
    delay_us(120);
  1866.  
    LCD_WR_REG(0x2900);
  1867.  
    }else if(lcddev.id==0X1963)
  1868.  
    {
  1869.  
    LCD_WR_REG(0xE2); //Set PLL with OSC = 10MHz (hardware), Multiplier N = 35, 250MHz < VCO < 800MHz = OSC*(N 1), VCO = 300MHz
  1870.  
    LCD_WR_DATA(0x1D); //参数1
  1871.  
    LCD_WR_DATA(0x02); //参数2 Divider M = 2, PLL = 300/(M 1) = 100MHz
  1872.  
    LCD_WR_DATA(0x04); //参数3 Validate M and N values
  1873.  
    delay_us(100);
  1874.  
    LCD_WR_REG(0xE0); // Start PLL command
  1875.  
    LCD_WR_DATA(0x01); // enable PLL
  1876.  
    delay_ms(10);
  1877.  
    LCD_WR_REG(0xE0); // Start PLL command again
  1878.  
    LCD_WR_DATA(0x03); // now, use PLL output as system clock
  1879.  
    delay_ms(12);
  1880.  
    LCD_WR_REG(0x01); //软复位
  1881.  
    delay_ms(10);
  1882.  
     
  1883.  
    LCD_WR_REG(0xE6); //设置像素频率,33Mhz
  1884.  
    LCD_WR_DATA(0x2F);
  1885.  
    LCD_WR_DATA(0xFF);
  1886.  
    LCD_WR_DATA(0xFF);
  1887.  
     
  1888.  
    LCD_WR_REG(0xB0); //设置LCD模式
  1889.  
    LCD_WR_DATA(0x20); //24位模式
  1890.  
    LCD_WR_DATA(0x00); //TFT 模式
  1891.  
     
  1892.  
    LCD_WR_DATA((SSD_HOR_RESOLUTION-1)>>8);//设置LCD水平像素
  1893.  
    LCD_WR_DATA(SSD_HOR_RESOLUTION-1);
  1894.  
    LCD_WR_DATA((SSD_VER_RESOLUTION-1)>>8);//设置LCD垂直像素
  1895.  
    LCD_WR_DATA(SSD_VER_RESOLUTION-1);
  1896.  
    LCD_WR_DATA(0x00); //RGB序列
  1897.  
     
  1898.  
    LCD_WR_REG(0xB4); //Set horizontal period
  1899.  
    LCD_WR_DATA((SSD_HT-1)>>8);
  1900.  
    LCD_WR_DATA(SSD_HT-1);
  1901.  
    LCD_WR_DATA(SSD_HPS>>8);
  1902.  
    LCD_WR_DATA(SSD_HPS);
  1903.  
    LCD_WR_DATA(SSD_HOR_PULSE_WIDTH-1);
  1904.  
    LCD_WR_DATA(0x00);
  1905.  
    LCD_WR_DATA(0x00);
  1906.  
    LCD_WR_DATA(0x00);
  1907.  
    LCD_WR_REG(0xB6); //Set vertical period
  1908.  
    LCD_WR_DATA((SSD_VT-1)>>8);
  1909.  
    LCD_WR_DATA(SSD_VT-1);
  1910.  
    LCD_WR_DATA(SSD_VPS>>8);
  1911.  
    LCD_WR_DATA(SSD_VPS);
  1912.  
    LCD_WR_DATA(SSD_VER_FRONT_PORCH-1);
  1913.  
    LCD_WR_DATA(0x00);
  1914.  
    LCD_WR_DATA(0x00);
  1915.  
     
  1916.  
    LCD_WR_REG(0xF0); //设置SSD1963与CPU接口为16bit
  1917.  
    LCD_WR_DATA(0x03); //16-bit(565 format) data for 16bpp
  1918.  
     
  1919.  
    LCD_WR_REG(0x29); //开启显示
  1920.  
    //设置PWM输出 背光通过占空比可调
  1921.  
    LCD_WR_REG(0xD0); //设置自动白平衡DBC
  1922.  
    LCD_WR_DATA(0x00); //disable
  1923.  
     
  1924.  
    LCD_WR_REG(0xBE); //配置PWM输出
  1925.  
    LCD_WR_DATA(0x05); //1设置PWM频率
  1926.  
    LCD_WR_DATA(0xFE); //2设置PWM占空比
  1927.  
    LCD_WR_DATA(0x01); //3设置C
  1928.  
    LCD_WR_DATA(0x00); //4设置D
  1929.  
    LCD_WR_DATA(0x00); //5设置E
  1930.  
    LCD_WR_DATA(0x00); //6设置F
  1931.  
     
  1932.  
    LCD_WR_REG(0xB8); //设置GPIO配置
  1933.  
    LCD_WR_DATA(0x03); //2个IO口设置成输出
  1934.  
    LCD_WR_DATA(0x01); //GPIO使用正常的IO功能
  1935.  
    LCD_WR_REG(0xBA);
  1936.  
    LCD_WR_DATA(0X01); //GPIO[1:0]=01,控制LCD方向
  1937.  
     
  1938.  
    LCD_SSD_BackLightSet(100);//背光设置为最亮
  1939.  
    }
  1940.  
    //初始化完成以后,提速
  1941.  
    if(lcddev.id==0X9341||lcddev.id==0X7789||lcddev.id==0X5310||lcddev.id==0X5510||lcddev.id==0X1963||lcddev.id==0X7789)//如果是这几个IC,则设置WR时序为最快
  1942.  
    {
  1943.  
    //重新配置写时序控制寄存器的时序
  1944.  
    FMC_Bank1E->BWTR[0]&=~(0XF<<0); //地址建立时间(ADDSET)清零
  1945.  
    FMC_Bank1E->BWTR[0]&=~(0XF<<8); //数据保存时间清零
  1946.  
    FMC_Bank1E->BWTR[0]|=5<<0; //地址建立时间(ADDSET)为5个HCLK =21ns
  1947.  
    FMC_Bank1E->BWTR[0]|=5<<8; //数据保存时间(DATAST)为4.6ns*4个HCLK=21ns
  1948.  
    }
  1949.  
    LCD_Display_Dir(0); //默认为竖屏
  1950.  
    LCD_LED(1); //点亮背光
  1951.  
    LCD_Clear(WHITE);
  1952.  
    }
  1953.  
    //清屏函数
  1954.  
    //color:要清屏的填充色
  1955.  
    void LCD_Clear(u32 color)
  1956.  
    {
  1957.  
    u32 index=0;
  1958.  
    u32 totalpoint=lcddev.width;
  1959.  
    totalpoint*=lcddev.height; //得到总点数
  1960.  
    LCD_SetCursor(0x00,0x0000); //设置光标位置
  1961.  
    LCD_WriteRAM_Prepare(); //开始写入GRAM
  1962.  
    for(index=0;index<totalpoint;index )
  1963.  
    {
  1964.  
    LCD->LCD_RAM=color;
  1965.  
    }
  1966.  
    }
  1967.  
    //在指定区域内填充单个颜色
  1968.  
    //(sx,sy),(ex,ey):填充矩形对角坐标,区域大小为:(ex-sx 1)*(ey-sy 1)
  1969.  
    //color:要填充的颜色
  1970.  
    void LCD_Fill(u16 sx,u16 sy,u16 ex,u16 ey,u32 color)
  1971.  
    {
  1972.  
    u16 i,j;
  1973.  
    u16 xlen=0;
  1974.  
    xlen=ex-sx 1;
  1975.  
    for(i=sy;i<=ey;i )
  1976.  
    {
  1977.  
    LCD_SetCursor(sx,i); //设置光标位置
  1978.  
    LCD_WriteRAM_Prepare(); //开始写入GRAM
  1979.  
    for(j=0;j<xlen;j )LCD->LCD_RAM=color; //显示颜色
  1980.  
    }
  1981.  
    }
  1982.  
    //在指定区域内填充指定颜色块
  1983.  
    //(sx,sy),(ex,ey):填充矩形对角坐标,区域大小为:(ex-sx 1)*(ey-sy 1)
  1984.  
    //color:要填充的颜色
  1985.  
    void LCD_Color_Fill(u16 sx,u16 sy,u16 ex,u16 ey,u16 *color)
  1986.  
    {
  1987.  
    u16 height,width;
  1988.  
    u16 i,j;
  1989.  
    width=ex-sx 1; //得到填充的宽度
  1990.  
    height=ey-sy 1; //高度
  1991.  
    for(i=0;i<height;i )
  1992.  
    {
  1993.  
    LCD_SetCursor(sx,sy i); //设置光标位置
  1994.  
    LCD_WriteRAM_Prepare(); //开始写入GRAM
  1995.  
    for(j=0;j<width;j )LCD->LCD_RAM=color[i*width j];//写入数据
  1996.  
    }
  1997.  
    }
  1998.  
    //画线
  1999.  
    //x1,y1:起点坐标
  2000.  
    //x2,y2:终点坐标
  2001.  
    void LCD_DrawLine(u16 x1, u16 y1, u16 x2, u16 y2)
  2002.  
    {
  2003.  
    u16 t;
  2004.  
    int xerr=0,yerr=0,delta_x,delta_y,distance;
  2005.  
    int incx,incy,uRow,uCol;
  2006.  
    delta_x=x2-x1; //计算坐标增量
  2007.  
    delta_y=y2-y1;
  2008.  
    uRow=x1;
  2009.  
    uCol=y1;
  2010.  
    if(delta_x>0)incx=1; //设置单步方向
  2011.  
    else if(delta_x==0)incx=0;//垂直线
  2012.  
    else {incx=-1;delta_x=-delta_x;}
  2013.  
    if(delta_y>0)incy=1;
  2014.  
    else if(delta_y==0)incy=0;//水平线
  2015.  
    else{incy=-1;delta_y=-delta_y;}
  2016.  
    if( delta_x>delta_y)distance=delta_x; //选取基本增量坐标轴
  2017.  
    else distance=delta_y;
  2018.  
    for(t=0;t<=distance 1;t )//画线输出
  2019.  
    {
  2020.  
    LCD_DrawPoint(uRow,uCol);//画点
  2021.  
    xerr =delta_x ;
  2022.  
    yerr =delta_y ;
  2023.  
    if(xerr>distance)
  2024.  
    {
  2025.  
    xerr-=distance;
  2026.  
    uRow =incx;
  2027.  
    }
  2028.  
    if(yerr>distance)
  2029.  
    {
  2030.  
    yerr-=distance;
  2031.  
    uCol =incy;
  2032.  
    }
  2033.  
    }
  2034.  
    }
  2035.  
    //画矩形
  2036.  
    //(x1,y1),(x2,y2):矩形的对角坐标
  2037.  
    void LCD_DrawRectangle(u16 x1, u16 y1, u16 x2, u16 y2)
  2038.  
    {
  2039.  
    LCD_DrawLine(x1,y1,x2,y1);
  2040.  
    LCD_DrawLine(x1,y1,x1,y2);
  2041.  
    LCD_DrawLine(x1,y2,x2,y2);
  2042.  
    LCD_DrawLine(x2,y1,x2,y2);
  2043.  
    }
  2044.  
    //在指定位置画一个指定大小的圆
  2045.  
    //(x,y):中心点
  2046.  
    //r :半径
  2047.  
    void LCD_Draw_Circle(u16 x0,u16 y0,u8 r)
  2048.  
    {
  2049.  
    int a,b;
  2050.  
    int di;
  2051.  
    a=0;b=r;
  2052.  
    di=3-(r<<1); //判断下个点位置的标志
  2053.  
    while(a<=b)
  2054.  
    {
  2055.  
    LCD_DrawPoint(x0 a,y0-b); //5
  2056.  
    LCD_DrawPoint(x0 b,y0-a); //0
  2057.  
    LCD_DrawPoint(x0 b,y0 a); //4
  2058.  
    LCD_DrawPoint(x0 a,y0 b); //6
  2059.  
    LCD_DrawPoint(x0-a,y0 b); //1
  2060.  
    LCD_DrawPoint(x0-b,y0 a);
  2061.  
    LCD_DrawPoint(x0-a,y0-b); //2
  2062.  
    LCD_DrawPoint(x0-b,y0-a); //7
  2063.  
    a ;
  2064.  
    //使用Bresenham算法画圆
  2065.  
    if(di<0)di =4*a 6;
  2066.  
    else
  2067.  
    {
  2068.  
    di =10 4*(a-b);
  2069.  
    b--;
  2070.  
    }
  2071.  
    }
  2072.  
    }
  2073.  
    //在指定位置显示一个字符
  2074.  
    //x,y:起始坐标
  2075.  
    //num:要显示的字符:" "--->"~"
  2076.  
    //size:字体大小 12/16/24/32
  2077.  
    //mode:叠加方式(1)还是非叠加方式(0)
  2078.  
    void LCD_ShowChar(u16 x,u16 y,u8 num,u8 size,u8 mode)
  2079.  
    {
  2080.  
    u8 temp,t1,t;
  2081.  
    u16 y0=y;
  2082.  
    u8 csize=(size/8 ((size%8)?1:0))*(size/2); //得到字体一个字符对应点阵集所占的字节数
  2083.  
    num=num-' ';//得到偏移后的值(ASCII字库是从空格开始取模,所以-' '就是对应字符的字库)
  2084.  
    for(t=0;t<csize;t )
  2085.  
    {
  2086.  
    if(size==12)temp=asc2_1206[num][t]; //调用1206字体
  2087.  
    else if(size==16)temp=asc2_1608[num][t]; //调用1608字体
  2088.  
    else if(size==24)temp=asc2_2412[num][t]; //调用2412字体
  2089.  
    else if(size==32)temp=asc2_3216[num][t]; //调用3216字体
  2090.  
    else return; //没有的字库
  2091.  
    for(t1=0;t1<8;t1 )
  2092.  
    {
  2093.  
    if(temp&0x80)LCD_Fast_DrawPoint(x,y,POINT_COLOR);
  2094.  
    else if(mode==0)LCD_Fast_DrawPoint(x,y,BACK_COLOR);
  2095.  
    temp<<=1;
  2096.  
    y ;
  2097.  
    if(y>=lcddev.height)return; //超区域了
  2098.  
    if((y-y0)==size)
  2099.  
    {
  2100.  
    y=y0;
  2101.  
    x ;
  2102.  
    if(x>=lcddev.width)return; //超区域了
  2103.  
    break;
  2104.  
    }
  2105.  
    }
  2106.  
    }
  2107.  
    }
  2108.  
    //m^n函数
  2109.  
    //返回值:m^n次方.
  2110.  
    u32 LCD_Pow(u8 m,u8 n)
  2111.  
    {
  2112.  
    u32 result=1;
  2113.  
    while(n--)result*=m;
  2114.  
    return result;
  2115.  
    }
  2116.  
    //显示数字,高位为0,则不显示
  2117.  
    //x,y :起点坐标
  2118.  
    //len :数字的位数
  2119.  
    //size:字体大小
  2120.  
    //color:颜色
  2121.  
    //num:数值(0~4294967295);
  2122.  
    void LCD_ShowNum(u16 x,u16 y,u32 num,u8 len,u8 size)
  2123.  
    {
  2124.  
    u8 t,temp;
  2125.  
    u8 enshow=0;
  2126.  
    for(t=0;t<len;t )
  2127.  
    {
  2128.  
    temp=(num/LCD_Pow(10,len-t-1));
  2129.  
    if(enshow==0&&t<(len-1))
  2130.  
    {
  2131.  
    if(temp==0)
  2132.  
    {
  2133.  
    LCD_ShowChar(x (size/2)*t,y,' ',size,0);
  2134.  
    continue;
  2135.  
    }else enshow=1;
  2136.  
     
  2137.  
    }
  2138.  
    LCD_ShowChar(x (size/2)*t,y,temp '0',size,0);
  2139.  
    }
  2140.  
    }
  2141.  
    //显示数字,高位为0,还是显示
  2142.  
    //x,y:起点坐标
  2143.  
    //num:数值(0~999999999);
  2144.  
    //len:长度(即要显示的位数)
  2145.  
    //size:字体大小
  2146.  
    //mode:
  2147.  
    //[7]:0,不填充;1,填充0.
  2148.  
    //[6:1]:保留
  2149.  
    //[0]:0,非叠加显示;1,叠加显示.
  2150.  
    void LCD_ShowxNum(u16 x,u16 y,u32 num,u8 len,u8 size,u8 mode)
  2151.  
    {
  2152.  
    u8 t,temp;
  2153.  
    u8 enshow=0;
  2154.  
    for(t=0;t<len;t )
  2155.  
    {
  2156.  
    temp=(num/LCD_Pow(10,len-t-1));
  2157.  
    if(enshow==0&&t<(len-1))
  2158.  
    {
  2159.  
    if(temp==0)
  2160.  
    {
  2161.  
    if(mode&0X80)LCD_ShowChar(x (size/2)*t,y,'0',size,mode&0X01);
  2162.  
    else LCD_ShowChar(x (size/2)*t,y,' ',size,mode&0X01);
  2163.  
    continue;
  2164.  
    }else enshow=1;
  2165.  
     
  2166.  
    }
  2167.  
    LCD_ShowChar(x (size/2)*t,y,temp '0',size,mode&0X01);
  2168.  
    }
  2169.  
    }
  2170.  
    //显示字符串
  2171.  
    //x,y:起点坐标
  2172.  
    //width,height:区域大小
  2173.  
    //size:字体大小
  2174.  
    //*p:字符串起始地址
  2175.  
    void LCD_ShowString(u16 x,u16 y,u16 width,u16 height,u8 size,u8 *p)
  2176.  
    {
  2177.  
    u8 x0=x;
  2178.  
    width =x;
  2179.  
    height =y;
  2180.  
    while((*p<='~')&&(*p>=' '))//判断是不是非法字符!
  2181.  
    {
  2182.  
    if(x>=width){x=x0;y =size;}
  2183.  
    if(y>=height)break;//退出
  2184.  
    LCD_ShowChar(x,y,*p,size,0);
  2185.  
    x =size/2;
  2186.  
    p ;
  2187.  
    }
  2188.  
    }
  2189.  
     
  2190.  
     
  2191.  
     
  2192.  
     
  2193.  
     
  2194.  
     
  2195.  
     
  2196.  
     
  2197.  
     
  2198.  
     
  2199.  
     
  2200.  
     
  2201.  
     
  2202.  
     
  2203.  
     
  2204.  
     
  2205.  
     
  2206.  
     
  2207.  
     
  2208.  
     
  2209.  
     
  2210.  
     
  2211.  
     
  2212.  
     
  2213.  
     
  2214.  
     
  2215.  
     
  2216.  
     
  2217.  
     
  2218.  
     
  2219.  
     
学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgabkgf
系列文章
更多 icon
同类精品
更多 icon
继续加载