/***************************************************************************************
****************************************************************************************
* FILE : lcd.c
* Description :
*
* Copyright (c) 2003~2008 by 创易电子. All Rights Reserved.
*
* History:
* Version Name Date Description
1.0 Wang Shaowei 2008/12/16 Initial Version (For DesignEasy LCM MCU board)
1.1 Liu Ying 2008/12/21 Comments
****************************************************************************************
****************************************************************************************/
#include "lcd.h"
#ifdef LOGO
#include "logo.h"
#endif
#define LCD_WIDTH 176
#define LCD_HEIGHT 220
#define LCD_FULL_SCREEN_X_START 0
#define LCD_FULL_SCREEN_Y_START 0
#define LCD_FULL_SCREEN_X_END (LCD_WIDTH-1)
#define LCD_FULL_SCREEN_Y_END (LCD_HEIGHT-1)
#define LCD_R_SET_COLUMN_ADDR_START_R61503 0x0050
#define LCD_R_SET_COLUMN_ADDR_END_R61503 0x0051
#define LCD_R_SET_ROW_ADDR_START_R61503 0x0052
#define LCD_R_SET_ROW_ADDR_END_R61503 0x0053
#define LCD_R_SET_RAM_ADDR_START_R61503 0x0020
#define LCD_R_SET_RAM_ADDR_END_R61503 0x0021
#define LCD_R_MEMORY_WRITE_R61503 0x0022
/*==================================================================
* Function : Truly_R61503_init
* Description : init R61503,
初始化LCD,初始化命令由LCD原厂提供,
有兴趣可以对照lcd driver ic看看每条命令的含义,
调节lcd显示效果也通过这些命令。
注: 这部分代码,本店不予技术支持
* Input Para : void
* Output Para : void
* Return Value: void
==================================================================*/
static void Truly_R61503_init(void)
{
LCD_CMD16(0x0000);
LCD_DAT16(0x0001);
//Delayms(20);
LCD_CMD16(0x0007);LCD_DAT16(0x0000);
LCD_CMD16(0x0012);LCD_DAT16(0x0000);
//Delayms(10);
LCD_CMD16(0x00A4);LCD_DAT16(0x0001);
//Delayms(10);
LCD_CMD16(0x0030);LCD_DAT16(0x0601);
LCD_CMD16(0x0031);LCD_DAT16(0x0501);
LCD_CMD16(0x0032);LCD_DAT16(0x0307);
LCD_CMD16(0x0033);LCD_DAT16(0x0206);
LCD_CMD16(0x0034);LCD_DAT16(0x0002);
LCD_CMD16(0x0035);LCD_DAT16(0x0004);
LCD_CMD16(0x0036);LCD_DAT16(0x0600);
LCD_CMD16(0x0037);LCD_DAT16(0x0701);
LCD_CMD16(0x0038);LCD_DAT16(0x1f0f);
LCD_CMD16(0x0039);LCD_DAT16(0x0000);
LCD_CMD16(0x0007);LCD_DAT16(0x0031);
LCD_CMD16(0x0018);LCD_DAT16(0x0001);
LCD_CMD16(0x0010);LCD_DAT16(0x11b0);
LCD_CMD16(0x0011);LCD_DAT16(0x0007);
LCD_CMD16(0x0012);LCD_DAT16(0x0114);//
//Delayms(10);
LCD_CMD16(0x0013);LCD_DAT16(0x8c02);//8d07 8c03
LCD_CMD16(0x0012);LCD_DAT16(0x1115);//1114
//Delayms(10);
LCD_CMD16(0x0001);LCD_DAT16(0x0100);
LCD_CMD16(0x0002);LCD_DAT16(0x0700);
LCD_CMD16(0x0003);LCD_DAT16(0x1030);
LCD_CMD16(0x0008);LCD_DAT16(0x0603);
LCD_CMD16(0x0070);LCD_DAT16(0x1b00);
LCD_CMD16(0x0071);LCD_DAT16(0x0001);
LCD_CMD16(0x0090);LCD_DAT16(0x0000);//0004
LCD_CMD16(0x0091);LCD_DAT16(0x0000);
LCD_CMD16(0x0092);LCD_DAT16(0x0002);
LCD_CMD16(0x0007);LCD_DAT16(0x0001);
//Delayms(30);
LCD_CMD16(0x0007);LCD_DAT16(0x0021);
//Delayms(10);
LCD_CMD16(0x0012);LCD_DAT16(0x1134);
//Delayms(10);
LCD_CMD16(0x0007);LCD_DAT16(0x0233);
LCD_CMD16(0x0022);
}
/*display on/off sleep in/out 由LCD原厂提供,
有兴趣可以对照lcd driver ic看看每条命令的含义,
注: 这部分代码,本店不予技术支持*/
static void Truly_R61503_display_off(void)
{
LCD_CMD16(0x0007);LCD_DAT16(0x0032);
LCD_CMD16(0x0012);LCD_DAT16(0x0134);
LCD_CMD16(0x0007);LCD_DAT16(0x0000);
LCD_CMD16(0x0010);LCD_DAT16(0x0180);
LCD_CMD16(0x0011);LCD_DAT16(0x0660);
LCD_CMD16(0x0012);LCD_DAT16(0x0104);
LCD_CMD16(0x0013);LCD_DAT16(0x0B04);
LCD_CMD16(0x0010);LCD_DAT16(0x0100);
}
static void Truly_R61503_display_on(void)
{
LCD_CMD16(0x0007);LCD_DAT16(0x0031);
LCD_CMD16(0x0018);LCD_DAT16(0x0001);
LCD_CMD16(0x0010);LCD_DAT16(0x11B0);
LCD_CMD16(0x0011);LCD_DAT16(0x0001);
LCD_CMD16(0x0012);LCD_DAT16(0x1134);
LCD_CMD16(0x0013);LCD_DAT16(0x8b02);
LCD_CMD16(0x0014);LCD_DAT16(0x8000);
LCD_CMD16(0x0012);LCD_DAT16(0x1134);
LCD_CMD16(0x0018);LCD_DAT16(0x0000);//要加这条指令,否则退出SLEEP 时可能会出现白屏
LCD_CMD16(0x0007);LCD_DAT16(0x0001);
LCD_CMD16(0x0007);LCD_DAT16(0x0021);
LCD_CMD16(0x0007);LCD_DAT16(0x0233);
}
/*==================================================================
* Function : Display_Logo
* Description : 显示全屏红色(0xF800),
若定义了LOGO,则在屏中间显示创易电子logo
* Input Para : void
* Output Para : void
* Return Value: void
==================================================================*/
static void Display_Logo(void)
{
U8 X,Y;
U8 code * pPoint;
/*设置刷屏区域*/
lcd_set_write_area(LCD_FULL_SCREEN_X_START, LCD_FULL_SCREEN_Y_START, LCD_FULL_SCREEN_X_END, LCD_FULL_SCREEN_Y_END);
/*送显示数据*/
for(Y = 0; Y < 55; Y++)
{
for(X = 0; X < 176; X++)
{
LCD_DAT(0xF8);
LCD_DAT(0x00);
}
}
#ifdef LOGO
pPoint = gImage_Logo;
for(Y = 55; Y < 165; Y++)
{
for(X = 0; X < 176; X++)
{
LCD_DAT(*pPoint ++);
LCD_DAT(*pPoint++);
}
}
#else
for(Y = 55; Y < 165; Y++)
{
for(X = 0; X < 176; X++)
{
LCD_DAT(0xF8);
LCD_DAT(0x00);
}
}
#endif
for(Y = 165; Y < 220; Y++)
{
for(X = 0; X < 176; X++)
{
LCD_DAT(0xF8);
LCD_DAT(0x00);
}
}
}
/*==================================================================
* Function : lcd_init
* Description : 初始化lcd,在使用lcd之前必须调用
* Input Para : void
* Output Para : void
* Return Value: void
==================================================================*/
void lcd_init(void)
{
/*************************************************************************/
// 以下部分需根据自己的单片机或者ARM系统相应配置
/*配置GPIO定义*/
P1M0 = 0x03;
P1M1 = 0x00;
/*配置总线速度*/
BUS_SPEED = 0x01;
/*外部RAM使能,一般单片机都需要把外部ram总线打开,否则外部总线无效*/
SETBIT(AUXR, 1);
/*************************************************************************/
//以下部分为LCD硬件复位,非常重要
//注意LCD_nRST的定义需要根据各自的系统配置
/*复位*/
LCD_nRST = 1;
LCD_nRST = 0;
uty_delay(0x2000);
LCD_nRST = 1;
/*************************************************************************/
//开背光,否则无法显示
//注意BL_EN的定义需要根据各自的系统配置
BL_EN =1;
/*************************************************************************/
//初始化LCD
//注意其中的LCD_CMD16、LCD_DAT16需要根据各自系统配置
//uty_delay为各个系统的delay函数
Truly_R61503_init();
/*************************************************************************/
//初始化完成之后就可以刷屏了
Display_Logo();
/*在创易电子的demo程序中,便于后面刷屏,所以先设置了刷屏区域*/
lcd_set_write_area(LCD_FULL_SCREEN_X_START, LCD_FULL_SCREEN_Y_START, LCD_FULL_SCREEN_X_END, LCD_FULL_SCREEN_Y_END);
}
/*==================================================================
* Function : lcd_set_write_area
* Description : 设置lcd memory write的区域
* Input Para : U8 StartX, U8 StartY,U8 EndX, U8 EndY
* Output Para : void
* Return Value: void
==================================================================*/
void lcd_set_write_area(U8 StartX, U8 StartY,U8 EndX, U8 EndY)
{
LCD_CMD16(LCD_R_SET_COLUMN_ADDR_START_R61503);
LCD_DAT16(StartX);
LCD_CMD16(LCD_R_SET_COLUMN_ADDR_END_R61503);
LCD_DAT16(EndX);
LCD_CMD16(LCD_R_SET_ROW_ADDR_START_R61503);
LCD_DAT16(StartY);
LCD_CMD16(LCD_R_SET_ROW_ADDR_END_R61503);
LCD_DAT16(EndY);
LCD_CMD16(LCD_R_SET_RAM_ADDR_START_R61503);
LCD_DAT16(StartX);
LCD_CMD16(LCD_R_SET_RAM_ADDR_END_R61503);
LCD_DAT16(StartY);
LCD_CMD16(LCD_R_MEMORY_WRITE_R61503);
}
/*==================================================================
* Function : lcd_enter_sleep
* Description :