EN BIT P3.0
RW BIT P3.1
RS BIT P3.2
DISPLAY EQU P0
SPEAKER BIT P1.0
LED BIT P1.2
OPEN BIT P1.1
RETURNBIT BIT 20H.1
PS1 EQU 46H
PS2 EQU 47H
PS3 EQU 48H
PS4 EQU 49H
PS5 EQU 4AH
PS6 EQU 4BH
AT1 EQU 34H
AT2 EQU 35H
AT3 EQU 36H
AT4 EQU 37H
AT5 EQU 38H
AT6 EQU 39H
SDA BIT P1.4
SCL BIT P1.3
ORG 0000H
LJMP START
ORG 000BH
LJMP INTERMIT_T0
ORG 001BH
LJMP INTERMIT_T1
ORG 0030H
START:
MOV SP,#60H
LCALL SYS_INITIALIZATION
MAIN0: LCALL STRAT_DISPLAY;
MAIN:
MOV 52H,#0
SETB LED
SETB TR0
LCALL KEY
CJNE A,#'A',NEXT1
LJMP SET_PASSWORD
NEXT1: CJNE A,#'B',NEXT2
LJMP INPUT_PASSWORD
NEXT2: AJMP MAIN
SYS_INITIALIZATION:
CLR LED
CLR OPEN
CLR SPEAKER
LCALL AT_RADE
AJMP LIKE
MOV 34H,#'1'
MOV 35H,#'2'
MOV 36H,#'3'
MOV 37H,#'4'
MOV 38H,#'5'
MOV 39H,#'6'
MOV 46H,34H
MOV 47H,35H
MOV 48H,36H
MOV 49H,37H
MOV 4AH,38H
MOV 4BH,39H
LCALL AT_WR
LIKE: MOV R7,#12
MOV R0,#40H
LOOP: MOV @R0,#00H
INC R0
DJNZ R7,LOOP
LCALL DELAY0_1S
MOV P0,#03H
CALL WRITE_INSTRUCTION
MOV P0,#01H
CALL WRITE_INSTRUCTION
MOV P0,#3FH
CALL WRITE_INSTRUCTION
MOV P0,#0FH
CALL WRITE_INSTRUCTION
MOV P0,#06H
CALL WRITE_INSTRUCTION
MOV R4,#10
MOV TMOD,#11H
MOV TH0,#3CH
MOV TL0,#0B0H
SETB EA
SETB ET0
RET
INTERMIT_T0:
PUSH ACC
PUSH PSW
MOV TH0,#3CH
MOV TL0,#0B0H
DJNZ R4,RETURN
CPL LED
MOV R4,#10
RETURN: POP PSW
POP ACC
RETI
INTERMIT_T1:
PUSH ACC
PUSH PSW
MOV TH1,#9EH
MOV TL1,#58H
DJNZ R4,RETURN_T1
CPL LED
CPL SPEAKER
MOV R4,#10
RETURN_T1:POP PSW
POP ACC
RETI
KEY: CALL KS
JNZ K1
JMP KEY
K1:
CALL DELAY
CALL KS
JNZ K2
JMP KEY
K2:
CLR TR0
CLR LED
MOV R2,#0FEH
MOV R6,#00H
K3: MOV A,R2
MOV P2,A
MOV A,P2
JB ACC.4,L1
MOV A,#0
LJMP LK
L1: JB ACC.5,L2
MOV A,#4
LJMP LK
L2: JB ACC.6,L3
MOV A,#8
LJMP LK
L3: JB ACC.7,NEXT_KEY
MOV A,#12
LK: ADD A,R6
MOV R6,A
K4: CALL KS
JNZ K4
MOV A,R6
MOV DPTR,#TABLE0
MOVC A,@A+DPTR
MOV 50H,A
RET
NEXT_KEY: INC R6
MOV A,R2
JNB ACC.7,KEY
RL A
MOV R2,A
JMP K3
KS: MOV P2,#0F0H
MOV A,P2
XRL A,#0F0H
RET
SET_PASSWORD:CALL CLEAR_DISPLAY
MOV DPTR,#TABLE4
CALL INPUT_HINT
MOV R0,#40H
CALL PASSWORD
JBC RETURNBIT,SET_PASSWORD
MOV R5,#6
MOV R0,#40H
MOV R1,#34H
INPUT_COMPERE: MOV A,@R0
XRL A,@R1
JNZ INPUT_ERROR
INC R0
INC R1
NOP
NOP
DJNZ R5,INPUT_COMPERE
JMP SET_PASSWORD0
INPUT_ERROR: SETB SPEAKER
SETB LED
CALL CLEAR_DISPLAY
MOV DPTR,#TABLE5
CALL INPUT_HINT
CALL DELAY1_5S
CLR SPEAKER
CLR LED
INC 52H
MOV A,52H
CJNE A,#3,SET_PASSWORD
SJMP $
SET_PASSWORD0: CALL CLEAR_DISPLAY
MOV DPTR,#TABLE2
CALL INPUT_HINT
MOV R0,#40H
CALL PASSWORD
JBC RETURNBIT,SET_PASSWORD
CALL CLEAR_DISPLAY
MOV DPTR,#TABLE3
CALL INPUT_HINT
CALL DELAY1_5S
CALL CLEAR_DISPLAY
MOV DPTR,#TABLE4
CALL INPUT_HINT
MOV R0,#46H
CALL PASSWORD
JBC RETURNBIT,SET_PASSWORD
MOV R5,#6
MOV R0,#40H
MOV R1,#46H
SET_COMPERE: MOV A,@R0
XRL A,@R1
JNZ SET_ERROR
INC R0
INC R1
DJNZ R5,SET_COMPERE
MOV 34H,40H
MOV 35H,41H
MOV 36H,42H
MOV 37H,43H
MOV 38H,44H
MOV 39H,45H
LCALL AT_WR
JMP MAIN0
SET_ERROR: SETB SPEAKER
SETB LED
CALL CLEAR_DISPLAY
MOV DPTR,#TABLE5
CALL INPUT_HINT
CALL DELAY1_5S
CLR SPEAKER
CLR LED
LJMP SET_PASSWORD0
INPUT_PASSWORD: CALL CLEAR_DISPLAY
MOV DPTR,#TABLE4
CALL INPUT_HINT
MOV R0,#40H
CALL PASSWORD
JBC RETURNBIT,INPUT_PASSWORD
MOV R5,#6
MOV R0,#40H
MOV R1,#34H
INPUT_COMPERE0:
MOV A,@R0
XRL A,@R1
JNZ INPUT_ERROR22
INC R0
INC R1
NOP
NOP
DJNZ R5,INPUT_COMPERE0
JMP DISPLAY_RIGHT
INPUT_ERROR22: SETB SPEAKER
SETB LED
CALL CLEAR_DISPLAY
MOV DPTR,#TABLE5
CALL INPUT_HINT
CALL DELAY1_5S
CLR SPEAKER
CLR LED
INC 52H
MOV A,52H
CJNE A,#3,INPUT_PASSWORD
SJMP $
DISPLAY_RIGHT: CALL CLEAR_DISPLAY
MOV DPTR,#TABLE6
CALL INPUT_HINT
SETB OPEN
NEXT_KEY1:CALL KEY
NOP
NOP
CJNE A,#'F',NEXT_KEY1
CLR OPEN
JMP MAIN0
STRAT_DISPLAY: MOV P0,#80H
CALL WRITE_INSTRUCTION
MOV DPTR,#TABLE1
CALL INPUT_HINT
MOV P0,#0C0H
CALL WRITE_INSTRUCTION
MOV DPTR,#TABLE11
CALL INPUT_HINT
RET
CLEAR_DISPLAY: MOV DISPLAY,#01H
CALL WRITE_INSTRUCTION
MOV P0,#06H
CALL WRITE_INSTRUCTION
RET
INPUT_HINT: MOV R5,#16
MOV A,#00H
ALL_OR_NOT: MOVC A,@A+DPTR
MOV DISPLAY,A
CALL WRITEDATA
INC DPTR
CLR A
NOP
NOP
DJNZ R5,ALL_OR_NOT
RET
PASSWORD: MOV R5,#6
MOV R1,#0C0H
MOV A,R1
MOV P0,A
CALL WRITE_INSTRUCTION
LOOP1: CALL KEY
NOP
NOP
CJNE A,#'C',NEXT_TO
SETB RETURNBIT
JMP ENDT
NEXT_TO: MOV A,50H
MOV @R0,A
MOV DISPLAY,A
CALL WRITEDATA
INC R1
INC R0
DJNZ R5,LOOP1
ENDT: RET
WRITEDATA: SETB RS
CLR RW
CLR EN
SETB EN
NOP
NOP
CLR EN
CALL DELAY
RET
WRITE_INSTRUCTION: CLR RS
CLR RW
CLR EN
SETB EN
NOP
NOP
CLR EN
CALL DELAY
RET
AT_RADE:PUSH PSW
PUSH ACC
MOV R0,#AT1
MOV R6,#06H
MOV R5,#08H
MOV R7,#00H
LCALL READ
NOP
NOP
POP ACC
POP PSW
RET
AT_WR: PUSH PSW
PUSH ACC
MOV R0,#PS1
MOV R6,#06H
MOV R5,#08H
MOV R7,#00H
LCALL WRT
NOP
NOP
POP ACC
POP PSW
RET
READ: NOP
NOP
LCALL START0
MOV A,#0A0H
LCALL WRB
LCALL CHK
JB F0,RD_FAIL
MOV A,R7
LCALL WRB
LCALL CHK
JB F0,RD_FAIL
LCALL START0
MOV A,#0A1H
LCALL WRB
LCALL CHK
JB F0,RD_FAIL
RD_N:
NOP
NOP
LCALL RDB
MOV @R0,A
DJNZ R6,GO_ACK
LCALL N_ACK
RD_FAIL:NOP
LCALL STOP
MOV A,#0FFH
RET
GO_ACK: NOP
NOP
INC R0
LCALL ACK
JMP RD_N
WRT: NOP
NOP
LCALL START0
MOV A,#0A0H
LCALL WRBYT
LCALL CHK
JB F0,WR_FAIL
MOV A,R7
LCALL WRBYT
LCALL CHK
JB F0,WR_FAIL
WR_N: NOP
NOP
MOV A,@R0
LCALL WRBYT
LCALL CHK
JB F0,WR_FAIL
INC R0
DJNZ R6,WR_N
WR_FAIL:NOP
LCALL STOP
MOV A,#0FFH
RET
START0: NOP
NOP
SETB SDA
SETB SCL
NOP
NOP
CLR SDA
NOP
NOP
CLR SCL
NOP
RET
STOP:
NOP
NOP
CLR SDA
SETB SCL
NOP
NOP
SETB SDA
NOP
NOP
CLR SCL
NOP
RET
ACK:
NOP
NOP
CLR SDA
SETB SCL
NOP
NOP
CLR SCL
SETB SDA
NOP
RET
N_ACK: NOP
NOP
SETB SDA
SETB SCL
NOP
NOP
CLR SCL
CLR SDA
NOP
RET
CHK: NOP
NOP
SETB SDA
NOP
NOP
SETB SCL
NOP
NOP
MOV C,SDA
MOV F0,C
CLR SCL
NOP
NOP
RET
RDBYT: MOV R5,#8
RLP:
SETB SDA
SETB SCL
MOV A,P1
JNB ACC.4,RD0
AJMP RD1
RLP1: DJNZ R5,RLP
RET
RD0: CLR C
MOV A,AT1
RLC A
MOV AT1,A
CLR P1.3
AJMP RLP1
RD1: SETB C
MOV A,AT1
RLC A
MOV AT1,A
CLR P1.3
AJMP RLP1
RET
RDB:
NOP
NOP
SETB SDA
MOV R5,#8
RD_B:
NOP
NOP
CLR SCL
NOP
NOP
SETB SCL
NOP
NOP
MOV C,SDA
RLC A
NOP
NOP
SETB SDA
CLR SCL
DJNZ R5,RD_B
NOP
RET
WRBYT: MOV R5,#8
WLP:
RLC A
JC WR1
CLR SDA
SETB SCL
NOP
NOP
CLR SCL
DJNZ R5,WLP
RET
WR1:
SETB SDA
SETB SCL
NOP
NOP
CLR SCL
CLR SDA
DJNZ R5,WLP
RET
WRB:
NOP
NOP
MOV R5,#8
WR_B:
NOP
NOP
SETB SDA
RLC A
JC WR_1
CLR SDA
NOP
WR_1:
SETB SCL
NOP
NOP
CLR SCL
NOP
CLR SDA
NOP
DJNZ R5,WR_B
NOP
RET
DELAY1_5S: PUSH 07H
PUSH 02H
PUSH 03H
MOV R7,#15
DEL22S: MOV R3,#0
DEL11S: MOV R2,#0
DJNZ R2,$
DJNZ R3,DEL11S
DJNZ R7,DEL22S
POP 03H
POP 02H
POP 07H
RET
DELAY0_1S: PUSH 02H
PUSH 03H
MOV R3,#0
DEL21S: MOV R2,#0
NOP
NOP
DJNZ R2,$
DJNZ R3,DEL21S
POP 03H
POP 02H
RET
DELAY: PUSH 07H
PUSH 06H
MOV R7,#10
D1: MOV R6,#248
NOP
NOP
DJNZ R6,$
DJNZ R7,D1
POP 06H
POP 07H
RET
TABLE0: DB 'C','B','0','A'
DB 'D','9','8','7'
DB 'E','6','5','4'
DB 'F','3','2','1'
TABLE1: DB 'PASSWORD: A SET '
TABLE11: DB ' B OPEN'
TABLE2: DB 'SET PASSWORD: '
TABLE3: DB 'INPUT AGAIN! '
TABLE4: DB 'INPUT PASSWROD: '
TABLE5: DB 'PASSWORD ERROR! '
TABLE6: DB 'PASSWORD OK!!! '
END
|