?? rd_lcd1602b.c
字號:
/***********************************************************
* 函數(shù)庫說明:LCD1602B基本驅(qū)動函數(shù)庫 *
* 版本: v2.11 *
* 作者: 傻孩子 *
* 創(chuàng)建日期: 2005年9月6日 *
* -------------------------------------------------------- *
* [支 持 庫] *
* -------------------------------------------------------- *
* [版本更新] *
* 修改: 傻孩子 *
* 修改日期: 2006年6月8日 *
* 版本: v2.11 *
* -------------------------------------------------------- *
* [版本歷史] *
* -------------------------------------------------------- *
* [使用說明] *
* 1、需要底層硬件驅(qū)動函數(shù)支持 *
* 基本的宏定義: *
* 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) *
* 當(dāng)處于串行狀態(tài)下時,只定義LCD_RS *
* LCD_E LCD_SEND_HALF_CHAR_HIGH(a) *
* LCD_SEND_HALF_CHAR_LOW(a) *
* 2、如果采用8數(shù)據(jù)位連接,則需要定義數(shù)據(jù)端口 *
* LCD_DATA_PORT,同時需要定義宏來開啟該功 *
* 能:_LCD1602_FULL_DATA_MODEL *
* 3、需要修改引用宏定義來指定底層硬件驅(qū)動 *
* 函數(shù)庫。 *
* 4、本庫驅(qū)動下的LCD顯示支持1602的各種連 *
* 接方法。當(dāng)使用只寫模式是請在引用該頭 *
* 文件之前加上宏定義: *
* # define _USE_LCD_ONLY_WRITE *
* 5、在調(diào)用本庫之前,定義RunStringSpeed可 *
* 以設(shè)置滾屏的速度。通過在引用前定義 *
* FlashTimeOut 和 FlashGIFTimeOut 可以 *
* 改變字符閃爍的頻率。 *
* 6、增加一個GIF字幕特效函數(shù)。 *
* 7、確定沒有LCD復(fù)位問題。 *
* 8、增加對595串行轉(zhuǎn)并行連接的支持。 *
* 需要頭文件SerialToCollateral.h *
***********************************************************/
/********************
* 頭 文 件 配 置 區(qū) *
********************/
# include "RD_MacroAndConst.h"
# include "LIB_Config.h"
# include "RD_LCD1602B.h"
/********************
* 系 統(tǒng) 宏 定 義 *
********************/
/*------------------*
* 常 數(shù) 宏 定 義 *
*------------------*/
# 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
/*------------------*
* 動 作 宏 定 義 *
*------------------*/
#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
#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
/********************
* 用戶變量類型定義 *
********************/
/********************
* 模塊結(jié)構(gòu)體定義區(qū) *
********************/
/********************
* 模塊函數(shù)聲明區(qū) *
********************/
static void LCDDelay(unsigned int Time);
static void LCDDelayUs(unsigned int Time);
/********************
* 全局函數(shù)聲明區(qū) *
********************/
void LCDInit(void);
void LCDSetXY(char X,char Y);
void LCDDisplayString(char *String);
void LCDDisplayNum(unsigned long Num,char BitCount);
void RunString(char *String,char Y,char StartX,char EndX);
char StringLength(char *String);
void Flash(char *String,char Icon,char X,char Y);
void FlashStringGroup(char String[][17],char StringCounter,char X,char Y);
void LCDWaitForReady(void);
void LCDSendCommand(char Command);
void LCDSendData(char Data);
/********************
* 全局函數(shù)引用區(qū) *
********************/
#ifdef _Use_LCD1602B_Serial
extern void refreshVirtualPORT(void);
#endif
/********************
* 模塊變量聲明區(qū) *
********************/
const static char CHR[16] = {'0','1','2','3','4','5','6','7','8'
,'9','a','b','c','d','e','f'};
/********************
* 全局變量聲明區(qū) *
********************/
static char LCD_Temp = 0;
/********************
* 全局變量引用區(qū) *
********************/
#ifndef SYS_TIMER_MS_ADD_UNTILL_OVF
extern unsigned int SystemTimer;
#define SYS_TIMER_MS_ADD_UNTILL_OVF SystemTimer
#else
extern unsigned int SYS_TIMER_MS_ADD_UNTILL_OVF;
#endif
/***********************************************************
* 函數(shù)說明:LCD驅(qū)動類毫秒延時函數(shù) *
* 輸入: 需要延時的大體毫秒數(shù) *
* 輸出: 無 *
* 調(diào)用函數(shù):LCDDelayUs() *
***********************************************************/
static void LCDDelay(unsigned int Time)
{
unsigned int TimeCounter = 0;
for (TimeCounter = 0;TimeCounter < Time;TimeCounter ++)
{
LCDDelayUs(255);
}
}
/***********************************************************
* 函數(shù)說明:LCD驅(qū)動指令周期延時函數(shù) *
* 輸入: 需要大體延時Us數(shù) *
* 輸出: 無 *
* 調(diào)用函數(shù):無 *
***********************************************************/
static void LCDDelayUs(unsigned int Time)
{
unsigned int TimeCounter = 0;
for (TimeCounter = 0;TimeCounter < Time;TimeCounter ++)
{
asm("nop");
}
}
/***********************************************************
* 函數(shù)說明:LCD初始化函數(shù) *
* 輸入: 無 *
* 輸出: 無 *
* 調(diào)用函數(shù):LCDDelay() LCDWaitForReady() *
* LCDSendCommand() *
***********************************************************/
void LCDInit(void)
{
LCDDelay(15);
#ifndef _LCD1602_FULL_DATA_MODEL
LCDSendCommand(0x28);
#else
LCDSendCommand(0x38);
#endif
LCDWaitForReady();
LCDSendCommand(LCD_CMD_DISP_CTR);
LCDWaitForReady();
LCDSendCommand(LCD_CMD_CLS);
LCDDelay(2);
LCDSendCommand(LCD_CMD_ENTER_SET);
LCDWaitForReady();
LCDSendCommand(LCD_CMD_NOT_MOVE);
}
#ifndef _Use_LCD1602B_Serial
/***********************************************************
* 函數(shù)說明:向LCD發(fā)送指令函數(shù) *
* 輸入: 需要發(fā)送的指令 *
* 輸出: 無 *
* 調(diào)用函數(shù):LCD_SEND_HALF_CHAR_HIGH() LCD_SEND_HALF_CHAR_LOW() *
***********************************************************/
void LCDSendCommand(char 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;
}
/***********************************************************
* 函數(shù)說明:向LCD發(fā)送數(shù)據(jù)函數(shù) *
* 輸入: 需要發(fā)送的數(shù)據(jù) *
* 輸出: 無 *
* 調(diào)用函數(shù):LCD_SEND_HALF_CHAR_HIGH() LCD_SEND_HALF_CHAR_LOW() *
***********************************************************/
void LCDSendData(char 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);
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -