?? rd_lcd1602b.s
字號:
.module RD_LCD1602B.c
.area text(rom, con, rel)
.dbfile O:\2007全國電子設計大賽\鍵盤顯示模塊\RD_LCD1602B.c
.area lit(rom, con, rel)
_CHR:
.byte 48,49
.byte 50,51
.byte 52,53
.byte 54,55
.byte 56,57
.byte 'a,'b
.byte 'c,'d
.byte 'e,'f
.area data(ram, con, rel)
.dbfile O:\2007全國電子設計大賽\鍵盤顯示模塊\RD_LCD1602B.c
_LCD_Temp:
.blkb 1
.area idata
.byte 0
.area data(ram, con, rel)
.dbfile O:\2007全國電子設計大賽\鍵盤顯示模塊\RD_LCD1602B.c
.area text(rom, con, rel)
.dbfile O:\2007全國電子設計大賽\鍵盤顯示模塊\RD_LCD1602B.c
.dbfunc s LCDDelay _LCDDelay fV
; TimeCounter1 -> R20,R21
; Time -> R10,R11
.even
_LCDDelay:
xcall push_xgset300C
movw R10,R16
.dbline -1
.dbline 189
; /***********************************************************
; * 函數庫說明: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
;
; /*------------------*
; * 動 作 宏 定 義 *
; *------------------*/
; #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
; /********************
; * 用戶變量類型定義 *
; ********************/
;
; /********************
; * 模塊結構體定義區 *
; ********************/
;
; /********************
; * 模塊函數聲明區 *
; ********************/
; static void LCDDelay(unsigned int Time);
; static void LCDDelayUs(unsigned int Time);
;
;
; /********************
; * 全局函數聲明區 *
; ********************/
; 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);
;
; /********************
; * 全局函數引用區 *
; ********************/
; #ifdef _Use_LCD1602B_Serial
; extern void refreshVirtualPORT(void);
; #endif
;
; /********************
; * 模塊變量聲明區 *
; ********************/
; const static char CHR[16] = {'0','1','2','3','4','5','6','7','8'
; ,'9','a','b','c','d','e','f'};
;
; /********************
; * 全局變量聲明區 *
; ********************/
; static char LCD_Temp = 0;
;
; /********************
; * 全局變量引用區 *
; ********************/
; #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
;
;
;
; /***********************************************************
; * 函數說明:LCD驅動類毫秒延時函數 *
; * 輸入: 需要延時的大體毫秒數 *
; * 輸出: 無 *
; * 調用函數:LCDDelayUs() *
; ***********************************************************/
; static void LCDDelay(unsigned int Time)
; {
.dbline 190
; unsigned int TimeCounter = 0;
.dbline 192
;
; for (TimeCounter = 0;TimeCounter < Time;TimeCounter ++)
clr R20
clr R21
xjmp L5
L2:
.dbline 193
; {
.dbline 194
; LCDDelayUs(255);
ldi R16,255
ldi R17,0
xcall _LCDDelayUs
.dbline 195
; }
L3:
.dbline 192
subi R20,255 ; offset = 1
sbci R21,255
L5:
.dbline 192
cp R20,R10
cpc R21,R11
brlo L2
X0:
.dbline -2
L1:
.dbline 0 ; func end
xjmp pop_xgset300C
.dbsym r TimeCounter1 20 i
.dbsym r Time 10 i
.dbend
.dbfunc s LCDDelayUs _LCDDelayUs fV
; TimeCounter1 -> R20,R21
; Time -> R16,R17
.even
_LCDDelayUs:
st -y,R20
st -y,R21
.dbline -1
.dbline 205
; }
;
; /***********************************************************
; * 函數說明:LCD驅動指令周期延時函數 *
; * 輸入: 需要大體延時Us數 *
; * 輸出: 無 *
; * 調用函數:無 *
; ***********************************************************/
; static void LCDDelayUs(unsigned int Time)
; {
.dbline 206
; unsigned int TimeCounter = 0;
.dbline 207
; for (TimeCounter = 0;TimeCounter < Time;TimeCounter ++)
clr R20
clr R21
xjmp L10
L7:
.dbline 208
; {
.dbline 209
; asm("nop");
nop
.dbline 210
; }
L8:
.dbline 207
subi R20,255 ; offset = 1
sbci R21,255
L10:
.dbline 207
cp R20,R16
cpc R21,R17
brlo L7
X1:
.dbline -2
L6:
.dbline 0 ; func end
ld R21,y+
ld R20,y+
ret
.dbsym r TimeCounter1 20 i
.dbsym r Time 16 i
.dbend
.dbfunc e LCDInit _LCDInit fV
.even
_LCDInit::
.dbline -1
.dbline 221
; }
;
; /***********************************************************
; * 函數說明:LCD初始化函數 *
; * 輸入: 無 *
; * 輸出: 無 *
; * 調用函數:LCDDelay() LCDWaitForReady() *
; * LCDSendCommand() *
; ***********************************************************/
; void LCDInit(void)
; {
.dbline 222
; LCDDelay(15);
ldi R16,15
ldi R17,0
xcall _LCDDelay
.dbline 227
;
; #ifndef _LCD1602_FULL_DATA_MODEL
; LCDSendCommand(0x28);
; #else
; LCDSendCommand(0x38);
ldi R16,56
xcall _LCDSendCommand
.dbline 229
; #endif
; LCDWaitForReady();
xcall _LCDWaitForReady
.dbline 230
; LCDSendCommand(LCD_CMD_DISP_CTR);
ldi R16,12
xcall _LCDSendCommand
.dbline 231
; LCDWaitForReady();
xcall _LCDWaitForReady
.dbline 232
; LCDSendCommand(LCD_CMD_CLS);
ldi R16,1
xcall _LCDSendCommand
.dbline 233
; LCDDelay(2);
ldi R16,2
ldi R17,0
xcall _LCDDelay
.dbline 234
; LCDSendCommand(LCD_CMD_ENTER_SET);
ldi R16,2
xcall _LCDSendCommand
.dbline 235
; LCDWaitForReady();
xcall _LCDWaitForReady
.dbline 236
; LCDSendCommand(LCD_CMD_NOT_MOVE);
ldi R16,20
xcall _LCDSendCommand
.dbline -2
L11:
.dbline 0 ; func end
ret
.dbend
.dbfunc e LCDSendCommand _LCDSendCommand fV
; Command -> R16
.even
_LCDSendCommand::
.dbline -1
.dbline 248
;
; }
;
; #ifndef _Use_LCD1602B_Serial
; /***********************************************************
; * 函數說明:向LCD發送指令函數 *
; * 輸入: 需要發送的指令 *
; * 輸出: 無 *
; * 調用函數:LCD_SEND_HALF_CHAR_HIGH() LCD_SEND_HALF_CHAR_LOW() *
; ***********************************************************/
; void LCDSendCommand(char Command)
; {
.dbline 249
; SetWrite;
ldi R24,255
out 0x1a,R24
.dbline 249
.dbline 249
in R24,0x18
andi R24,253
out 0x18,R24
.dbline 249
.dbline 250
; SetCommand;
in R24,0x18
andi R24,254
out 0x18,R24
.dbline 250
.dbline 263
; #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;
out 0x1b,R16
.dbline 264
; LCD_E = HIGH;
in R24,0x18
ori R24,4
out 0x18,R24
.dbline 265
; LCD_E = LOW;
in R24,0x18
andi R24,251
out 0x18,R24
.dbline 267
; #endif
; SetRead;
clr R2
out 0x1a,R2
.dbline 267
ldi R24,255
out 0x1b,R24
.dbline 267
.dbline 267
in R24,0x18
ori R24,2
out 0x18,R24
.dbline 267
.dbline 268
; SetCommand;
in R24,0x18
andi R24,254
out 0x18,R24
.dbline 268
.dbline -2
L12:
.dbline 0 ; func end
ret
.dbsym r Command 16 c
.dbend
.dbfunc e LCDSendData _LCDSendData fV
; Data -> R16
.even
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -