Ht47AD轉(zhuǎn)換器應(yīng)用
Ht47AD轉(zhuǎn)換器應(yīng)用
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轉(zhuǎn)換允許
MOV a,0fh ;TIMER A計(jì)數(shù)系統(tǒng)時(shí)鐘
andm a,tmrc
set adcr.4 ;TIMER B計(jì)數(shù)傳感器電阻-參考電容
set adcr.5
clr aCC ;定時(shí)/計(jì)數(shù)器初值
MOV tmral,a
MOV tmrah,a
MOV tmrbl,a
MOV tmrbh,a
clr int_count ;中斷次數(shù)計(jì)數(shù)器
set tmrc.4 ;開(kāi)定時(shí)/計(jì)數(shù)器
set intc1.0 ;定時(shí)/計(jì)數(shù)器中斷允許
set intc0.0 ;總中斷允許
jmp $
;----------------------------
t_int: inc int_count ;定時(shí)/計(jì)數(shù)器中斷服務(wù)子程序
MOV a,int_count ;中斷次數(shù)判斷
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,則進(jìn)行除法操作
jmp div_over ;n為0,則不進(jìn)行除法操作
div: clr c ;除法操作
rrc kh
rrc kl
sdz count
jmp div
div_over:
clr acc ;TIMER A計(jì)數(shù)初值為0
MOV tmral,a
MOV tmrah,a
MOV a,0ffh ;TIMER B計(jì)數(shù)初值為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的值,記為T(mén)0
MOV a,tmral
MOV tl,a
clr adcr.0 ;TIMER A溢出作為中斷
clr adcr.5 ;TIMER B計(jì)數(shù)參考電阻-參考電容
MOV a,0ffh ;TIMER A計(jì)數(shù)初值為65536-T0
sub a,tl
MOV tmral,a
MOV a,0ffh
sub a,th
MOV tmrah,a
clr acc ;TIMER B計(jì)數(shù)初值為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,則進(jìn)行 乘法操作
jmp mul_over ;n為0,則不進(jìn)行乘法操作
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計(jì)數(shù)傳感器電阻-參考電容
clr acc ;定時(shí)/計(jì)數(shù)器初值
MOV tmral,a
MOV tmrah,a
MOV tmrbl,a
MOV tmrbh,a
clr int_count ;清除中斷次數(shù)計(jì)數(shù)器
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
;---------------------------------