单片机驱动LCD源程序(128647);TEST TO 12864-7
;CONTROLLER: KS0108
;SIDE: 128 X 64 DOTS
;****************************************************************
;RS REG P3.0 ;DEFINE LCM DATA/INSTRUCTION PIN
;R/W REG P3.1 ;DEFINE LCM READ/WRITE PIN
;E REG P3.2 ;DEFINE LCM ENABLE PIN
;CS1 REG P3.3 ;DEFINE LCM CHIP 1 SELECT
;CS2 REG P3.4 ;DEFINE LCM CHIP 2 SELECT
;RSTB REG P3.5 ;DEFINE LCM RESET PIN
;DB0~DB7 REG P1.0~P1.7 ;DEFINE LCM DATA BUS
ORG 0000H
INIT: CLR P3.5 ;DISPLAY RESET
NOP
NOP
SETB P3.5
MOV P3,#038H ;ENBALE CHIP 1 AND CHIP 2
SETB P3.1 ;R/W=1
CLR P3.0 ;RS=0
INIT1: ORL P1,#0FFH ;P1 INKEYT MODE
SETB P3.2 ;E=1
MOV A,P1 ;READ BUSY SIGNAL
CLR P3.2 ;E=0
JB ACC.7,INIT1 ;BUSY END?
JB ACC.4,INIT1 ;RESET END?
MOV A,#0C0H ;DISPLAY START LINE
LCALL TRS0
MOV A,#03FH ;DISPLAY ON
LCALL TRS0
START:
LCALL CLEAR ;START TO TEST
LCALL ICON
LCALL KEY
LCALL TEST
LCALL BOX
LCALL KEY
JMP START
CLEAR: MOV P3,#038H ;CLEAR DISPLAY RAM
MOV R5,#0B8H
MOV A,#0C0H
LCALL TRS0
CLEAR2: MOV A,R5
LCALL TRS0
MOV A,#40H
LCALL TRS0
MOV R4,#40H
CLEAR1: MOV A,#00H
LCALL TRS1
DJNZ R4,CLEAR1
INC R5
CJNE R5,#0C0H,CLEAR2
RET
ICON: CLR P3.3 ;TEST ICON
SETB P3.4
MOV A,#0BFH
LCALL TRS0
MOV A,#07CH
LCALL TRS0
MOV R4,#04H
MOV A,#80H
ICON1: LCALL TRS1
DJNZ R4,ICON1
RET
TEST: MOV DPTR,#ADATA ;TEST 1
MOV 67H,DPH
MOV 68H,DPL
MOV R0,#07H
TEST5: MOV R5,#0B8H
MOV P3,#038H
TEST3: MOV A,R5
LCALL TRS0
MOV A,#40H
LCALL TRS0
MOV R4,#08H
TEST2: MOV DPH,67H
MOV DPL,68H
MOV R3,#08H
TEST1: MOV A,#00H
MOVC A,@A+DPTR
LCALL TRS1
INC DPTR
DJNZ R3,TEST1
DJNZ R4,TEST2
INC R5
CJNE R5,#0BFH,TEST3
SETB P3.3
CLR P3.4
MOV A,#0BFH
LCALL TRS0
MOV A,#40H
LCALL TRS0
LCALL TESTS
CLR P3.3
SETB P3.4
MOV A,#0BFH
LCALL TRS0
MOV A,#40H
LCALL TRS0
LCALL TESTT
SETB P3.3
SETB P3.4
LCALL KEY
CLR C
MOV A,68H
ADD A,#08H
MOV 68H,A
JNC TEST4
INC 67H
TEST4: DJNZ R0,TEST5
RET
TESTS: MOV R4,#08H ;SUB. OF TEST 1
TESTS2: MOV DPH,67H
MOV DPL,68H
MOV R3,#08H
TESTS1: MOV A,#00H
MOVC A,@A+DPTR
LCALL TRS1
INC DPTR
DJNZ R3,TESTS1
DJNZ R4,TESTS2
RET
TESTT: MOV R4,#07H ;SUB. OF TEST 1
TESTT2: MOV DPH,67H
MOV DPL,68H
MOV R3,#08H
TESTT1: MOV A,#00H
MOVC A,@A+DPTR
LCALL TRS1
INC DPTR
DJNZ R3,TESTT1
DJNZ R4,TESTT2
MOV DPH,67H
MOV DPL,68H
MOV R3,#04H
TESTT3: MOV A,#00H
MOVC A,@A+DPTR
LCALL TRS1
INC DPTR
DJNZ R3,TESTT3
MOV R3,#04H
TESTT4: MOV A,#00H
MOVC A,@A+DPTR
ANL A,#7FH
LCALL TRS1
INC DPTR
DJNZ R3,TESTT4
RET
BOX: LCALL CLEAR ;TEST 2
SETB P3.3
SETB P3.4
MOV A,#0B8H
LCALL TRS0
MOV A,#040H
LCALL TRS0
MOV R4,#40H
BOX1: MOV A,#01H
LCALL TRS1
DJNZ R4,BOX1
SETB P3.3
SETB P3.4
MOV A,#0BFH
LCALL TRS0
MOV A,#040H
LCALL TRS0
MOV R4,#40H
BOX2: MOV A,#80H
LCALL TRS1
DJNZ R4,BOX2
SETB P3.3
CLR P3.4
MOV R5,#0B8H
BOX3: MOV A,R5
LCALL TRS0
MOV A,#040H
LCALL TRS0
MOV A,#0FFH
LCALL TRS1
INC R5
CJNE R5,#0C0H,BOX3
CLR P3.3
SETB P3.4
MOV R5,#0B8H
BOX4: MOV A,R5
LCALL TRS0
MOV A,#7FH
LCALL TRS0
MOV A,#0FFH
LCALL TRS1
INC R5
CJNE R5,#0C0H,BOX4
CLR P3.3
SETB P3.4
MOV A,#0BFH
LCALL TRS0
MOV A,#7CH
LCALL TRS0
MOV R4,#03H
BOX5: MOV A,#00H
LCALL TRS1
DJNZ R4,BOX5
MOV A,#7FH
LCALL TRS1
RET
DELAY: MOV 40H,#1FH ;DELAY TIME
DELAY1: MOV 41H,#30H
DELAY2: DJNZ 41H,DELAY2
DJNZ 40H,DELAY1
RET
KEY: ORL P2,#0FFH ;SELECT KEY FOR TEST
KEY1: MOV C,P2.0
JC KEY1
CALL DELAY
CALL DELAY
MOV C,P2.0
JC KEY1
CALL DELAY
MOV R4,#20H
KEY2: CALL DELAY
DJNZ R4,KEY2
RET
TRS0: CALL BUSY ;SEND OUT INSTRUCTION
CLR P3.1
CLR P3.0
JMP WRITE
TRS1: CLR P3.1 ;SEND OUT DATA
SETB P3.0
WRITE: MOV P1,A
CLR P3.2
SETB P3.2
CLR P3.2
RET
BUSY: CLR P3.0 ;READ BUSY
SETB P3.1
SETB P3.2
MOV C,P1.7
CLR P3.2
JC BUSY
RET
TRS2: MOV P1,#0FFH
SETB P3.1
SETB P3.0 ;READ DATA
SETB P3.2
MOV A,P1
NOP
CLR P3.2
RET
ADATA:
DB 055H,055H,055H,055H,055H,055H,055H,055H
DB 0AAH,0AAH,0AAH,0AAH,0AAH,0AAH,0AAH,0AAH
DB 0FFH,000H,0FFH,000H,0FFH,000H,0FFH,000H
DB 000H,0FFH,000H,0FFH,000H,0FFH,000H,0FFH
DB 040H,03FH,015H,015H,07FH,000H,000H,000H
DB 000H,024H,02AH,07FH,02AH,012H,000H,000H
DB 000H,000H,032H,049H,079H,041H,03EH,000H
END ;END OF PROGRAM
文章评论(0条评论)
登录后参与讨论