|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
我早年设计的一个红外密码锁,适用于红外芯片为sc5104.
源程序如下:
;this program is more exacte,uarrary can't be affected by other
;remoter.
;this program is finished on 2003-9-18,use 93c46 to save the code
temph equ 30h
templ equ 31h
intcount equ 33h
daima equ 34h
secondkeyflag bit 20h.0
keyerrorflag bit 20h.1
yindaflag equ 20h.2
secondkey equ 20h.3
kaisuo equ p3.0
read equ 0
write equ 2
ewen equ 4
ewds equ 6
cs bit p3.2
clk bit p3.3
di bit p3.4
do bit p3.5
adr46 equ 32h
addressh equ 35h
addressl equ 36h
panshunum equ 37h
highcount equ 38h
key equ 39h
keynum equ 3ah
errornum equ 3bh
tensecond equ 3ch
sound equ p3.1
keyaddress equ 60h
mimaaddress equ 68h
org 00h
ljmp start
org 0003h
reti
org 001bh
ljmp timer1int
org 0040h
start:
mov p1,#00h
setb kaisuo
mov p3,#10100000b
mov tmod,#11h
mov errornum,#00H
mov keynum ,#00h
mov tensecond,#00h
mov 20h,#00h
clr secondkeyflag
clr secondkey
setb et1
setb ea
lcall read9346
mov p1,#0efh
lcall sounddelay
start1: ;yi ge key de kaishi
mov highcount,#00h
mov addressh,#40h
mov addressl,#50h
mov highcount,#00h
mov panshunum,#00h
mov intcount,#00h
mov a,addressl
mov r0,a
mov a,#00h
mov r1,#12
clear1:
mov @r0,a
inc r0
djnz r1,clear1
mov a,addressh
mov r0,A
mov a,#00h
mov r1,#12
clear2:
mov @r0,a
inc r0
djnz r1,clear2
begin:
jb p3.7,$
highbegin:
jnb p3.7,$
levelhigh:
setb tr0
jb p3.7,levelhigh
clr tr0
mov temph,th0
mov templ,tl0
mov th0,#00h
mov tl0,#00h
inc highcount
mov a,addressh
mov r0,a
mov a,temph
mov @r0,a
inc addressh
mov a,addressl
mov r0,a
mov a,templ
mov @r0,a
inc addressl
mov a,highcount
mov r3,#11
lcall subfun
jnc chuli
ajmp highbegin
chuli:
mov highcount,#00h
mov a,addressh
subb a,#08h
mov addressh,a
mov a,addressl
subb a,#08h
mov addressl ,a
mov daima,#0ffh
panshu:
mov a,addressh
mov r0,a
mov a,@r0
xrl a,#01h
jz panshu1
mov a,addressl
mov r0,a
mov a,@r0
mov r3,#60
lcall subfun
jc error
mov a,@r0
mov r3,#220
lcall subfun
jnc error
mov a,daima
clr c
rlc a
mov daima,a
mov a,panshunum
xrl a,#07h
jz dongzuo
ajmp next
panshu1:
mov a,addressl
mov r0,a
mov a,@r0
mov r3,#0
lcall subfun
jc error
mov a,@r0
mov r3,#160
lcall subfun
jnc error
mov a,daima
setb c
rlc a
mov daima,a
mov a,panshunum
xrl a,#07h
jz dongzuo
next:
inc panshunum
inc addressh
inc addressl
ajmp panshu
error:
mov p1,#0b7h;display "E",MEANS Input key is error
lcall delay
lcall exit
ljmp start1
dongzuo:
mov panshunum,#00h
clr tr0
mov tl0,#00h
mov th0,#00h
mov a,daima
xrl a,#11000000b; guan key,turn the secondkeyflag
jnz dongzuo1
cpl secondkeyflag
jnb secondkeyflag,jixu2
lcall sounddelay
lcall delay
lcall sounddelay
ajmp jixu1
jixu2:
lcall sounddelay
jixu1:
lcall exit
ljmp start1
dongzuo1:
mov a,daima
xrl a,#11000001b; 2 or 6
jnz dongzuo2
jb secondkeyflag,key6
mov key,#02h
ajmp key26
key6:
mov key,#06h
key26:
lcall sounddelay
lcall display
lcall exit
ljmp start1
dongzuo2:
mov a,daima
xrl a,#11000010b;key 4/8
jnz dongzuo3
jb secondkeyflag,key8
mov key,#4
ajmp key48
key8:
mov key,#08h
key48:
lcall display
lcall sounddelay
lcall exit
ljmp start1
dongzuo3:
mov a,daima
xrl a,#11000100b; key 3 or 7
jnz dongzuo4
jb secondkeyflag,key7
mov key,#03h
ajmp key37
key7:
mov key,#07h
key37:
lcall display
lcall sounddelay
lcall exit
ljmp start1
dongzuo4:
mov a,daima
xrl a,#11001000b;key 1 or 5
jnz dongzuo4_1
jb secondkeyflag,key5
mov key,#01h
ajmp dongzuo4_1
key5:
mov key,#05h
dongzuo4_1:
lcall display
lcall sounddelay
lcall exit
ljmp start1
exit:
clr tr0
clr tf0
mov th0,#00h
mov tl0,#00h
dongzuo1_1:
jnb p3.7,dong2
ajmp dong1
dong2:
clr tr0
clr tf0
mov th0,#00h
mov tl0,#00h
ajmp dongzuo1_1
dong1:
setb tr0
jbc tf0,exitnext
jb p3.7,dongzuo1_1
ajmp exit
exitnext:
lcall delay
ret
subfun:
clr c
subb a,r3
ret
delay:
mov r7,#0ffh
d1:mov r6,#0ffh
d2:djnz r6,d2
djnz r7,d1
ret
sounddelay:
mov r7,#0ffh
sound1:mov r6,#0ffh
sound2:djnz r6,sound2
cpl sound
djnz r7,sound1
clr sound
ret
display:
mov a,key
mov dptr,#segtable
movc a,@a+dptr
mov p1,a
mov a,keynum
mov r3,#08h
lcall subfun
jc godisplayexit ;if haven't 8 keys,exit the sub toute
keychuli: ;have 8 keys ,begin to deal keys
jb p1.0,keychuli1
lcall delay
jnb p1.0,savekey1_1
keychuli1:
mov keynum,#00h
mov r7,#08h;8 keys
bijiao:
mov a,keynum
add a,#keyaddress
mov r0,a
mov a,keynum
add a,#mimaaddress
mov r1,a
mov a,@r1
xrl a,@r0
jnz bijiaoerror; bijiao is error
inc keynum
mov a,keynum
cjne a,#08,bijiao
mov keynum,#00h;8 mima bijiao is done
clr kaisuo
mov errornum,#00h;clear error cishu
mov r1,#20
mov p1,#0a5h;display "|-", MEANS THE input key is right ,and is openning the
alarm:lcall sounddelay
djnz r1,alarm
setb kaisuo
mov p1,#0efh; display "0"
ljmp displayexit1
savekey1_1:
ajmp savekey
bijiaoerror: ;mima bijiao cuowu chuli
mov keynum,#00h
mov a,errornum
mov r3,#2h
lcall subfun
jnc erroralarm
mov a,errornum
inc a
mov dptr,#segtable
movc a,@a+dptr
mov p1,a ;display error num
mov r1,#03h
errordisp:
lcall sounddelay
mov p1,#00h
lcall sounddelay
mov p1,a
djnz r1,errordisp
inc errornum
ljmp displayexit1
godisplayexit:
ajmp displayexit
erroralarm:
mov errornum,#00h
mov p1,#0b7h;display "E"
setb keyerrorflag
mov th1,#3ch
mov tl1,#0b0h
mov tensecond,#00h
mov intcount,#00h
setb tr1 ;enable timer1 to dedao interupt
jb keyerrorflag,$
clr tr1
mov p1,#0efh; display "0"
ljmp displayexit1
savekey:
mov keynum,#00h
savekey1:
mov a,keynum
add a,#keyaddress
mov r0,a
mov a,keynum
add a,#mimaaddress
mov r1,a
mov a,@r0
xch a,@r1
mov a,keynum
cjne a,#07h,savenext;baocun not done
mov keynum,#00h ;baocun done
lcall write9346 ;write to 9346
mov p1,#0cfh;display "|_|", means is saving the code
lcall sounddelay
lcall delay
lcall sounddelay
lcall delay
lcall sounddelay
mov p1,#0efh
ajmp displayexit1
savenext:
inc keynum
ajmp savekey1
displayexit:
mov a,keynum
add a,#keyaddress
mov r0,a
mov a,key
mov @r0,a ;save keys
inc keynum
displayexit1:
ret
timer1int:;timer1 50ms intrupt route
clr tr1
mov th1,#3ch
mov tl1,#0b0h
setb tr1
inc intcount
mov a,intcount
cjne a,#200,intexit
mov intcount,#00h
inc tensecond
mov a,tensecond
cjne a,#180,intexit
mov tensecond,#00h
clr keyerrorflag
intexit:
reti
segtable:
db 0efh,49h,77h,7bh,0d9h,0bbh,0bfh,69h,0ffh
read9346:
mov r0,#mimaaddress
mov adr46,#00h
mov templ,#04h
a1:
mov a,#read
call to9346
mov a,r5
mov @r0,a
inc r0
mov a,r4
mov @r0,a
inc adr46
inc r0
djnz templ,a1
ret
write9346:
mov r0,#keyaddress
mov templ,#04h
mov adr46,#00h
write0:
mov a,#ewen
call to9346
mov a,@r0
mov r5,a
inc r0
mov a,@r0
mov r4,a
mov a,#write
call to9346
mov a,#ewds
call to9346
inc r0
inc adr46
call delay1
djnz templ,write0
ret
to9346:
setb cs
setb di
setb clk
call delay93
clr clk
call delay93
mov dptr,#jptble
jmp @a+dptr
jptble:
ajmp sread
ajmp swrite
ajmp sewen
ajmp sewds
sread:
mov a,adr46
add a,#80h
call sdt46
call rdt46
mov r5,a
call rdt46
mov r4,a
jmp ex9346
swrite:
mov a,adr46
add a,#40h
call sdt46
mov a,r5
call sdt46
mov a,r4
call sdt46
jmp ex9346
sewen:
mov a,#30h
call sdt46
jmp ex9346
sewds:
clr a
call sdt46
ex9346:
clr cs
ret
sdt46:
mov r3,#08h
sd1:
rlc a
mov di,c
setb clk; upedge to write
call delay93
clr clk
call delay93
djnz r3,sd1
ret
rdt46:
mov r3,#08h
rd1:
setb clk
call delay93
clr clk
call delay93
mov c,do
rlc a
djnz r3,rd1
ret
delay93:
mov r7,#0fh
djnz r7,$
ret
delay1:
mov r4,#20
d11:
mov r5,#20
d22:
mov r6,#248
djnz r6,$
djnz r5,d22
djnz r4,d11
ret
end |
-
电路图
|