给定为显示带符号(电动机正反转)角度偏移,范围-359.9——+359.9精确到0.1的程序,改为带符号显示偏移范围-90.00——+90.00精确到0.03
也就是说每次最小偏移是0.03 原程序为
fushu equ acc.7 ;位设定
sign equ p3.0 ;符号位
abit equ p3.2
bbit equ p3.4
org 0000h
ljmp main
org 0100h
main:
mov psw , #00h
mov r3, #00h ;置0
mov r4, #00h
mov 70h,#00h
mov 71h,#00h
mov 72h,#00h
mov 71h,#00h
setb p3.0
setb p3.6
setb p3.1
mov p2,#88h
;mov r5,#00h
loop2: mov r7,#0ffh
loop1: mov r6,#0ffh ;延时chushiyianshi
loop: djnz r6,loop
djnz r7,loop1
; djnz r5,loop2
clr p3.0
setb p3.6
setb p3.1
mov p2,#00h
clr p3.0
setb p3.3
setb p3.7
mov p1,#00h
mov sp,#60h
mov r0,#80h
mov r1,#02h
clear: mov @r1,#00h ;设定存储位置,清0
inc r1
djnz r0,clear
mov r1,#00h
clr p3.0
reada: mov c,abit ;读abit
jnc aup ;脉冲沿判定
adow: mov c,abit
jc pd_adow_bbit
mov c,bbit
jnc adowb0
ljmp adowb1
pd_adow_bbit: ;判断adow时的b
mov c,bbit
jc adow_bnextdow
adow_bnextup:
mov c,bbit
jc adow_bup
jmp adow
adow_bup:ljmp bupa1
adow_bdow:ljmp bdowa1
adow_bnextdow:
mov c,bbit
jnc adow_bdow
ljmp adow
adowb1: lcall adddisplay
lcall display
ljmp bdow
adowb0: lcall subbdisplay
lcall display
ljmp bup
aup: mov c,abit
jnc pd_aup_bbit
mov c,bbit
jnc aupb0
ljmp aupb1
pd_aup_bbit: ;判断aup时的b
mov c,bbit
jc aup_bnextdow
aup_bnextup:
mov c,bbit
jc aup_bup
ljmp aup
aup_bup:ljmp bupa0
aup_bdow:ljmp bdowa0
aup_bnextdow:
mov c,bbit
jnc aup_bdow
ljmp aup
aupb1: lcall subbdisplay
lcall display
ljmp bdow
aupb0: lcall adddisplay
lcall display
ljmp bup
bup: mov c,bbit
jnc pd_bup_abit
mov c,abit
jc bupa1
ljmp bupa0
pd_bup_abit: ;判断bup时的a
mov c,abit
jc bup_anextdow
bup_anextup:
mov c,abit
jc bup_aup
ljmp bup
bup_aup:ljmp aupb0
bup_adow:ljmp adowb0
bup_anextdow:
mov c,abit
jnc bup_adow
ljmp bup
bupa0: lcall subbdisplay
lcall display
ljmp aup
bupa1: lcall adddisplay
lcall display
ljmp adow
bdow: mov c,bbit
jc pd_bdow_abit
mov c,abit
jnc bdowa0
ljmp bdowa1
pd_bdow_abit: ;判断bdow时的a
mov c,abit
jc bdow_anextdow
bdow_anextup:
mov c,abit
jc bdow_aup
ljmp bdow
bdow_aup:ljmp aupb1
bdow_adow:ljmp adowb1
bdow_anextdow:
mov c,abit
jnc bdow_adow
ljmp bdow
bdowa1:
lcall subbdisplay
lcall display
ljmp adow
bdowa0: lcall adddisplay
lcall display
ljmp aup
adddisplay: ;加显示
;mov 76h,#88h
;mov 75h,#00h
mov a,r3
jb acc.7,fu1 ;判断r3的7位置是否为1是跳fu1
clr sign
mov a,r4
add a,#01h
mov r4,a
mov a,r3
addc a,#00h
mov r3,a
lcall addbcd
mov a,r4
cjne a,#0e0h,aret ;3000个脉冲上限判断120000
mov a,r3
cjne a,#2eh,aret
mov r3, #00h
mov r4, #00h
mov 72h,#00h
mov 71h,#00h
mov 70h,#00h
mov 73h,#00h
lcall display
sjmp are