?? rd_lcd1602b.h
字號:
/********************************************************
* 函數(shù)庫說明:LCD1602B基本驅(qū)動函數(shù)庫 *
* 版本: v1.7b *
* 作者: 傻孩子 *
* 日期: 2005年9月6日 *
* 修改: 傻孩子 *
* 修改日期: 2005年12月12日 *
* *
* 說明: *
* 1、需要底層硬件驅(qū)動函數(shù)支持 *
* 基本的宏定義: *
* LCD_RS LCD_RW LCD_E *
* LCD_SetWriteData LCD_SetReadData *
* LCD_HalfData_Port LCD_HalfData_DDR *
* LCD_SendHalfCharHigh(a) *
* LCD_SendHalfCharLow(a) *
* 2、自帶基本的延時函數(shù)。需要外部提供毫秒 *
* 單向增加的兩個計數(shù)器用于特效顯示: *
* FlashTimeCounter RunTimeCounter *
* 3、需要修改引用宏定義來指定底層硬件驅(qū)動 *
* 函數(shù)庫。 *
* 4、本庫驅(qū)動下的LCD顯示支持1602的各種連 *
* 接方法。當(dāng)使用只寫模式是請在引用該頭 *
* 文件之前加上宏定義: *
* # define _Use_LCDOnlyWrite *
* 5、在調(diào)用本庫之前,定義RunStringSpeed可 *
* 以設(shè)置滾屏的速度。通過在引用前定義 *
* FlashTimeOut 和 FlashGIFTimeOut 可以 *
* 改變字符閃爍的頻率。 *
* 6、增加一個GIF字幕特效函數(shù)。 *
* 7、確定沒有LCD復(fù)位問題。 *
********************************************************/
#ifndef _Use_LCD1602B
# define _Use_LCD1602B
/***********************
* 系 統(tǒng) 宏 定 義 *
***********************/
/*---------------------*
* 常 數(shù) 宏 定 義 *
*---------------------*/
#ifndef True
# define True 0x01
#endif
#ifndef False
# define False 0x00
#endif
#ifndef Enable
# define Enable 0x01
#endif
#ifndef Disable
# define Disable 0x00
#endif
#ifndef RunStringSpeed
# define RunStringSpeed 100
#endif
#ifndef FlashTimeOut
# define FlashTimeOut 500
#endif
#ifndef FlashGIFTimeOut
# define FlashGIFTimeOut 1000
#endif
# define LCD_Write 0x00
# define LCD_Read 0x01
# define LCD_Command 0x00
# define LCD_Data 0x01
# define LCD_CMD_Init 0x28
# define LCD_CMD_DispCtr 0x0c
# define LCD_CMD_CLS 0x01
# define LCD_CMD_EnterSet 0x06
# define LCD_CMD_IconShow 0x0f
# define LCD_CMD_IconHide 0x0c
# define LCD_CMD_NotMove 0b00010100
/*---------------------*
* 動 作 宏 定 義 *
*---------------------*/
# define SetReadState LCD_SetReadData;LCD_RS = LCD_Command;LCD_RW = LCD_Read;
# define SetRead LCD_SetReadData;LCD_RW = LCD_Read;
# define SetWrite LCD_SetWriteData;LCD_RW = LCD_Write;
# define SetCommand LCD_RS = LCD_Command;
# define SetData LCD_RS = LCD_Data;
# define Print(a) LCDDisplayString(a);
# define Locate(x,y) LCDSetXY(x-1,y-1);
# define CLS LCDWaitForReady();LCDSendCommand(LCD_CMD_CLS);
# define PrintN(a,b) LCDDisplayNum((unsigned long)a,b);
# define ShowIcon LCDWaitForReady();LCDSendCommand(LCD_CMD_IconShow);
# define HideIcon LCDWaitForReady();LCDSendCommand(LCD_CMD_IconHide);
/***********************
* 全局變量聲明區(qū) *
***********************/
const char CHR[16] = {'0','1','2','3','4','5','6','7','8'
,'9','a','b','c','d','e','f'};
extern unsigned int FlashTimeCounter;
extern unsigned int RunTimeCounter;
extern unsigned int FlashGIFStringCounter;
/***********************
* 系統(tǒng)函數(shù)聲明區(qū) *
***********************/
void LCDInit(void);
void LCDSendCommand(char Command);
void LCDSendData(char Data);
void LCDWaitForReady(void);
void LCDSetXY(char X,char Y);
void LCDDisplayString(char *String);
void LCDDisplayNum(unsigned long Num,char BitCount);
void LCDDelay(unsigned int Time);
void LCDDelayUs(unsigned int Time);
void RunString(char *String,char Direction,char Y,char StartX,char EndX);
void Flash(char *String,char Icon,char X,char Y);
char StringLength(char *String);
void FlashStringGroup(char String[][17],char StringCounter,char X,char Y);
/********************************************************
* 函數(shù)說明:LCD驅(qū)動類毫秒延時函數(shù) *
* 輸入: 需要延時的大體毫秒數(shù) *
********************************************************/
void LCDDelay(unsigned int Time)
{
unsigned int TimeCounter = 0;
for (TimeCounter = 0;TimeCounter < Time;TimeCounter ++)
{
LCDDelayUs(255);
}
}
/********************************************************
* 函數(shù)說明:LCD驅(qū)動指令周期延時函數(shù) *
* 輸入: 需要大體延時Us數(shù) *
********************************************************/
void LCDDelayUs(unsigned int Time)
{
unsigned int TimeCounter = 0;
for (TimeCounter = 0;TimeCounter < Time;TimeCounter ++)
{
asm("nop");
}
}
/********************************************************
* 函數(shù)說明:LCD初始化函數(shù) *
********************************************************/
void LCDInit(void)
{
LCDDelay(15);
LCDWaitForReady();
LCDSendCommand(LCD_CMD_Init);
LCDWaitForReady();
LCDSendCommand(LCD_CMD_DispCtr);
LCDWaitForReady();
LCDSendCommand(LCD_CMD_CLS);
LCDDelay(2);
LCDSendCommand(LCD_CMD_EnterSet);
}
/********************************************************
* 函數(shù)說明:向LCD發(fā)送指令函數(shù) *
* 輸入: 需要發(fā)送的指令 *
********************************************************/
void LCDSendCommand(char Command)
{
SetWrite;
SetCommand;
{
LCD_E = Enable;
LCD_SendHalfCharHigh(Command);
LCD_E = Disable;
}
{
LCD_E = Enable;
LCD_SendHalfCharLow(Command);
LCD_E = Disable;
}
SetRead;
SetCommand;
}
/********************************************************
* 函數(shù)說明:向LCD發(fā)送數(shù)據(jù)函數(shù) *
********************************************************/
void LCDSendData(char Data)
{
SetWrite;
SetData;
{
LCD_E = Enable;
LCD_SendHalfCharHigh(Data);
LCD_E = Disable;
}
{
LCD_E = Enable;
LCD_SendHalfCharLow(Data);
LCD_E = Disable;
}
SetRead;
SetCommand;
}
/********************************************************
* 函數(shù)說明:等待LCD空閑狀態(tài)函數(shù) *
********************************************************/
void LCDWaitForReady(void)
{
#ifdef _Use_LCDOnlyWrite
LCDDelayUs(30);
#else
SetRead;
SetCommand;
LCD_E = Enable;
while (LCD_BF == Enable); //RW=1,讀PD7,為0表示空閑;
LCD_E = Disable;
#endif
}
/********************************************************
* 函數(shù)說明:設(shè)置顯示坐標(biāo)函數(shù) *
********************************************************/
void LCDSetXY(char X,char Y)
{
char Address;
if (Y == 0)
{
Address = 0x80 + X;
}
else
{
Address = 0xc0 + X;
}
LCDWaitForReady();
LCDSendCommand(Address);
}
/********************************************************
* 函數(shù)說明:LCD字符串顯示函數(shù) *
********************************************************/
void LCDDisplayString(char *String)
{
while(*String)
{
LCDWaitForReady();
LCDSendData(*String);
String++;
}
}
/********************************************************
* 函數(shù)說明:數(shù)值顯示函數(shù)(HEX) *
* 輸入: 需要顯示的數(shù)字(無符號長整形) *
********************************************************/
void LCDDisplayNum(unsigned long Num,char BitCount)
{
char a = 0;
for (a = 8-BitCount ;a<8;a++)
{
LCDSendData(CHR[(Num<<(a<<2))>>28]);
}
}
/********************************************************
* 函數(shù)說明:滾屏字幕效果 *
* 輸入: 需要滾屏的字符串 長度 位置 *
********************************************************/
void RunString(char *String,char Direction,char Y,char StartX,char EndX)
{
static char StringHead = 0;
char SCREEN[17];
char a = 0;
char Point = StringHead;
char StringLong = StringLength(String);
static int RunTimeCounter = 0;
for (a = 0;a<EndX - StartX + 1;a++)
{
SCREEN[a] = String[Point];
Point ++;
if (Point == StringLong)
{
Point = 0;
}
}
for (;a < 17;a++)
{
SCREEN[a] =' ';
}
RunTimeCounter ++;
if (RunTimeCounter >RunStringSpeed)
{
StringHead ++;
RunTimeCounter = 0;
if (StringHead == StringLong)
{
StringHead = 0;
}
}
Locate(StartX,Y)
Print(SCREEN)
}
/********************************************************
* 函數(shù)說明:字符串長度測試函數(shù) *
********************************************************/
char StringLength(char *String)
{
char n = 0;
while (*String)
{
n++;
String ++;
}
return n;
}
/********************************************************
* 函數(shù)說明:閃爍顯示函數(shù) *
********************************************************/
void Flash(char *String,char Icon,char X,char Y)
{
char a = 0;
char StringLong = StringLength(String);
if (FlashTimeCounter % FlashTimeOut > (FlashTimeOut >> 1))
{
Locate(X,Y)
Print(String)
}
else
{
for (a = X ;a < X+StringLong;a++)
{
Locate(a,Y)
LCDWaitForReady();
LCDSendData(Icon);
}
}
}
/********************************************************
* 函數(shù)說明:字幕GIF函數(shù) *
********************************************************/
void FlashStringGroup(char String[][17],char StringCounter,char X,char Y)
{
static char Pictures = 0;
static char DispState = 0;
if (FlashGIFStringCounter % FlashGIFTimeOut > (FlashGIFTimeOut >> 1))
{
if (DispState == 0)
{
Pictures ++;
if (Pictures == StringCounter)
{
Pictures = 0;
}
DispState = 1;
}
}
else
{
if (DispState == 1)
{
Pictures ++;
if (Pictures == StringCounter)
{
Pictures = 0;
}
DispState = 0;
}
}
Locate(X,Y);
Print(String[Pictures]);
}
#endif
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -