|
发表于 2008-2-10 22:03:22
|
显示全部楼层
/***********************************************************
* 函数库说明:LCD320240基本驱动函数声明库 *
* 版本: v1.00 *
* 作者: 王卓然 *
* 创建日期: 2007年11月12日 *
* -------------------------------------------------------- *
* [支 持 库] *
* 支持库名称:RD_MacroAndConst.h *
* 需要版本: v0.01 &abv *
* 支持库说明:系统常用宏定义库 *
* *
* 支持库名称:LIB_Config.h *
* 需要版本: ----- *
* 支持库说明:库函数配置声明库 *
* -------------------------------------------------------- *
* [版本更新] *
* 修改: *
* 修改日期: *
* 版本: *
* -------------------------------------------------------- *
* [版本历史] *
* -------------------------------------------------------- *
* [使用说明] *
***********************************************************/
/********************
* 头 文 件 配 置 区 *
********************/
# include "RD_MacroAndConst.h"
# include "GUI_Config.h"
/********************
* 系 统 宏 定 义 *
********************/
/*------------------*
* 常 数 宏 定 义 *
*------------------*/
# define LCD_CMD_SCROLL 0x44
# define LCD_CMD_CSRFORM 0x5D
# define LCD_CMD_CGRAM_ADR 0x5C
# define LCD_CMD_CSRDIR 0x4C
# define LCD_CMD_HDOT_SCR 0x5A
# define LCD_CMD_OVLAY 0x5B
# define LCD_CMD_CSRW 0x46
# define LCD_CMD_CSRR 0x47
# define LCD_CMD_MWRITE 0x42
# define LCD_CMD_MREAD 0x43
# define LCD_LAYER_MIX_MODEL_OR 0x00
# define LCD_LAYER_MIX_MODEL_EXCLUSIVE_OR 0x01
# define LCD_LAYER_MIX_MODEL_AND 0x02
# define LCD_LAYER_MIX_MODEL_PRIORITY_OR 0x03
# define LCD_CURSOR 0
# define LCD_SAD1 2
# define LCD_SAD2_4 4
# define LCD_SAD3 6
# define LCD_DISP_BLANK 0x00
# define LCD_DISP_SHOW 0x01
# define LCD_DISP_FLASH 0x02
# define LCD_DISP_FLASH_FAST 0x03
# define _M0 0
# define _M1 1
# define _M2 2
# define _WS 3
# define _IV 5
# define _TL 6
# define _DR 7
# define _DM1 2
# define _DM2 3
# define _OV 4
/*------------------*
* 动 作 宏 定 义 *
*------------------*/
#ifndef LCD_EL_ON
# define LCD_EL_ON s_chTemp
#endif
#ifndef LCD_DISP_OFF
# error Need for defined LCD_DISP_OFF _Pxn !
#endif
#ifndef LCD_DATA_OUT
# error Need for defined LCD_DATA_OUT PORTx !
#endif
#ifndef LCD_DATA_IN
# error Need for defined LCD_DATA_IN PINx !
#endif
#ifndef LCD_DATA_DDR
# error Need for defined LCD_DATA_DDR DDRx !
#endif
#ifndef LCD_A0
# error Need for defined LCD_A0 _Pxn !
#endif
#ifndef LCD_CS
# error Need for defined LCD_CS _Pxn !
#endif
#ifndef LCD_WR
# error Need for defined LCD_WR _Pxn !
#endif
#ifndef LCD_RD
# error Need for defined LCD_RD _Pxn !
#endif
#ifndef LCD_RST
# warning You may be forget to define LCD_RST !
# define LCD_EL_ON s_chTemp
#endif
# define SEND_CMD(n) LCD_320240_Send_Command(n);
# define SEND_DATA(n) LCD_320240_Send_Data(n);
# define READ_STATUS LCD_320240_Read_Status()
# define READ_DATA LCD_320240_Read_Data()
/********************
* 用户变量类型定义 *
********************/
typedef struct _LCD_320240_System_Set LCD_320240_SYSTEM_SET;
/********************
* 模块结构体定义区 *
********************/
struct _LCD_320240_System_Set
{
//P1
unsigned M0:1;
unsigned M1:1;
unsigned M2:1;
unsigned W_S:1;
unsigned :1;
unsigned IV:1;
unsigned T_L:1;
unsigned DR:1;
//P2
unsigned FX:4;
unsigned :3;
unsigned WF:1;
//P3
unsigned FY:4;
unsigned :4;
uint8 C_R;
uint8 TC_R;
uint8 L_F;
uint16 AP;
};
/********************
* 函 数 声 明 区 *
********************/
void LCD_320240_INIT(void);
void LCD_320240_Send_Command(uint8 chCMD);
void LCD_320240_Write_Display_Data_Stream(uint8 *pData,uint16 wLength,uint8 chBlankSymble);
uint8 *LCD320240_Read_Display_Data_Stream(uint8 *pData,uint16 wLength);
void LCD_320240_CSRW(uint16 wAddress);
void LCD_320240_Scroll(LCD_320240_SCROLL *pScroll,uint8 chParameterID);
void LCD_320240_Write_Display_Data(uint8 chData);
uint8 LCD_320240_Read_Display_Data(void);
void LCD_320240_CSRDIR(uint8 chDirection);
uint8 LCD_320240_Read_Status(void);
/********************
* 模块函数声明区 *
********************/
static void LCD_320240_Send_Data(uint8 chData);
uint8 LCD_320240_Read_Status(void);
static uint8 LCD_320240_Read_Data(void);
static void LCD_320240_System_Set(LCD_320240_SYSTEM_SET *pSet,uint8 chParameterID);
static void LCD_320240_CSRFORM(uint8 chWidth,uint8 chHeight);
static void LCD_320240_HDot_SCR(uint8 chPixels);
static void LCD_320240_OVLAY(uint8 chLayerMixModel,
BOOL bIfUseGraphics,BOOL bIfUseThreeLayer);
static void LCD_320240_Display_On_Off(uint8 chSADFlashSet,BOOL bEnable);
//static void LCD_320240_CGRAM_ADR(uint16 wAddress);
/********************
* 模块变量声明区 *
********************/
static uint8 s_chTemp = 0; //容错用变量
static LCD_320240_SYSTEM_SET s_SystemSet = {0};
static LCD_320240_SCROLL g_ScreenScroll = {0};
/********************
* 全局变量声明区 *
********************/
/***********************************************************
* 函数说明:向LCD发送指令函数 *
* 输入: 要发送的数据 *
* 输出: 无 *
* 调用函数:无 *
***********************************************************/
void LCD_320240_Send_Command(uint8 chCMD)
{
LCD_DATA_DDR = 0xff;
LCD_DATA_OUT = chCMD;
LCD_CS = LOW;
LCD_A0 = HIGH;
LCD_RD = HIGH;
LCD_WR = LOW;
LCD_WR = HIGH;
LCD_CS = HIGH;
//释放数据总线
//LCD_DATA_DDR = 0x00;
//LCD_DATA_OUT = 0x00;
}
/***********************************************************
* 函数说明:向LCD发送数据函数 *
* 输入: 要发送的数据 *
* 输出: 无 *
* 调用函数:无 *
***********************************************************/
static void LCD_320240_Send_Data(uint8 chData)
{
LCD_DATA_DDR = 0xff;
LCD_DATA_OUT = chData;
LCD_CS = LOW;
LCD_A0 = LOW;
LCD_RD = HIGH;
LCD_WR = LOW;
LCD_WR = HIGH;
LCD_CS = HIGH;
//释放数据总线
//LCD_DATA_DDR = 0x00;
//LCD_DATA_OUT = 0x00;
}
/***********************************************************
* 函数说明:读取LCD320240系统状态 *
* 输入: 无 *
* 输出: 读取到的系统状态 *
* 调用函数:无 *
***********************************************************/
uint8 LCD_320240_Read_Status(void)
{
uint8 chTempData = 0;
//释放数据总线
LCD_DATA_DDR = 0x00;
LCD_DATA_OUT = 0x00;
LCD_CS = LOW;
LCD_A0 = LOW;
LCD_RD = LOW;
LCD_WR = HIGH;
NOP();
chTempData = LCD_DATA_IN;
LCD_RD = HIGH;
LCD_CS = HIGH;
return chTempData;
}
/***********************************************************
* 函数说明:读取LCD320240存储器数据 *
* 输入: 无 *
* 输出: 读取到的数据 *
* 调用函数:无 *
***********************************************************/
static uint8 LCD_320240_Read_Data(void)
{
uint8 chTempData = 0;
//释放数据总线
LCD_DATA_DDR = 0x00;
LCD_DATA_OUT = 0x00;
LCD_CS = LOW;
LCD_A0 = HIGH;
LCD_RD = LOW;
LCD_WR = HIGH;
NOP();
chTempData = LCD_DATA_IN;
LCD_RD = HIGH;
LCD_CS = HIGH;
return chTempData;
}
/***********************************************************
* 函数说明:LCD320240初始化函数 *
* 输入: 无 *
* 输出: 无 *
* 调用函数:无 *
***********************************************************/
void LCD_320240_INIT(void)
{
uint16 n = 0;
//硬件复位
LCD_RST = LOW;
LCD_DISP_OFF = LOW;
LCD_EL_ON = HIGH;
LCD_DATA_DDR = 0x00;
LCD_DATA_OUT = 0x00;
LCD_WR = HIGH;
LCD_RD = HIGH;
LCD_CS = LOW;
LCD_A0 = HIGH;
for (n = 0;n < 60000;n++);
LCD_RST = HIGH;
LCD_EL_ON = LOW;
#ifdef LCD_320240_USE_EXTERNAL_CGROM
s_SystemSet.M0 = 1;
#endif
#ifdef LCD_320240_USE_MORE_CGRAM
s_SystemSet.M1 = 1;
#endif
#ifdef LCD_320240_USE_16_PIXAL_CHAR
s_SystemSet.M2 = 1;
#endif
#ifdef LCD_320240_USE_DUAL_PANEL_DRIVER
s_SystemSet.W_S = 1;
#endif
s_SystemSet.IV = 1;
#ifndef LCD_320240_FX
s_SystemSet.FX = 7;
#else
s_SystemSet.FX = MIN(LCD_320240_FX,15);
#endif
#ifndef LCD_320240_FY
s_SystemSet.FY = 7;
#else
s_SystemSet.FY = MIN(LCD_320240_FY,15);
#endif
s_SystemSet.WF = 1;
#ifndef LCD_320240_C_R
s_SystemSet.C_R = ((s_SystemSet.FX+1) / 8) * 40-1;
#else
s_SystemSet.C_R = MIN(239,LCD_320240_C_R);
#endif
#ifndef LCD_320240_TC_R
s_SystemSet.TC_R = s_SystemSet.C_R+4;
#else
s_SystemSet.TC_R = MAX(LCD_320240_TC_R,s_SystemSet.C_R + 4);
#endif
#ifndef LCD_320240_L_F
s_SystemSet.L_F = 239;
#else
s_SystemSet.L_F = MIN(LCD_L_F,0xff);
#endif
#ifndef LCD_320240_AP
s_SystemSet.AP = s_SystemSet.C_R+1;
#else
s_SystemSet.AP = MAX(LCD_320240_AP,s_SystemSet.C_R+1);
#endif
LCD_320240_System_Set(&s_SystemSet,8);
g_ScreenScroll.SAD1 = 0;
g_ScreenScroll.SL1 = 240;
g_ScreenScroll.SAD2 = LCD_SCREEN_GRAPHIC_DATA_COUNT;
g_ScreenScroll.SL2 = 240;
g_ScreenScroll.SAD3 = LCD_SCREEN_GRAPHIC_DATA_COUNT << 1;
//g_ScreenScroll.SAD4 = 0;
LCD_320240_Scroll(&g_ScreenScroll,8);
LCD_320240_HDot_SCR(0);
LCD_320240_OVLAY(LCD_LAYER_MIX_MODEL_EXCLUSIVE_OR,TRUE,TRUE);
LCD_320240_Display_On_Off
(
(LCD_DISP_FLASH_FAST<<LCD_CURSOR)|
(LCD_DISP_SHOW<<LCD_SAD1)|
(LCD_DISP_SHOW<<LCD_SAD2_4)|
(LCD_DISP_SHOW<<LCD_SAD3)
,FALSE
);
LCD_320240_CSRFORM(8,7);
LCD_320240_CSRDIR(LCD_CURSOR_DIRECTION_RIGHT);
LCD_320240_CLS_GRAPHIC_FRONT
LCD_320240_CLS_GRAPHIC_MIDDLE
LCD_320240_CLS_GRAPHIC_BACK
LCD_320240_DISPLAY_ENABLE
}
/***********************************************************
* 函数说明:设定图层/光标闪烁方式函数 *
* 输入: 闪烁方式参数 *
* 输出: 无 *
* 调用函数:SEND_CMD() SEND_DATA() *
***********************************************************/
static void LCD_320240_Display_On_Off(uint8 chSADFlashSet,BOOL bEnable)
{
if (bEnable)
{
SEND_CMD(LCD_CMD_DISP_ON);
}
else
{
SEND_CMD(LCD_CMD_DISP_OFF);
}
SEND_DATA(chSADFlashSet);
}
/***********************************************************
* 函数说明:显示模式设置函数 *
* 输入: 图层合并模式,是否进入图形模式, *
* 是否使用3图层 *
* 输出: 无 *
* 调用函数:SEND_CMD() SEND_DATA() *
***********************************************************/
static void LCD_320240_OVLAY(uint8 chLayerMixModel,
BOOL bIfUseGraphics,BOOL bIfUseThreeLayer)
{
uint8 chParameter = 0;
SEND_CMD(LCD_CMD_OVLAY);
chParameter = chLayerMixModel & 0x03;
if (bIfUseGraphics)
{
chParameter |= BIT(_DM1)|BIT(_DM2);
}
if (bIfUseThreeLayer)
{
chParameter |= BIT(_OV);
}
SEND_DATA(chParameter);
}
/***********************************************************
* 函数说明:设置左右滚屏像素数 *
* 输入: 滚屏的像素数 *
* 输出: 无 *
* 调用函数:SEND_CMD() SEND_DATA() *
***********************************************************/
static void LCD_320240_HDot_SCR(uint8 chPixels)
{
SEND_CMD(LCD_CMD_HDOT_SCR);
SEND_DATA(MIN(chPixels,7));
}
/***********************************************************
* 函数说明:光标形状设置函数 *
* 输入: 光标宽度和高度 *
* 输出: 无 *
* 调用函数:无 *
***********************************************************/
static void LCD_320240_CSRFORM(uint8 chWidth,uint8 chHeight)
{
SEND_CMD(LCD_CMD_CSRFORM);
SEND_DATA(MIN(chWidth-1,0x0f));
SEND_DATA(MAX(MIN(chHeight-1,0x0f),1)); //光标宽度至少为2(1+1)
}
/***********************************************************
* 函数说明:系统显示缓冲区设置函数 *
* 输入: 缓冲区设置指针 修改参数的ID *
* 输出: 无 *
* 调用函数:无 *
***********************************************************/
void LCD_320240_Scroll(LCD_320240_SCROLL *pScroll,uint8 chParameterID)
{
uint8 n = 0;
SEND_CMD(LCD_CMD_SCROLL);
while(chParameterID--)
{
SEND_DATA(((uint8 *)pScroll)[n++]);
}
}
/***********************************************************
* 函数说明:系统设置函数 *
* 输入: 系统设置指针 修改参数的ID *
* 输出: 无 *
* 调用函数:无 *
***********************************************************/
static void LCD_320240_System_Set(LCD_320240_SYSTEM_SET *pSet,uint8 chParameterID)
{
uint8 n = 0;
SEND_CMD(LCD_CMD_SYSTEM_SET);
if (chParameterID != 0)
{
SEND_DATA(((uint8 *)pSet)[n] | BIT(4));
n++;
chParameterID--;
}
while(chParameterID--)
{
SEND_DATA(((uint8 *)pSet)[n++]);
}
}
/***********************************************************
* 函数说明:光标自动移动方向设定 *
* 输入: 移动方向 *
* 输出: 无 *
* 调用函数:SEND_CMD() *
***********************************************************/
void LCD_320240_CSRDIR(uint8 chDirection)
{
SEND_CMD(LCD_CMD_CSRDIR | (chDirection & 0x03));
}
/***********************************************************
* 函数说明:设置读写地址(光标地址)函数 *
* 输入: 地址 *
* 输出: 无 *
* 调用函数:SEND_CMD() SEND_DATA() *
***********************************************************/
void LCD_320240_CSRW(uint16 wAddress)
{
SEND_CMD(LCD_CMD_CSRW);
SEND_DATA(wAddress);
SEND_DATA(wAddress>>8);
}
/***********************************************************
* 函数说明:LCD字符生成器地址设置函数 *
* 输入: 地址 *
* 输出: 无 *
* 调用函数:SEND_CMD() SEND_DATA() *
***********************************************************/
/*
static void LCD_320240_CGRAM_ADR(uint16 wAddress)
{
SEND_CMD(LCD_CMD_CGRAM_ADR);
SEND_DATA(wAddress);
SEND_DATA(wAddress>>8);
}
*/
/***********************************************************
* 函数说明:读取LCD320240显存当前读写指针 *
* 输入: 无 *
* 输出: 无 *
* 调用函数:SEND_CMD() READ_DATA() *
***********************************************************/
uint16 LCD_320240_CSRR(void)
{
uint16 wAddress = 0;
SEND_CMD(LCD_CMD_CSRR);
wAddress = READ_DATA;
wAddress |= (uint16)READ_DATA << 8;
return wAddress;
}
/***********************************************************
* 函数说明:单个显存数据发送函数 *
* 输入: 要发送的数据 *
* 输出: 无 *
* 调用函数:SEND_CMD() SEND_DATA() *
***********************************************************/
void LCD_320240_Write_Display_Data(uint8 chData)
{
SEND_CMD(LCD_CMD_MWRITE);
SEND_DATA(chData);
}
/***********************************************************
* 函数说明:读取单个显存数据函数 *
* 输入: 无 *
* 输出: 读取到的数据 *
* 调用函数:SEND_CMD() READ_DATA() *
***********************************************************/
uint8 LCD_320240_Read_Display_Data(void)
{
SEND_CMD(LCD_CMD_MREAD);
return READ_DATA;
}
/***********************************************************
* 函数说明:LCD320240数据流读取函数 *
* 输入: 保存数据的指针,读取数据的大小 *
* 输出: 保存数据的指针 *
* 调用函数:SEND_CMD() *
***********************************************************/
uint8 *LCD320240_Read_Display_Data_Stream(uint8 *pData,uint16 wLength)
{
uint16 n = 0;
if (pData == NULL)
{
//指针为空,无法读取任何数据
return NULL;
}
SEND_CMD(LCD_CMD_MREAD);
//释放数据总线
LCD_DATA_DDR = 0x00;
LCD_DATA_OUT = 0x00;
LCD_WR = HIGH;
LCD_CS = LOW;
LCD_A0 = HIGH;
for (n = 0;n < wLength;n++)
{
LCD_RD = LOW;
WDR();
pData[n] = LCD_DATA_IN;
LCD_RD = HIGH;
}
LCD_CS = HIGH;
return pData;
}
/***********************************************************
* 函数说明:LCD320240数据流发送函数 *
* 输入: 要发送的数据指针,NULL表示清屏,数据的长度 *
* 输出: 无 *
* 调用函数:SEND_CMD() *
***********************************************************/
void LCD_320240_Write_Display_Data_Stream(uint8 *pData,uint16 wLength,uint8 chBlankSymble)
{
uint16 n = 0;
uint8 Temp = 0;
SEND_CMD(LCD_CMD_MWRITE);
LCD_CS = LOW;
if (pData == NULL)
{
LCD_A0 = LOW;
LCD_DATA_DDR = 0xff;
LCD_DATA_OUT = chBlankSymble;
for (n = 0;n < wLength;n++)
{
LCD_WR = LOW;
WDR();
LCD_WR = HIGH;
}
}
else
{
LCD_A0 = LOW;
LCD_DATA_DDR = 0xff;
for (n = 0;n < wLength;n++)
{
LCD_DATA_OUT = pData[n];
LCD_WR = LOW;
WDR();
LCD_WR = HIGH;
}
}
LCD_CS = HIGH;
} |
|