澳门澳博集团

当前位置:澳博集团 > 解密技术下载 >

用AT89C2051单片机组成的数字定时器源程序

2010-03-31 10:00

AT89C2051单片机组成的数字定时器源程序
org 0000h
ajmp main
nop
org 01bh
clr tr1
ajmp timon
org 30h
;----------------------
main: mov 40h,#00h
mov 41h,#00h
mov 42h,#09h
mov 43h,#09h
mov 4ah,#09h
mov 4bh,#09h
mov p3,#0ffh
mov sp,#50h
mov tmod,#10h
mov ie,#88h
mov tl1,#37h
mov th1,#70h
setb tr1
;------------------------
disp: ;显示
nop
mov dptr,#tab
clr p3.4
mov a,42h
movc a,@a+dptr ;
anl p1,#01h
orl p1,a
setb p3.5
lcall ms10
acall key
clr p3.5
mov a,43h
movc a,@a+dptr
anl p1,#01h
orl p1,a
setb p3.4
lcall ms10
acall key1
ajmp disp
;------------------------
timon:;定时计数中断子程序
setb rs0
push psw
push acc
mov tl1,#37h
mov th1,#70h
setb tr1
inc 40h
mov r0,40h
cjne r0,#8,tim
mov 40h,#00h
cpl p1.0
t11: inc 41h
mov r0,41h
cjne r0,#60,tim
mov 41h,#00h
mov r0,42h
cjne r0,#00,tia
ajmp tib
tia: dec 42h
ajmp tim
tib: mov r1,43h
cjne r1,#00,tic
mov p1,#0ffh
setb p3.7
clr p1.0
clr tr1
mov 42h,#0ah
mov 43h,#0ah
ajmp tim
tic: dec 43h
mov 42h,#09h
tim: pop acc
pop psw
reti
;------------------------
key:;-按键处理子程序
nop
k0: jb p3.0,k1
acall ms10
acall ms10
MOV IE,#0;
setb p3.7
jnb p3.0,time
k1: jb p3.3,k4
acall ms10
acall ms10
MOV IE,#0;
jnb p3.3,off
k4: jb p3.2,fh
clr p3.7
acall ms10
acall ms10
jnb p3.2,qd
fh: ret
time: jnb p3.0,$
mov r4,4ah
dec 4ah
cjne r4,#00h,ti1
mov 4ah,#09h
ti1: mov 43h,4ah
setb tr1
mov 40h,#00h
mov 41h,#00h
ret
key1: nop
k5: jb p3.1,k1
acall ms10
acall ms10
MOV IE,#0;
setb p3.7
jnb p3.1,time1
ljmp k1
;------------------------
qd: mov ie,#88h
mov 42h,4bh
mov 43h,4ah
mov 40h,#00h
mov 41h,#00h
setb tr1
clr p3.7
ret;
time1: jnb p3.1,$
mov r4,4bh
dec 4bh
cjne r4,#00h,ti2
mov 4bh,#09h
ti2: mov 42h,4bh
setb tr1
mov 40h,#00h
mov 41h,#00h
ret
;------------------------
off:;--退出
jnb p3.3,$
mov r0,#00h
clr tr1

mov 42h,#0ah
mov 43h,#0ah
setb p3.7
setb p1.0
ajmp disp
;------------------------
ms10:;- 延时
mov r0,#100
ms: nop
djnz r0,ms
ret
tab:db 80h,0f2h,48h,60h,32h,24h
db 04h,0f0h,00h,20h,7eh
end