一些关于1602显示的头文件.docx
《一些关于1602显示的头文件.docx》由会员分享,可在线阅读,更多相关《一些关于1602显示的头文件.docx(24页珍藏版)》请在冰豆网上搜索。
一些关于1602显示的头文件
RD_LCD1602b.c
/***********************************************************
* 函数库说明:
LCD1602B基本驱动函数库 *
* 版本:
v2.11 *
* 作者:
傻孩子 *
* 创建日期:
2005年9月6日 *
* -------------------------------------------------------- *
* [支 持 库] *
* -------------------------------------------------------- *
* [版本更新] *
* 修改:
傻孩子 *
* 修改日期:
2006年6月8日 *
* 版本:
v2.11 *
* -------------------------------------------------------- *
* [版本历史] *
* -------------------------------------------------------- *
* [使用说明] *
* 1、需要底层硬件驱动函数支持 *
* 基本的宏定义:
*
* LCD_RS LCD_RW LCD_E *
* LCD_SET_WRITE_DATA LCD_SET_READ_DATA *
* LCD_SEND_HALF_CHAR_HIGH(a) *
* LCD_SEND_HALF_CHAR_LOW(a) *
* 当处于串行状态下时,只定义LCD_RS *
* LCD_E LCD_SEND_HALF_CHAR_HIGH(a) *
* LCD_SEND_HALF_CHAR_LOW(a) *
* 2、如果采用8数据位连接,则需要定义数据端口 *
* LCD_DATA_PORT,同时需要定义宏来开启该功 *
* 能:
_LCD1602_FULL_DATA_MODEL *
* 3、需要修改引用宏定义来指定底层硬件驱动 *
* 函数库。
*
* 4、本库驱动下的LCD显示支持1602的各种连 *
* 接方法。
当使用只写模式是请在引用该头 *
* 文件之前加上宏定义:
*
* # define _USE_LCD_ONLY_WRITE *
* 5、在调用本库之前,定义RunStringSpeed可 *
* 以设置滚屏的速度。
通过在引用前定义 *
* FlashTimeOut 和 FlashGIFTimeOut 可以 *
* 改变字符闪烁的频率。
*
* 6、增加一个GIF字幕特效函数。
*
* 7、确定没有LCD复位问题。
*
* 8、增加对595串行转并行连接的支持。
*
* 需要头文件SerialToCollateral.h *
***********************************************************/
/********************
* 头 文 件 配 置 区 *
********************/
# include "RD_MacroAndConst.h"
# include "LIB_Config.h"
# include "RD_LCD1602B.h"
/********************
* 系 统 宏 定 义 *
********************/
/*------------------*
* 常 数 宏 定 义 *
*------------------*/
# define LCD_CMD_DISP_CTR 0x0c
# define LCD_CMD_CLS 0x01
# define LCD_CMD_ENTER_SET 0x02
# define LCD_CMD_ICON_SHOW 0x0f
# define LCD_CMD_ICON_HIDE 0x0c
# define LCD_CMD_NOT_MOVE 0x14
# define LCD_WRITE 0x00
# define LCD_READ 0x01
# define LCD_COMMAND 0x00
# define LCD_DATA 0x01
#ifndef LCD_RUN_STRING_SPEED
# define LCD_RUN_STRING_SPEED 100
#endif
#ifndef LCD_FLASH_TIME_OUT
# define LCD_FLASH_TIME_OUT 0x03ff
#endif
#ifndef LCD_FLASH_STRING_GROUP_TIME_OUT
# define LCD_FLASH_STRING_GROUP_TIME_OUT 0x03ff
#endif
/*------------------*
* 动 作 宏 定 义 *
*------------------*/
#if defined(_USE_LCD_ONLY_WRITE) || defined(_Use_LCD1602B_Serial)
#ifndef LCD_SET_WRITE_DATA
# define LCD_SET_WRITE_DATA
#endif
#ifndef LCD_SET_READ_DATA
# define LCD_SET_READ_DATA
#endif
#ifndef LCD_RW
# define LCD_RW LCD_Temp
#endif
#ifndef LCD_BF
# define LCD_BF LCD_Temp
#endif
#else
#ifndef LCD_SET_WRITE_DATA
# error No define LCD_SET_WRITE_DATA
#endif
#ifndef LCD_SET_READ_DATA
# error No define LCD_SET_READ_DATA
#endif
#ifndef LCD_RW
# error No define LCD_RW
#endif
#ifndef LCD_BF
# error No define LCD_BF
#endif
#endif
#ifndef LCD_RS
# error Need define LCD_RS
#endif
#ifndef _Use_LCD1602B_Serial
# define SetReadState LCD_SET_READ_DATA;LCD_RS = LCD_COMMAND;LCD_RW = LCD_READ;
# define SetRead LCD_SET_READ_DATA;LCD_RW = LCD_READ;
# define SetWrite LCD_SET_WRITE_DATA;LCD_RW = LCD_WRITE;
# define SetCommand LCD_RS = LCD_COMMAND;
# define SetData LCD_RS = LCD_DATA;
#else
# define _USE_LCD_ONLY_WRITE
# define SetReadState
# define SetRead
# define SetWrite
# define SetCommand LCD_RS = LCD_COMMAND;refreshVirtualPORT();
# define SetData LCD_RS = LCD_DATA;refreshVirtualPORT();
# define SetEnable LCD_E = High;refreshVirtualPORT();
# define SetDisable LCD_E = Low;refreshVirtualPORT();
#endif
#ifdef _LCD1602_FULL_DATA_MODEL
#ifndef LCD_DATA_PORT
#error Need for macro:
LCD_DATA_PORT
#endif
#endif
/********************
* 用户变量类型定义 *
********************/
/********************
* 模块结构体定义区 *
********************/
/********************
* 模块函数声明区 *
********************/
static void LCDDelay(UINT16 Time);
static void LCDDelayUs(UINT16 Time);
/********************
* 全局函数声明区 *
********************/
void LCDInit(void);
void LCDSetXY(UINT8 X,UINT8 Y);
void LCDDisplayString(UINT8 *String);
void LCDDisplayNum(unsigned long Num,UINT8 BitCount);
void RunString(UINT8 *String,UINT8 Y,UINT8 StartX,UINT8 EndX);
UINT8 StringLength(UINT8 *String);
void Flash(UINT8 *String,UINT8 Icon,UINT8 X,UINT8 Y);
void FlashStringGroup(UINT8 String[][17],UINT8 StringCounter,UINT8 X,UINT8 Y);
void LCDWaitForReady(void);
void LCDSendCommand(UINT8 Command);
void LCDSendData(UINT8 Data);
void PrintD(INT32 nNumber,UINT8 chCounter);
/********************
* 全局函数引用区 *
********************/
#ifdef _Use_LCD1602B_Serial
extern void refreshVirtualPORT(void);
#endif
/********************
* 模块变量声明区 *
********************/
const static UINT8 CHR[16] = {'0','1','2','3','4','5','6','7','8'
,'9','a','b','c','d','e','f'};
/********************
* 全局变量声明区 *
********************/
static UINT8 LCD_Temp = 0;
/********************
* 全局变量引用区 *
********************/
#ifndef SYS_TIMER_MS_ADD_UNTILL_OVF
extern UINT16 g_wSystemTimer;
#define SYS_TIMER_MS_ADD_UNTILL_OVF g_wSystemTimer
#else
extern UINT16 SYS_TIMER_MS_ADD_UNTILL_OVF;
#endif
/***********************************************************
* 函数说明:
LCD驱动类毫秒延时函数 *
* 输入:
需要延时的大体毫秒数 *
* 输出:
无 *
* 调用函数:
LCDDelayUs() *
***********************************************************/
static void LCDDelay(UINT16 Time)
{
UINT16 TimeCounter = 0;
for (TimeCounter = 0;TimeCounter < Time;TimeCounter ++)
{
LCDDelayUs(255);
}
}
/***********************************************************
* 函数说明:
LCD驱动指令周期延时函数 *
* 输入:
需要大体延时Us数 *
* 输出:
无 *
* 调用函数:
无 *
***********************************************************/
static void LCDDelayUs(UINT16 Time)
{
UINT16 TimeCounter = 0;
for (TimeCounter = 0;TimeCounter < Time;TimeCounter ++)
{
asm("nop");
}
}
/***********************************************************
* 函数说明:
LCD初始化函数 *
* 输入:
无 *
* 输出:
无 *
* 调用函数:
LCDDelay() LCDWaitForReady() *
* LCDSendCommand() *
***********************************************************/
void LCDInit(void)
{
LCDDelay(15);
#ifndef _LCD1602_FULL_DATA_MODEL
LCDSendCommand(0x28);
#else
LCDSendCommand(0x38);
#endif
//LCDWaitForReady();
LCDDelay(100);
LCDSendCommand(LCD_CMD_DISP_CTR);
LCDDelay(100);
LCDSendCommand(LCD_CMD_CLS);
LCDDelay(100);
LCDSendCommand(LCD_CMD_ENTER_SET);
LCDDelay(100);
LCDSendCommand(LCD_CMD_NOT_MOVE);
}
#ifndef _Use_LCD1602B_Serial
/***********************************************************
* 函数说明:
向LCD发送指令函数 *
* 输入:
需要发送的指令 *
* 输出:
无 *
* 调用函数:
LCD_SEND_HALF_CHAR_HIGH() LCD_SEND_HALF_CHAR_LOW() *
***********************************************************/
void LCDSendCommand(UINT8 Command)
{
SetWrite;
SetCommand;
#ifndef _LCD1602_FULL_DATA_MODEL
{
LCD_SEND_HALF_CHAR_HIGH(Command);
LCD_E = HIGH;
LCD_E = LOW;
}
{
LCD_SEND_HALF_CHAR_LOW(Command);
LCD_E = HIGH;
LCD_E = LOW;
}
#else
LCD_DATA_PORT = Command;
LCD_E = HIGH;
LCD_E = LOW;
#endif
SetRead;
SetCommand;
}
/***********************************************************
* 函数说明:
向LCD发送数据函数 *
* 输入:
需要发送的数据 *
* 输出:
无 *
* 调用函数:
LCD_SEND_HALF_CHAR_HIGH() LCD_SEND_HALF_CHAR_LOW() *
***********************************************************/
void LCDSendData(UINT8 Data)
{
SetWrite;
SetData;
#ifndef _LCD1602_FULL_DATA_MODEL
{
LCD_SEND_HALF_CHAR_HIGH(Data);
LCD_E = HIGH;
LCD_E = LOW;
}
{
LCD_SEND_HALF_CHAR_LOW(Data);
LCD_E = HIGH;
LCD_E = LOW;
}