SDA BIT P1.0
SCL BIT P1.1
ORG 0000H
AJMP MAIN
ORG 0100H
MAIN:
ACALL RESTIC2
ACALL READ_SAFE
AJMP $
ACALL WRITE_SAFE
ACALL PASSWORLD
ACALL WRITE_SAFE2
ACALL READ_SAFE
ajmp $
ACALL NEWPASS ;修改密码子程序,可调用也可不调用
;AJMP $
ACALL WRITE
;ACALL NEWPASS ;修改密码子程序,可调用也可不调用
ACALL READ
AJMP $
WRITE: ;写数据子程序
ACALL START
MOV A,#38H
ACALL SHIFT
MOV A,#40H
ACALL SHIFT
MOV A,#0FH
ACALL SHIFT
ACALL STOP
ACALL DELLL
RET
SHIFT: ;输入移位子程序,
MOV R2,#8
CLR C ;清空C
CLR SCL ;拉低时钟线
SEND8:
RRC A ;左移A
MOV SDA,C ;将C送入数据线
NOP
NOP
NOP
SETB SCL ;拉高
NOP
NOP
NOP
NOP
CLR SCL ;拉低
DJNZ R2,SEND8 ;R2减一
RET
;DEL: ;本来想用于系统复位时,提供32个脉冲,可结果却不尽人意,用不了,以后再研究
;CLR SCL
;CLR SDA
;MOV R2,#32
;DEL2:
;SETB SCL
;NOP
;NOP
;NOP
;NOP
;CLR SCL
;NOP
;NOP
;NOP
;NOP
;DJNZ R2,DEL2
;RET
DELLL: ;提供255个50HZ的脉冲
CLR SCL
MOV R2,#5
DJNZ R2,$
CLR SDA
MOV R2,#5
DJNZ R2,$
MOV R2,#255
DELLL2:
SETB SCL
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
CLR SCL
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
;NOP
DJNZ R2,DELLL2
RET
READ: ;读主存储区子程序
ACALL START
MOV A,#30H
ACALL SHIFT
MOV A,#40H
ACALL SHIFT
MOV A,#0FFH
ACALL SHIFT
ACALL STOP
RERE: ;读取IO线数据子程序
CLR SCL
MOV R2,#8
ACALL READ2
RET
READ2:
SETB SCL
NOP
NOP
NOP
NOP
NOP
NOP
MOV C,SDA
RRC A
CLR SCL
NOP
NOP
NOP
NOP
NOP
NOP
DJNZ R2,READ2
MOV P2,A
RET
RESTIC2: ;系统复位子程序
CLR RST
CLR SCL
SETB SDA
MOV R2,#6
DJNZ R2,$
SETB RST
MOV R2,#6
DJNZ R2,$
SETB SCL
MOV R2,#6
DJNZ R2,$
CLR SCL
MOV R2,#6
DJNZ R2,$
CLR RST
ACALL RERE
ACALL RERE
ACALL RERE
ACALL RERE
MOV P2,#0FFH
RET
START: ;开总线
CLR SCL
CLR SDA
MOV R2,#2
DJNZ R2,$
SETB SCL
NOP
NOP
SETB SDA
NOP
NOP
CLR SDA
NOP
NOP
CLR SCL
RET
STOP: ;结束总线
CLR SDA
CLR SCL
MOV R2,#3
DJNZ R2,$
SETB SCL
NOP
NOP
NOP
NOP
SETB SDA
NOP
NOP
CLR SCL
RET
READ_SAFE: ;读密码,第一位为错误计数位,后面3个位密码保存位
ACALL START
MOV A,#31H
ACALL SHIFT
MOV A,#0FFH
ACALL SHIFT
MOV A,#0FFH
ACALL SHIFT
ACALL STOP
ACALL RERE
MOV R1,A
ACALL RERE
;MOV R1,A
ACALL RERE
ACALL RERE
MOV P2,R1;;;;;;;;;;;;;;;;;
RET
WRITE_SAFE:
ACALL START
MOV A,#39H
ACALL SHIFT
MOV A,#00H
ACALL SHIFT
MOV A,#06H ;输入06H,或04H或00H
ACALL SHIFT
ACALL STOP
ACALL DELLL
RET
PASSWORLD: ;输入并校验密码子程序
ACALL START
MOV A,#33H
ACALL SHIFT
MOV A,#01H
ACALL SHIFT
MOV A,#0FFH
ACALL SHIFT
ACALL STOP
ACALL DELLL
ACALL START
MOV A,#33H
ACALL SHIFT
MOV A,#02H
ACALL SHIFT
MOV A,#0FFH
ACALL SHIFT
ACALL STOP
ACALL DELLL
ACALL START
MOV A,#33H
ACALL SHIFT
MOV A,#03H
ACALL SHIFT
MOV A,#0FFH
ACALL SHIFT
ACALL STOP
ACALL DELLL
RET
WRITE_SAFE2:
ACALL START
MOV A,#39H
ACALL SHIFT
MOV A,#00H
ACALL SHIFT
MOV A,#0FFH
ACALL SHIFT
ACALL STOP
ACALL DELLL
RET
NEWPASS: ;更改密码子程序
ACALL START
MOV A,#39H
ACALL SHIFT
MOV A,#01H
ACALL SHIFT
MOV A,#55H
ACALL SHIFT
ACALL STOP
ACALL DELLL
ACALL START
MOV A,#39H
ACALL SHIFT
MOV A,#02H
ACALL SHIFT
MOV A,#55H
ACALL SHIFT
ACALL STOP
ACALL DELLL
ACALL START
MOV A,#39H
ACALL SHIFT
MOV A,#03H
ACALL SHIFT
MOV A,#55H
ACALL SHIFT
ACALL STOP
ACALL DELLL
RET