- RS BIT P3.5 ;定义RS为P2.0
- RW BIT P3.6 ;定义RW为P2.1
- E BIT P3.7 ;定义E为P2.2
- ORG 0000H
- SJMP START
- ORG 0030H
- START:
- MOV 70H,#06H
- MOV 71H,#0C0H
- MOV 72H,#80H
- MOV 75H,#06H
- LCALL LCDINIT
- MAIN: MOV 68H,#03H
- MOV 55H,#01H
- MOV 61H,#00H
- MOV A,#01H ;清屏
- MOV R1,#00H
- LCALL BUSY
- LCALL WRTC
- LCALL MINGXIAN
- MOV R3, #0C0H
- MOV SP,#40H
- MOV 57H,#00H
- MAIN1:
- CHU:MOV A, P1
- CJNE A,#0FFH,SB
- LJMP CHU
- SB: MOV 34H, A
- MOV DPTR ,#KEYTAB
- MOV R4,#0FFH
- LP:INC R4
- CLR A
- MOVC A,@A+DPTR
- INC DPTR
- CJNE A ,34H,LP
- KDL:MOV A,P1
- CJNE A,#0FFH,KDL
- INC R4
- MOV 35H,R4
- MOV A,35H
- MOV DPTR,#KEYTAB1
- ADCA:MOV R1,#00H
- MOV A,R1
- MOVC A,@A+DPTR
- INC DPTR
- DJNZ R4,ADCA
- MOV 35H,A
- MOV A,R3 ;显示开及光标设置
- LCALL BUSY
- LCALL WRTC
- MOV A,35H
- CJNE A,#41H,XHSR
- LJMP STOP
- XHSR:SETB RS
- CLR RW
- CLR E
- MOV P2,A
- SETB E
- CLR E
- CLR E
- INC R3
- PUSH ACC
- INC 57H
- LJMP MAIN1
- STOP:SJMP ZZA
- ZZA:
- MOV A,70H
- CJNE A,75H,JKL
- LCALL LCDINIT
- JKL:
- MOV R3,#80H
- MOV 66H,68H
- MOV 61H,#0FH
- MAIN2:
- MOV A,P1
- CJNE A,#0E7H,QWER
- ASD:MOV A,P1
- CJNE A,#0FFH,ASD
- LCALL ASDF
-
- QWER: MOV A,72H ;显示开及光标设置
- LCALL BUSY
- LCALL WRTC
- MOV R2,#0FH
- LCALL XUANZHE
- LCALL DELAY
- LCALL WRTD
- MOV A,66H
- CJNE A,#01H,OP9
- SJMP OP8
- OP9:
- LCALL XUEHAO
- MOV 67H,68H
- ;********设置程序*******;
- OP8:
- MOV A,P1
- CJNE A,#0EBH,TYU1
- RTY:
- MOV A,P1
- CJNE A,#0FFH,RTY
- LCALL BNM
- MOV 55H,R4
- TYU1:
- MOV A,P1
- CJNE A,#77H,TYU3
- RTY5:MOV A,P1
- CJNE A,#0FFH,RTY5
- LCALL BNM
- MOV 68H,R4
-
- TYU3:MOV R6,55H
- TYU: LCALL DELAY
- DJNZ R6,TYU
- INC R3
- DEC 61H
-
- ;********数字**********
- DJNZ 66H,RFV
- LCALL SHANSUO
- MOV 66H,#01H
- DJNZ 67H,RFV
- MOV 66H,68H
-
- RFV:CJNE R3,#0A1H,MAIN2
- LJMP ZZA
- ;***************初始化*****************
- LCDINIT:
- LCALL DELAY ;延时15ms
- LCALL DELAY
- LCALL DELAY
- MOV A,#38H ;显示模式设置(8位数据线,16*2 5*7点阵)
- LCALL WRTC
- LCALL DELAY ;延时5ms
- MOV A,#38H
- LCALL WRTC
- LCALL DELAY ;延时5ms
- MOV A,#38H
- LCALL WRTC
- LCALL DELAY ;延时5ms
- MOV A,#38H
- LCALL BUSY
- LCALL WRTC
- MOV A,#08H
- LCALL BUSY
- LCALL WRTC
- MOV A,#01H ;清屏
- LCALL BUSY
- LCALL WRTC
- MOV A,70H ;显示光标移动设置
- LCALL BUSY
- LCALL WRTC
- MOV A,#0CH ;示开关控制,显示开,无光标,不闪烁。
- LCALL BUSY
- LCALL WRTC
- MOV A,#40H ;写CGRAM地址.
- LCALL BUSY
- LCALL WRTC
- MOV A ,75H
- CJNE A,#06H,IOO
- MOV 75H,#04H
- SJMP IOOP
- IOO:MOV 75H,#06H
- IOOP:RET
- ;***************写命令子程序*****************
- WRTC:
- CLR RS
- CLR RW
- CLR E
- MOV P2,A
- SETB E
- CLR E
- RET
- ;*****************写数据子程序***************
- WRTD: MOV R1,61H
- AGAIN: MOV A,R1
- MOVC A,@A+DPTR
- SETB RS
- CLR RW
- CLR E
- MOV P2,A
- SETB E
- CLR E
- INC R1
- MOV A,R1
- MOV B,R2 ; 数据写完没有.
- CJNE A,B,AGAIN
- RET
-
- ;*****************判忙子程序******************
- BUSY:
- MOV 50H,A
- CLR RS
- SETB RW
- TT0: SETB E
- MOV A,P2
- CLR E
- ANL A,#80H
- JNZ TT0
- MOV A,50H
- RET
- ;***************************************************
- SHANSUO:
-
- MOV A,71H ;显示开及光标设置
- LCALL BUSY
- LCALL WRTC
- MOV R2,#0FH
- MOV DPTR,#TAB
-
- LCALL DELAY
- MOV R1,#00H
- MOV A,R1
- MOVC A,@A+DPTR
- SETB RS
- CLR RW
- CLR E
- MOV P2,A
- SETB E
- CLR E
- INC R1
- MOV A,R1
- MOV B,R2 ; 数据写完没有.
- CJNE A,B,AGAIN
- RET
- ;*************************************************
- ASDF:
- MOV A,P1
- CJNE A,#0FFH,ASDF1
- SJMP ASDF
- ASDF1:
- CJNE A,#0D7H,ZX
-
- MOV 70H,#04H
- MOV 71H,#0CFH
- MOV 72H,#8FH
- SJMP ZX1
- ZX:
- MOV 70H,#06H
- MOV 71H,#0C0H
- MOV 72H,#80H
-
- ZX1:LJMP ZZA
-
- ;********************************************
- BNM: MOV A ,P1
- CJNE A,#0FFH,BNM1
- SJMP BNM
- BNM1:
- MOV 34H, A
- MOV DPTR ,#KEYTAB
- MOV R4,#0FFH
- LP5:INC R4
- CLR A
- MOVC A,@A+DPTR
- INC DPTR
- CJNE A ,34H,LP5
- KDL1:MOV A,P1
- CJNE A,#0FFH,KDL1
- INC R4
- RET
- ;*************************************************
- MINGXIAN:
- MOV A,#80H ;显示开及光标设置
- LCALL BUSY
- LCALL WRTC
- MOV R2,#0DH
- MOV DPTR,#TAB4
- LCALL DELAY
- FGHJ: MOV A,R1
- MOVC A,@A+DPTR
- SETB RS
- CLR RW
- CLR E
- MOV P2,A
- SETB E
- CLR E
- INC R1
- MOV A,R1
- MOV B,R2 ; 数据写完没有.
- CJNE A,B,FGHJ
- RET
- ;*********延时******* *************************
- DELAY: MOV R5,#10
- D1: MOV R7,#250
- DJNZ R7,$
- DJNZ R5,D1
- RET
- ;*********************************
- XUEHAO:
- MOV A,71H ;显示开及光标设置
- LCALL BUSY
- LCALL WRTC
- MOV 59H,57H
- MOV R1,#41H
- LCALL QAZ
- OP5:
- MOV A,@R1
- SETB RS
- CLR RW
- CLR E
- MOV P2,A
- SETB E
- CLR E
- MOV A,70H
- CJNE A,#04H,WSX
- DEC R1
- SJMP WSX1
- WSX:INC R1
-
- WSX1:DJNZ 59H,OP5
- RET
- ;*********************************************************
- XUANZHE:
- MOV A,70H
- CJNE A,#04H,CVB
- MOV DPTR,#TAB6
- SJMP VB
- CVB:MOV DPTR,#TAB5
- VB:RET
- ;***********************************************************
- KEYTAB:
- DB 7EH,0BEH,0DEH,0EEH
- DB 7DH,0BDH,0DDH,0EDH
- DB 7BH,0BBH,0DBH,0EBH
- DB 77H,0B7H,0D7H,0E7H
- KEYTAB1:
- DB 30H,31H,32H,33H
- DB 34H,35H,36H,37H
- DB 38H,39H,41H,42H
- DB 43H,44,45H ,46H
- TAB6:
- DB " GNIP GNEHC IL "
- TAB5: DB " LI CHENG PING "
- TAB: DB " "
-
- TAB4: DB "LI CHENG PING"
- ;*********************************** *****************
- QAZ:
- MOV A,70H
- CJNE A,#04H,QAZ1
- MOV A,57H
- ADD A,#40H
- MOV R1,A
- QAZ1:RET
- ;*********************************
- END
- *
复制代码 |