以下程序已实际调试运行通过)
; ---AT89C2051加氧泵控制器源程序-OK!
org 0000h
ajmp main
nop
org 01bh
clr tr1
ajmp timon
org 30h
main:mov 40h,#00h
mov 41h,#00h
mov 42h,#00h
mov 43h,#02h
mov 44h,#00h
mov 45h,#00h
mov 46h,#00h
mov 4ah,#02h
mov 4bh,#00h
mov 4ch,#01h
mov 4dh,#05h
nca equ 48h
ncb equ 49h
mov p3,#0ffh
mov sp,#50h
mov tmod,#10h
mov ie,#88h
mov tl1,#46h
mov th1,#76h
clr nca
clr ncb
setb tr1
clr p3.7
disp:;------显示-------
mov r3,46h
cjne r3,#1,ct
mov dptr,#tab
clr p3.2
mov a,42h
movc a,@a+dptr
anl p1,#01h
orl p1,a
jb ncb,xsb
setb p3.3
lcall ms10
xsb: acall key
clr p3.3
jb nca,ys1
mov a,43h
movc a,@a+dptr
anl p1,#01h
orl p1,a
setb p3.2
ys1: lcall ms10
ajmp disp
ct: mov dptr,#tab
clr p3.2
mov a,42h
movc a,@a+dptr
anl p1,#01h
orl p1,a
jb ncb,xsd
setb p3.3
lcall ms10
xsd: acall key
clr p3.3
jb nca,ys2
mov a,43h
movc a,@a+dptr
anl p1,#01h
orl p1,a
setb p3.2
ys2: lcall ms10
ajmp disp
timon:;定时计数中断子程序--
setb rs0
push psw
push aCC
mov tl1,#46h
mov th1,#76h
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
cpl p3.7
mov r6,46h
inc 46h
cjne r6,#01h,zd
mov 46h,#00h
mov 42h,4bh
mov 43h,4ah
ajmp tim
zd: mov 42h,4dh
mov 43h,4ch
ajmp tim
tic: dec 43h
mov 42h,#09h
tim: pop acc
pop psw
reti
key:;-----按键处理-------
nop
k0: jb p3.1,k1
acall ms10
acall ms10
jnb p3.1,sz
ljmp k1
sz: jnb p3.1,$
setb p3.7
inc 44h
mov r5,44h
k1: cjne r5,#01h,k2
setb nca
clr ncb
setb p3.5
clr p3.4
mov 46h,#00h
mov ie,#00h
jb p3.0,fh
acall ms10
acall ms10
jnb p3.0,ct1
k2: cjne r5,#02h,k3
setb ncb
clr nca
mov 46h,#00h
mov ie,#00h
jb p3.0,fh
acall ms10
acall ms10
jnb p3.0,ct2
k3: cjne r5,#03h,k4
setb nca
clr ncb
setb p3.4
clr p3.5
mov 46h,#01h
mov 42h,4dh
mov 43h,4ch
mov ie,#00h
jb p3.0,fh
acall ms10
acall ms10
jnb p3.0,cd1
k4: cjne r5,#4h,k5
setb ncb
clr nca
mov 46h,#01h
mov ie,#00h
jb p3.0,fh
acall ms10
acall ms10
jnb p3.0,cd2
k5: cjne r5,#05h,fh
mov r5,#00h
setb p3.4
setb p3.5
ljmp qd
fh: ret
ct1:;-----常通个位定时减----
jnb p3.0,$
mov r4,4bh
dec 4bh
cjne r4,#00h,ct1a
mov 4bh,#09h
ct1a:mov 42h,4bh
ret;
ct2:;-----常通十位定时减----
jnb p3.0,$
mov r4,4ah
dec 4ah
cjne r4,#00h,ct2a
mov 4ah,#09h
ct2a:mov 43h,4ah
ret
cd1:;-----常断个位定时减----
jnb p3.0,$
mov r4,4dh
dec 4dh
cjne r4,#00h,cd1a
mov 4dh,#09h
cd1a:mov 42h,4dh
ret;
cd2:;-----常断十位定时减----
jnb p3.0,$
mov r4,4ch
dec 4ch
cjne r4,#00h,cd2a
mov 4ch,#09h
cd2a:mov 43h,4ch
ret
qd: mov 46h,#00h
mov 44h,#00h
mov 42h,4bh
mov 43h,4ah
mov ie,#88h
clr nca
clr ncb
setb tr1
clr p3.7
ret
ms10:;----- 延时毫秒-------
mov r0,#100
ms: nop
djnz r0,ms
ret
;---------------------------
tab: db 80h,0f2h,48h,60h,32h,24h
db 04h,0f0h,00h,20h
end
上一篇:4×4矩阵键盘C语言程序参考
下一篇:单片机模拟遥控器
推荐阅读最新更新时间:2024-03-16 15:53