;LCD部分用到的RAM0200H~~~~021FH用到的Rn有R15/R14
;LCD復(fù)位子程序(LCD_REST)不須要設(shè)事先置直接調(diào)用即可
;半屏顯示子程序(LCD)在調(diào)用前必須送入頁地址 例如:MOV.B #0B8H,LCD_PAGE_BRAM
;CALL#LCD顯示上屏
;:MOV.B #0BAH,LCD_PAGE_BRAM
;CALL#LCD顯示下屏
;LCDUP_WORD0_BRAM~~~LCDUP_WORD6_RAM是上屏顯示字的代碼寄存器一屏顯示7個字
;LCDDOWN_WORD0_BRAM~~~LCDDOWN_WORD6_RAM是下屏顯示字的代碼寄存器一屏顯示7個字
;每屏顯示是以中間為基準(zhǔn)向兩邊平均顯示在調(diào)用半屏顯示子程序時已經(jīng)自動計(jì)算LCD的列地址
;清屏指令可分全屏清除(LCD_CLEAR_ALL)和半屏清除(LCD_CLEAR)
;注 全屏清除子程序不需入口直接調(diào)用就行而半屏清除子程序在調(diào)用前入口與半屏顯示子程序相同
#i nclude“MSP430x14x.h”
NAME LCD
MODULE LCD
PUBLICLCD
RSEG PROM
;=========LCD==================================
;A0=1為數(shù)據(jù)A0=0為命令
#defineA004H
#defineE102H
#defineE201H
#defineBIT_OUTP4OUT
#defineDATA_BUSP2OUT
;=============LCD____8RAM的位定義===============
#defineLCD_COM_BRAM0200H
#defineLCD_DATA_BRAM0201H
#defineLCD_LIE_BRAM0202H
#defineLCD_PAGE_BRAM0203H
;=============LCD_UP_RAM============================
#defineLCDUP_WORD0_BRAM 0204H
#defineLCDUP_WORD1_BRAM 0205H
#defineLCDUP_WORD2_BRAM 0206H
#defineLCDUP_WORD3_BRAM 0207H
#defineLCDUP_WORD4_BRAM 0208H
#defineLCDUP_WORD5_BRAM 0209H
#defineLCDUP_WORD6_BRAM 020AH
;==========下面的RAM只是在測試狀態(tài)下才會用到=====
#defineLCDUP_WORD7_BRAM 020BH
;=============LCD_DOWN_RAM=====================
#defineLCDDOWN_WORD0_BRAM 020CH
#defineLCDDOWN_WORD1_BRAM 020DH
#defineLCDDOWN_WORD2_BRAM 020EH
#defineLCDDOWN_WORD3_BRAM 020FH
#defineLCDDOWN_WORD4_BRAM 0210H
#defineLCDDOWN_WORD5_BRAM 0211H
#defineLCDDOWN_WORD6_BRAM 0212H
;==========下面的RAM只是在測試狀態(tài)下才會用到=====
#defineLCDDOWN_WORD7_BRAM 0213H
;=============LCD_數(shù)據(jù)寄存器_RAM=================
#defineLCD_R0_BRAM0214H
#defineLCD_R1_BRAM0215H
;=============LCD____16RAM的位定義===============
#defineLCD_COUNT_WRAM021CH
#defineLCD_WORD_WRAM021EH
;=============LCD____BIT的位定義===============
#defineLCD_BIT_RAM0220H
#defineLCD_E1_E20000H
;是LCD左右屏選擇為BIT=1選通左邊BIT=0選通右邊
#defineLCD_INV02H
;高電平時顯示反白
;---------------------------------------------------
;===========================================================
LCD_E1_COM
BIC.B#A0,&BIT_OUT;A0置低 設(shè)為命令通道
MOV.BLCD_COM_BRAM,&LCD_BUS ;輸出命令
BIS.B#E1,&BIT_OUT ;開E1
BIC.B#E1,&BIT_OUT ;關(guān)E1
RET;反回
LCD_E2_COM
BIC.B#A0,&BIT_OUT ;A0置低 設(shè)為命令通道
MOV.BLCD_COM_BRAM,&LCD_BUS ;輸出命令
BIS.B#E2,&BIT_OUT ;開E2
BIC.B#E2,&BIT_OUT ;關(guān)E2
RET;反回
LCD_E1_DATA
BIS.B#A0,&BIT_OUT ;A0置高 設(shè)為命令通道
MOV.BLCD_DATA_BRAM,&LCD_BUS ;輸出命令
BIS.B#E1,&BIT_OUT ;開E1
BIC.B#E1,&BIT_OUT ;關(guān)E1
RET;反回
LCD_E2_DATA
BIS.B#A0,&BIT_OUT ;A0置高 設(shè)為數(shù)據(jù)通道
MOV.BLCD_DATA_BRAM,&LCD_BUS ;輸出命令
BIS.B#E2,&BIT_OUT ;開E2
BIC.B#E2,&BIT_OUT ;關(guān)E2
RET;反回
;================CLEAR_LCD_DISPALY==============
;每次直接調(diào)用程序就可以清全屏顯示 不須入口
LCD_CLEAR_ALL
CLRR15
CLRR14
LCD_CLEAR_ALL_1
BIS.B#0B8H,R15
MOV.BR15,LCD_COM_BRAM
CALL#LCD_E1_COM
CALL#LCD_E2_COM
MOV.B#00H,LCD_COM_BRAM
CALL#LCD_E1_COM
CALL#LCD_E2_COM
MOV.B#61D,R14
LCD_CLEAR_ALL_2
MOV.B#000H,LCD_DATA_BRAM
CALL#LCD_E1_DATA
CALL#LCD_E2_DATA
CLRZ
DEC.BR14
JNZLCD_CLEAR_ALL_2
INC.BR15
CLRZ
CMP.B#0BCH,R15
JNELCD_CLEAR_ALL_1
RET
;================CLEAR_LCD_DISPALY=============
;每次直接調(diào)用程序就可以清半屏顯示
;調(diào)用前必須送入頁地址到LCD_PAGE_RAM(頁地址寄存器)
;例如:MOV.B #0B8H,LCD_PAGE_BRAM
;:CALL #LCD_CLEAR 就是清上半屏顯示
;:MOV.B #0BAH,LCD_PAGE_BRAM
;:CALL #LCD_CLEAR 就是清下半屏顯示
LCD_CLEAR
CLRR15
MOV.BLCD_PAGE_BRAM,LCD_LIE_BRAM
ADD.B#2D,LCD_LIE_BRAM
LCD_CLEAR_1
BIS.BLCD_PAGE_BRAM,R15
MOV.BR15,LCD_COM_BRAM
CALL#LCD_E1_COM
CALL#LCD_E2_COM
MOV.B#00H,LCD_COM_BRAM
CALL#LCD_E1_COM
CALL#LCD_E2_COM
MOV#61D,R14
LCD_CLEAR_2
MOV.B#00H,LCD_DATA_BRAM
CALL#LCD_E1_DATA
CALL#LCD_E2_DATA
CLRZ
DEC.BR14
JNZLCD_CLEAR_2
INC.BR15
CLRZ
CMP.BLCD_LIE_BRAM,R15
JNZLCD_CLEAR_1
RET
;===============RESETTING_LCD_MODE=============
;調(diào)用此程序是使LCD復(fù)位并進(jìn)入工作狀態(tài)
LCD_REST
MOV.B#0E2H,LCD_COM_BRAM ;復(fù)位
CALL#LCD_E1_COM
CALL#LCD_E2_COM
MOV.B#0A4H,LCD_COM_BRAM ;關(guān)閉休閑狀態(tài)
CALL#LCD_E1_COM
CALL#LCD_E2_COM
MOV.B#0A9H,LCD_COM_BRAM ;設(shè)置1/32占空比
CALL#LCD_E1_COM
CALL#LCD_E2_COM
MOV.B#0A0H,LCD_COM_BRAM ;正向排序設(shè)置
CALL#LCD_E1_COM
CALL#LCD_E2_COM
MOV.B#0C0H,LCD_COM_BRAM ;設(shè)置顯示起始行為第一行
CALL#LCD_E1_COM
CALL#LCD_E2_COM
MOV.B#0AFH,LCD_COM_BRAM ;開顯示設(shè)置
CALL#LCD_E1_COM
CALL#LCD_E2_COM
RET
;查LCD PAGE #0B8H.#0B9H/#0BAH.#0BBH上屏須要顯示的個數(shù)
;這段程序已測試過03-3-12 9:55
;R15/R14/R13
LCD_CHK
CLRLCD_COUNT_RAM
MOV.B#8,LCD_R0_RAM;查殉上屏須要顯示的個數(shù),一屏最多可以顯示7個16X16
CLR.BLCD_LIE_BRAM;清上屏查殉結(jié)果寄存器
MOVLCD_WORD_RAM,R14 ;把須要檢查字的首位16位地址放進(jìn)R14.LCD_WORD_RAM
;定義時必須是16位地址
LCD_CHK_0
DEC.BLCD_R0_RAM
JZLCD_CHK_1;測試完成退出
CLRZ
MOV.B@R14+,LCD_COUNT_RAM
TST.BLCD_COUNT_RAM;測試每個字寄存器是否為零
JZLCD_CHK_0;為零時轉(zhuǎn)
INC.BLCD_LIE_BRAM;大于零查殉結(jié)果寄存器加一
JMPLCD_CHK_0;反回測試
LCD_CHK_1
CLRLCD_COUNT_RAM
MOV.BLCD_LIE_BRAM,LCD_COUNT_RAM
MOVLCD_COUNT_RAM,&MPY ;把檢測的結(jié)果乘以16
MOV#16D,&OP2
MOV&RESLO,LCD_COUNT_RAM ;相乘的結(jié)果放回寄存器
MOV.BLCD_COUNT_RAM,LCD_LIE_BRAM
RRA.BLCD_LIE_BRAM;結(jié)果除2.放到上屏頁的寄存器
MOV.B#61D,LCD_COUNT_RAM
SUB.BLCD_LIE_BRAM,LCD_COUNT_RAM
MOV.BLCD_COUNT_RAM,LCD_LIE_BRAM
RET
;調(diào)用前必須把要顯示屏第一個字的地址放在R15內(nèi)
;列:MOV#LCDUP_WORD0_BRAM,LCD_WORD_RAM
;MOV#LCDDOWN_WORD0_BRAM,LCD_WORD_RAM
;用到的寄存器R15/R14
LCD
CLRZ
CMP.B#0B8H,LCD_PAGE_BRAM
JNELCD_1
MOV#LCDUP_WORD0_BRAM,LCD_WORD_RAM
JMPLCD_0
LCD_1 MOV#LCDDOWN_WORD0_BRAM,LCD_WORD_RAM
LCD_0 CALL#LCD_CHK
BIS.B#BIT0,LCD_BIT_RAM
MOV.B#7D,LCD_R1_RAM
;每次調(diào)用均連續(xù)顯示7個16X16的字而遇到字寄存器是
MOVLCD_WORD_RAM,R15 ;零就反回因?yàn)樽直砝锩媸菦]有零的
LCD_DISPALY
CLRR14
MOV.B@R15+,R14
TSTR14;R15是顯示字首位地址寄存器,準(zhǔn)備用于間接尋址
JZLCD_RET;字寄存器是零就反回
MOV#32D,&MPY;查表然后吧結(jié)果送到寄存器
MOVR14,&OP2
MOV&RESLO,LCD_COUNT_RAM
ADD#LCD_DB,LCD_COUNT_RAM
MOVLCD_COUNT_RAM,R14
MOV.B#32D,LCD_R0_RAM;R14用于放計(jì)算查找數(shù)據(jù)的個數(shù)
LCD_PAGE
MOV.BLCD_PAGE_BRAM,LCD_COM_BRAM;把頁地址送到命令寄存器
CLRZ
BIT.B#BIT0,LCD_BIT_RAM
;LCD_BIT_RAM的BIT0=LCD_E1_E2為高時轉(zhuǎn)到E1發(fā)送,第就是E2
JZLCD_PAGE_E2;Z為零就轉(zhuǎn)到E2否則向下工作
LCD_PAGE_E1
CALL#LCD_E1_COM;向E1發(fā)送頁地址
JMPLCD_LIE;跳去列發(fā)送
LCD_PAGE_E2
CALL#LCD_E2_COM;向E2發(fā)送頁地址
LCD_LIE
MOV.BLCD_LIE_BRAM,LCD_COM_BRAM;把列地址送到命令寄存器
CLRZ
BIT.B#BIT0,LCD_BIT_RAM
;LCD_BIT_RAM為高時轉(zhuǎn)到E1發(fā)送,第就是E2
JZLCD_LIE_E2;Z為零就轉(zhuǎn)到E2否則向下工作
LCD_LIE_E1
CALL#LCD_E1_COM;向E1發(fā)送列地址
JMPLCD_DATA
LCD_LIE_E2
CALL#LCD_E2_COM;向E2發(fā)送列地址
LCD_DATA
CALL#LCD_FIND_DATA;調(diào)用數(shù)據(jù)發(fā)送命令
CLRZ
BIT.B#BIT0,LCD_PAGE_BRAM ;測試頁寄存器的BIT0位
JNZLCD_PAGE_0;大于零(即是BIT0=1)就轉(zhuǎn)
BIS.B#BIT0,LCD_PAGE_BRAM ;把頁寄存器的BIT0位置高(原來是低#0B8H/#0BAH)
JMPLCD_RETURN
LCD_PAGE_0
BIC.B#BIT0,LCD_PAGE_BRAM ;把頁寄存器的BIT0位置低(原來是高#0B9H/#0BBH)
INC.BLCD_LIE_BRAM;列地址加一
CLRZ
CMP.B#61D,LCD_LIE_BRAM;檢查列有沒有超過61列
JNZLCD_RETURN;Z大于零就轉(zhuǎn)等于零就向下工作
CLR.BLCD_LIE_BRAM;清列寄存器
CLRZ
BIT.B#BIT0,LCD_BIT_RAM ;測試LCD_BIT_RAM位在E1就轉(zhuǎn)為E2 在E2就立即反回
JNZLCD_PAGE_1;Z為零就轉(zhuǎn)到E2否則向下工作
JMPLCD_RET;轉(zhuǎn)到子程序反回命令
LCD_PAGE_1
BIC.B#BIT0,LCD_BIT_RAM ;把LCD_BIT_RAM位置低設(shè)為E2顯示狀態(tài)
JMPLCD_PAGE;反回頁傳送命令地址
LCD_RETURN
CLRZ
DEC.BLCD_R0_RAM;查找數(shù)據(jù)的個數(shù)寄存器減1
JNZLCD_PAGE;R14大于零轉(zhuǎn)回頁傳送命令地址
CLRZ
DEC.BLCD_R1_RAM;字個數(shù)寄存器減1
BIC.B#BIT0,LCD_PAGE_BRAM
JNZLCD_DISPALY;反回主顯示調(diào)用程序
LCD_RET
RET;反回主程序
;===================================================
LCD_FIND_DATA
MOV.B@R14+,LCD_DATA_BRAM
CLRZ
BIT.B#INV_BIT,LCD_BIT_RAM
JZNO_INV
INV.BLCD_DATA_BRAM
NO_INV CLRZ
BIT.B#BIT0,LCD_BIT_RAM ;測試LCD_BIT_RAM位在E1就轉(zhuǎn)為E2 在E2就立即反回
JZLCD_FIND_E2;Z為零就轉(zhuǎn)到E2否則向下工作
CALL#LCD_E1_DATA;調(diào)用E1數(shù)據(jù)發(fā)送子程序
JMPLCD_FIND_DATA_RET
LCD_FIND_E2
CALL#LCD_E2_DATA;調(diào)用E2數(shù)據(jù)發(fā)送子程序
LCD_FIND_DATA_RET
RET
END LCD
評論
查看更多