AT89C2051内部比较器应用例子

at89c2051内部比较器应用例子
this program implements a simple two-digit voltmeter, utilizing an
; at89cx051 microcontroller, two resistors, a capacitor and two hp5082-7300
; decimal led displays. the code is compatible with both the at89c1051 and
; at89c2051 when operating with a 12 mhz clock. code modifications may be
; required for operation at a different clock rate.
; the voltmeter application demonstrates the rc analog-to-digital conversion
; method. the microcontroller uses an output pin, which swings from ground to
; vcc, to alternately charge and discharge the capacitor through a resistor.
; utilizing the internal comparator, the microcontroller measures the time
; required for the voltage on the capacitor to match the unknown voltage and
; uses the result as an index into a table. the table contains display values
; corresponding to the capacitor voltage. each display value is encoded in
; one byte as two bcd digits, which are displayed as volts and tenths of a
; volt on the two decimal displays. there is no software hysteresis, so the
; display may oscillate at a transition voltage.
; the conversion routine, adc, is general purpose, returning the entry in
; the table which corresponds to the measured time. the table contents may
; be modified to any data format required by an application.
the nop instructions in the conversion routine are used to delay the first
; sample in the charge and discharge portions of the measurement cycle.
; the amount of delay has an effect on measurement accuracy, and the number
; of nops may be adjusted (slightly) for best results.
;
; scount is defined as the minimum number of samples which must be taken to
; guarantee that the voltage on the capacitor has reached vcc/2. tcharge and
; tdischarge are defined as the minimum time required for the voltage on the
; capacitor to approach within 1/2 delta v of vcc and ground, respectively.
; the minimum conversion time is approximately tcharge + tdischarge, or
; six milliseconds. the maximum conversion time is approximately tcharge +
; tdischarge + 2 * (5 microseconds * scount), or seven milliseconds.
;
; for additional information refer to the application note.
scountequ79; minimum samples to reach vcc/2
tchargeequ3; cap charge time, in milliseconds
tdischargeequ3; cap discharge time, in milliseconds
dseg at 0020h
org0020h; stack origin
stack:ds0020h; stack depth
cseg
org0000h; power on/reset vector
jmpon_reset
org0003h; external interrupt 0 vector
reti; undefined
org000bh; timer 0 overflow vector
reti; undefined
org0013h; external interrupt 1 vector
reti; undefined
org001bh; timer 1 overflow vector
reti; undefined
org0023h; serial i/o interrupt vector
reti; undefined
org0040h; begin constant data space
$include(vtable.asm); get lookup table
org00e0h; begin code space
using0; register bank zero
on_reset:
movsp, #(stack-1); initialize stack pointer
movie, #0; deactivate all interrupts
movp1, #0; write zeros to displays
mova, #0ffh; deactivate output ports
movp1, a;
movp3, a;
clrp3.7; discharge capacitor
mova, #tdischarge; wait
calldelay_ms;
loop:
calladc; convert
callvshow; display voltage
sjmploop; again
adc:
; convert analog-to-digital.
; triggers capacitor charge/discharge and samples the comparator
; output at regular intervals until the comparator changes state.
; the sample interval is five microseconds with a 12 mhz clock.
; a maximum of scount samples are taken during the charge portion
; of the cycle and scount samples during the discharge portion of
; the cycle. the number of samples is used as an index into a table
; containing voltage equivalents. the number of table entries is
; twice scount. if the comparator does not switch, the last table
; entry is returned. assumes that the capacitor is fully discharged
; on entry, and discharges the capacitor before return.
; the table entry is returned in a. nothing is saved.
; charge capacitor.
mova, #0; initialize loop count
setbp3.7; begin charging1 us
nop; padding1 us
nop;1 us
ad1:
jbp3.6, ad4; jump if comp output high2 us
inca; increment count1 us
cjnea, #scount, ad1; loop until timeout2 us
; timeout.
; be sure capacitor is fully charged.
mova, #tcharge; wait
calldelay_ms;
; discharge capacitor.
mova, #0; initialize loop count
clrp3.7; begin discharging1 us
nop; padding1 us
nop;1 us
ad2:
jnbp3.6, ad3; jump if comp output low2 us
inca; increment count1 us
cjnea, #scount, ad2; loop until timeout2 us
; timeout.
deca; last count
ad3:
adda, #scount; use top half of table
; fetch table entry.
ad4:
movdptr, #volttable; pointer to base of table
movca, @a+dptr; get voltage data
pushacc; save data temporarily
; be sure capacitor is fully discharged.
clrp3.7; begin discharging
mova, #tdischarge; wait
calldelay_ms;
popacc
ret
vshow:
; display two bcd digits on a pair of hp5082-7300 displays.
; the four data lines to each display share p1.7:1.4. the units
; display is selected by a low on p1.3 and the tenths display by a
; low on p1.2. the units display is wired to light the decimal point.
; on entry, expects two packed bcd digits in a. returns nothing.
; all registers preserved, including flags.
pushpsw
pushacc
pushacc; save digits
orla, #00001111b; set unused bits
movp1, a; write units digit
clrp1.3; strobe data into display
setbp1.3;
popacc; restore digits
swapa; move low digit into high nybble
orla, #00001111b; set unused bits
movp1, a; write tenths digit
clrp1.2; strobe data into display
setbp1.2;
popacc
poppsw
ret
delay_ms:
; delay for approximately one millisecond times the value in a.
; all registers preserved, including flags.
pushpsw
pushacc
pushb
movb, #0
ddm:
djnzb, $; 512 us @ 12 mhz
djnzb, $; 512 us @ 12 mhz
djnzacc, ddm
popb
popacc
poppsw
ret
end

GPGPU在关键军事情报中不断变化的作用
Zenimax Media刚刚被微软以75亿美元的价格收购
工业路由器在快递自提柜上的作用
70+高分子行业上市公司陆续发布了2020年半年度报告
瑞士开发新半导体材料-辉钼矿
AT89C2051内部比较器应用例子
半干式双层水凝胶电极用于无创连续脑电图采集
硬盘录像机的主要功能
3D技术在全方位汽车立体监视系统中应用
降低继电器线圈功耗的电路图
怎么选择合适的热缩管?
传英特尔正与台积电、三星洽谈,英特尔将成台积电3纳米芯片第二大户
突发!楼氏电子或出售MEMS麦克风业务!歌尔股份成最大赢家?
又一国产巨头崛起,目标直指富士康的饭碗:手机代工生产
电能质量分析仪软件DRANVIEW 7介绍
可定制的人工智能对话是怎样的
喜讯!菲菱科思荣获“智能制造能力成熟度等级二级”认证
今日传感财经:烟气监测概念报涨;机动车检测概念报涨;红外传感器概念报涨
美的库卡智能制造科技园全面投产,规划机器人年产能8-10万台
jvm管理的内存包括哪几个运行时数据内存