松翰單片機(jī)1602
//{{SONIX_CODE_OPTION
.Code_Option WDT_CLK Flosc/4
.Code_Option Reset_Pin P04
.Code_Option LVD LVD_Max ; 3.3V Reset
.Code_Option Watch_Dog Disable ;關(guān)閉看門(mén)狗
.Code_Option Low_Fcpu Flosc/1
.Code_Option High_Clk IHRC_16M ; Internal 16M RC Oscillator
.Code_Option High_Fcpu Fhosc/1
.Code_Option Security Enable
.Code_Option Noise_Filter Enable
//}}SONIX_CODE_OPTION
DATA EQU P4 ;數(shù)據(jù)口
DATAM EQU P4M
RS EQU P0.0 ;數(shù)據(jù)/命令
RSM EQU P0M.0
RW EQU P0.1 ;讀/寫(xiě)
RWM EQU P0M.1
E EQU P0.2 ;控制使能
EM EQU P0M.2
ORG 0000H
JMP A1
ORG 0015H
A1: MOV A,#30H;顯示內(nèi)容
MOV 41H,A
MOV A,#31H
MOV 42H,A
MOV A,#32H
MOV 43H,A
MOV A,#33H
MOV 44H,A
MOV A,#01H;清屏
MOV 30H,A
CALL ZL01
MOV A,#250
MOV 31H,A
A2:
MOV A,#38H;設(shè)置顯示模式5*7點(diǎn)
MOV 30H,A
CALL ZL01
DECMS 31H
JMP A2
MOV A,#0CH;開(kāi)顯示關(guān)光標(biāo)
MOV 30H,A
CALL ZL01
CALL XS01;顯示子程序
JMP $
;*************************************************
;顯示子程序
;*************************************************
XS01: MOV A,#38H;設(shè)置顯示模式
MOV 30H,A
CALL ZL01
MOV A,#0CH;開(kāi)顯示
MOV 30H,A
CALL ZL01
MOV A,#0C8H;顯示起始位置
MOV 30H,A
CALL ZL01
B0MOV H,#0 ; 清“H”以尋址RAM bank 0。
B0MOV L,#41H ; 設(shè)定寄存器地址。
XS02: MOV A,@HL;顯示內(nèi)容處理
MOV 30H,A
CALL SJ01
INCMS L;顯示下一數(shù)據(jù)
MOV A,L
CMPRS A,#45H;是否已顯示完成
JMP XS02
RET
;*****************************************
;寫(xiě)命令子程序
;*****************************************
ZL01: MOV A,#0FFH;設(shè)置數(shù)據(jù)口為輸出狀態(tài)
MOV DATAM,A
MOV DATA,A;輸出高電平
B0BSET RSM;設(shè)置為數(shù)據(jù)模式
B0BCLR RS
B0BSET RWM;設(shè)置為讀模式
B0BSET RW
B0BSET EM;允許操作
B0BSET E
ZL02:
B0BCLR P4M.7;忙檢
B0BTS0 P4.7;P4.7=1忙,P4.7=0空閑
JMP ZL02
B0BSET EM;關(guān)閉使能
B0BCLR E
B0BSET RSM;設(shè)置為命令模式
B0BCLR RS
B0BSET RWM;設(shè)置為寫(xiě)模式
B0BCLR RW
MOV A,#0FFH;將要寫(xiě)的內(nèi)容輸出到數(shù)據(jù)口
MOV DATAM,A
MOV A,30H
MOV DATA,A
B0BSET EM;允許使能操作
B0BSET E
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
B0BSET EM;關(guān)閉使能
B0BCLR E
RET
;*****************************************
;寫(xiě)數(shù)據(jù)子程序
;*****************************************
SJ01: MOV A,#0FFH
MOV DATAM,A
MOV DATA,A
B0BSET RSM
B0BCLR RS
B0BSET RWM
B0BSET RW
B0BSET EM
B0BSET E
SJ02:
B0BCLR P4M.7
B0BTS0 P4.7
JMP SJ02
B0BSET EM
B0BCLR E
B0BSET RSM;設(shè)置為數(shù)據(jù)模式
B0BSET RS
B0BSET RWM
B0BCLR RW
MOV A,#0FFH
MOV DATAM,A
MOV A,30H
MOV DATA,A
B0BSET EM
B0BSET E
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
B0BSET EM
B0BCLR E
RET
ENDP
評(píng)論