霍尔元件测速程序_Anythink_百度空间

这是前几天为跑步机编的测速程序,使用一个磁铁和一个霍尔元件,单片机资源一个外部中断和一个定时器.xx度比较高,{zg}xx度1/256转.程序主要难度在未完整脉冲数的计算.圈数越少小数分辨率越高.
clk_74164     equ 5
data_74164    equ 6
enable_74164 equ 7
protect_a     equ 3fh
protect_c     equ 3eh
protect_4     equ 3dh
;====================
p_times       equ 20h
bai           equ 21h
shi           equ 22h
ge            equ 23h
xiaoshu       equ 24h
four          equ 25h
eight         equ 26h
time          equ 27h
p_times2      equ 28h
time2         equ 29h
;====================
org 0
jmp setup_mcu
;==========中断=======
org 8
disi
mov protect_a,a
swapa 04h
mov protect_4,a
swapa 03h
mov protect_c,a
jbs 0fh,0
jmp pint_interrupt
;=======tcc zhongduan===
tcc_interrupt:
jz time
jmp tcc_out
mov a,p_times
mov p_times2,a
clr time
clr p_times
tcc_out:
mov a,@67h
mov 01h,a
jmp interrupt_end
;=======================
pint_interrupt:
mov p_times,p_times
jbc 03h,2
call setup_tcc
inc p_times
;====================
interrupt_end:
clr 0fh
swapa protect_c
mov 03h,a
swapa protect_4
mov 04h,a
mov a,protect_a
eni
reti
;========setup tcc======
setup_tcc:
call chuli
mov a,@67h
mov 01h,a
clr time
clr p_times
ret
;=====================
chuli:
dec p_times2
call half_time
call jisuan
call xianshi
ret
;=====================
half_time:
mov a,time
mov time2,a
clra
add a,p_times2
djz time
jmp $-2
mov p_times,a
com p_times
swap time2
mov a,@0fh
and time2,a
mov a,@10h
add time2,a
mov a,time2
sub p_times,a
jbs 03h,0
ret
inc xiaoshu
jmp $-4
mov a,@0fh
sub a,xiaoshu
jbs 03h,0
ret
mov a,@0fh
mov xiaoshu,a
ret;http://hi.baidu.com/nailson
;=========================
setup_mcu:
clr p_times
clr p_times2
clr shi
clr bai
clr ge
clr time
clr xiaoshu
clra
iow 06h
mov a,@0ffh
iow 05h
mov a,@01000000b
iow 0eh
mov a,@10000111b
contw
mov a,@00000101b
iow 0fh
mov a,@67h
mov 01h,a
eni
jmp $
;=====================
xianshi:
mov a,xiaoshu
call segtab1
mov xiaoshu,a
mov a,bai
call segtab
mov bai,a
mov a,shi
call segtab
mov shi,a
mov a,ge
call segtab
mov ge,a
dec ge
mov a,@4
mov four,a
mov A,@21h
mov 04h,A
mov a,@8
mov eight,a
move3:mov a,@8
mov eight,a
move:
bc 06h,5
rrc 00h
jbs 03h,0
bc 06h,6
jbc 03h,0
bs 06h,6
bs 06h,5
djz eight
jmp move
INC 04h
djz four
jmp move3
bc 06h,7
clr xiaoshu
clr bai
clr shi
clr ge
ret
;========================
jisuan:
mov a,@64h
sub p_times2,a
jbc 03h,0
jmp bai_c0
jmp bai_c1
bai_c0:
inc bai
jmp jisuan
bai_c1:
mov a,@64h
add p_times2,a
shi_jisuan:
mov a,@0ah
sub p_times2,a
jbc 03h,0
jmp shi_c0
jmp shi_c1
shi_c0:
inc shi
jmp shi_jisuan
shi_c1:
mov a,@0ah
add a,p_times2
mov ge,a
ret;http://hi.baidu.com/nailson
segtab:tbl
retl 0b00000011;0
retl 0b10011111;1
retl 0b00100101;2
retl 0b00001101;3
retl 0b10011001;4
retl 0b01001001;5
retl 0b01000001;6
retl 0b00011111;7
retl 0b00000001;8
retl 0b00001001;9
segtab1:tbl
retl 0b00000011;00h
retl 0b00000011;00h
retl 0b10011111;01h
retl 0b10011111;01h
retl 0b00100101;02h
retl 0b00001101;03h
retl 0b00001101;03h
retl 0b10011001;04h
retl 0b01001001;05h
retl 0b01001001;05h
retl 0b01000001;06h
retl 0b01000001;06h
retl 0b00011111;07h
retl 0b00000001;08h
retl 0b00000001;08h
retl 0b00001001;09h
end



郑重声明:资讯 【霍尔元件测速程序_Anythink_百度空间】由 发布,版权归原作者及其所在单位,其原创性以及文中陈述文字和内容未经(企业库qiyeku.com)证实,请读者仅作参考,并请自行核实相关内容。若本文有侵犯到您的版权, 请你提供相关证明及申请并与我们联系(qiyeku # qq.com)或【在线投诉】,我们审核后将会尽快处理。
—— 相关资讯 ——