Ht47AD转换器应用
include ht47c20.inc
data .section 'data'
Rs equ 0064h
n db ?
count db ?
kh db ?
kl db ?
th db ?
tl db ?
int_count db ?
;----------------------------
code .section at 0 'code'
org 00h
jmp start
org 04h
reti
org 08h
reti
org 0ch
reti
org 10h
jmp t_int
;----------------------------
start: clr iNTC0
clr intc1
clr adcr
set adcr.1 ;A/D转换允许
MOV a,0fh ;TIMER A计数系统时钟
andm a,tmrc
set adcr.4 ;TIMER B计数传感器电阻-参考电容
set adcr.5
clr aCC ;定时/计数器初值
MOV tmral,a
MOV tmrah,a
MOV tmrbl,a
MOV tmrbh,a
clr int_count ;中断次数计数器
set tmrc.4 ;开定时/计数器
set intc1.0 ;定时/计数器中断允许
set intc0.0 ;总中断允许
jmp $
;----------------------------
t_int: inc int_count ;定时/计数器中断服务子程序
MOV a,int_count ;中断次数判断
MOV count,a
sdz count
jmp next
jmp int1
next: sdz count
jmp int3
jmp int2
;----------------------------
int1: MOV a,tmrbh ;第一次中断
MOV kh,a ;读取TIMER B的值,记为KRT0CS
MOV a,tmrbl
MOV kl,a
clr n
clr tblp
sCAN_tab: ;查表,确定n的值
tabrdl acc
sub a,kl
MOV a,tblh
sbc a,kh
inc n
inc tblp
sz c
jmp scan_over
jmp scan_tab
scan_over:
dec n
;----------
; MOV a,08h
;subm a,n
;----------
MOV a,high Rs
MOV kh,a
MOV a,low Rs
MOV kl,a
MOV a,n
MOV count,a
sz count ;判断n是否为0
jmp div ;n不为0,则进行除法操作
jmp div_over ;n为0,则不进行除法操作
div: clr c ;除法操作
rrc kh
rrc kl
sdz count
jmp div
div_over:
clr acc ;TIMER A计数初值为0
MOV tmral,a
MOV tmrah,a
MOV a,0ffh ;TIMER B计数初值为65536-KRTCS
sub a,kl
MOV tmrbl,a
MOV a,0ffh
sub a,kh
MOV tmrbh,a
set adcr.0 ;TIMER B溢出作为中断
set tmrc.4
reti
;----------------------------
int2: MOV a,tmrah ;第二次中断
MOV th,a ;读取TIMER A的值,记为T0
MOV a,tmral
MOV tl,a
clr adcr.0 ;TIMER A溢出作为中断
clr adcr.5 ;TIMER B计数参考电阻-参考电容
MOV a,0ffh ;TIMER A计数初值为65536-T0
sub a,tl
MOV tmral,a
MOV a,0ffh
sub a,th
MOV tmrah,a
clr acc ;TIMER B计数初值为0
MOV tmrbl,a
MOV tmrbh,a
set tmrc.4
reti
;----------------------------
int3: MOV a,tmrbh ;第三次中断
MOV kh,a ;读取TIMER B的值,记为KRSCS
MOV a,tmrbl
MOV kl,a
MOV a,n
MOV count,a
sz count ;判断n是否为0
jmp mul ;n不为0,则进行 乘法操作
jmp mul_over ;n为0,则不进行乘法操作
mul: clr acc ;乘法操作
rlc kl
rlc kh
sdz count
jmp mul
mul_over:
call display
clr adcr.0 ;TIMER A溢出作为中断
set adcr.5 ;TIMER B计数传感器电阻-参考电容
clr acc ;定时/计数器初值
MOV tmral,a
MOV tmrah,a
MOV tmrbl,a
MOV tmrbh,a
clr int_count ;清除中断次数计数器
set tmrc.4
reti
;----------------------------
display proc ;显示子程序
ret
display endp
;----------------------------
org 700h
tab: dc 100h,200h,400h,800h,1000h,2000h,4000h,8000h,0ffffh
;------------------------------------------------------------
include ht47c20.inc
data .section 'data'
count1 db ?
count2 db ?
code .section at 0 'code'
org 00h
jmp start
org 04h
reti
org 08h
reti
org 0ch
reti
org 10h
jmp ad_int
;---------------------------------
start:
clr intc0
clr intc1
MOV a,0fh
andm a,tmrc
MOV a,32h
MOV adcr,a
clr acc
MOV tmral,a
MOV tmrah,a
MOV tmrbl,a
MOV tmrbh,a
set tmrc.4
set intc1.0
set intc0.0
jmp $
;---------------------------------
ad_int: MOV a,tmrbh
MOV count1,a
MOV a,tmrbl
MOV count2,a
call calculate
reti
;---------------------------------
calculate proc
ret
calculate endp
;---------------------------------
上一篇:HT47I_O口应用
下一篇:HT47蜂鸣器应用
推荐阅读最新更新时间:2024-03-16 15:53