AT89C2051内部比较器应用例子

发布时间:2023-04-03  

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.

  SCOUNT    EQU  79    ; minimum samples to reach Vcc/2
  TCHARGE    EQU  3    ; cap charge time, in milliseconds
  TDISCHARGE  EQU  3    ; cap discharge time, in milliseconds
  DSEG AT 0020H
  ORG  0020H    ; stack origin
  stack:    DS  0020H    ; stack depth
  CSEG
  ORG  0000H    ; power on/reset vector
  jmp  on_reset
  ORG  0003H    ; external interrupt 0 vector
  reti      ; undefined
  ORG  000BH    ; timer 0 overflow vector
  reti      ; undefined
  ORG  0013H    ; external interrupt 1 vector
  reti      ; undefined
  ORG  001BH    ; timer 1 overflow vector
  reti      ; undefined
  ORG  0023H    ; serial I/O interrupt vector
  reti      ; undefined
  ORG  0040H    ; begin constant data space
  $INCLUDE(vtable.asm)      ; get lookup table
  ORG  00E0H    ; begin code space
  USING  0    ; register bank zero
  on_reset:
  mov  sp, #(stack-1)  ; initialize stack pointer
  mov  IE, #0    ; deactivate all interrupts
  mov  p1, #0    ; write zeros to displays
  mov  a, #0ffh  ; deactivate output ports
  mov  p1, a    ;
  mov  p3, a    ;
  clr  p3.7    ; discharge capacitor
  mov  a, #TDISCHARGE  ; wait
  call  delay_ms  ;
  loop:
  call  adc    ; convert
  call  vshow    ; display voltage
  sjmp  loop    ; 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.

  mov  a, #0    ; initialize loop count
  setb  p3.7    ; begin charging    1 uS
  nop      ; padding      1 uS
  nop      ;        1 uS
  ad1:
  jb  p3.6, ad4  ; jump if comp output high  2 uS
  inc  a    ; increment count    1 uS
  cjne  a, #SCOUNT, ad1  ; loop until timeout    2 uS
  ; Timeout.
  ; Be sure capacitor is fully charged.
  mov  a, #TCHARGE  ; wait
  call  delay_ms  ;
  ; Discharge capacitor.
  mov  a, #0    ; initialize loop count
  clr  p3.7    ; begin discharging    1 uS
  nop      ; padding      1 uS
  nop      ;        1 uS
  ad2:
  jnb  p3.6, ad3  ; jump if comp output low  2 uS
  inc  a    ; increment count    1 uS
  cjne  a, #SCOUNT, ad2  ; loop until timeout    2 uS
  ; Timeout.
  dec  a    ; last count
  ad3:
  add  a, #SCOUNT  ; use top half of table
  ; Fetch table entry.
  ad4:
  mov  dptr, #VoltTable  ; pointer to base of table
  movc  a, @a+dptr    ; get voltage data
  push  acc      ; save data temporarily
  ; Be sure capacitor is fully discharged.
  clr  p3.7    ; begin discharging
  mov  a, #TDISCHARGE  ; wait
  call  delay_ms  ;
  pop  acc
  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.

  push  psw
  push  acc
  push  acc    ; save digits
  orl  a, #00001111b  ; set unused bits
  mov  p1, a    ; write units digit
  clr  p1.3    ; strobe data into display
  setb  p1.3    ;
  pop  acc    ; restore digits
  swap  a    ; move low digit into high nybble
  orl  a, #00001111b  ; set unused bits
  mov  p1, a    ; write tenths digit
  clr  p1.2    ; strobe data into display
  setb  p1.2    ;
  pop  acc
  pop  psw
  ret

  delay_ms:

  ; Delay for approximately one millisecond times the value in A.

  ; All registers preserved, including flags.

  push  psw
  push  acc
  push  b
  mov  b, #0
  ddm:
  djnz  b, $    ; 512 uS @ 12 MHz
  djnz  b, $    ; 512 uS @ 12 MHz
  djnz  acc, ddm
  pop  b
  pop  acc
  pop  psw
  ret
  END


文章来源于:电子工程世界    原文链接
本站所有转载文章系出于传递更多信息之目的,且明确注明来源,不希望被转载的媒体或个人可与我们联系,我们将立即进行删除处理。

相关文章

    运算放大器的3种基本电路(电压比较器电压跟随器和同相比例放大器); 介绍了电压比较器的三种类型:单限、滞回和窗口电压比较器,重点讨论了它们的工作原理、阈值......
    。 迟滞比较器 在单限电压比较器的基础上引入正反馈网络,就组成了具有双门限值的迟滞比较器,如下图所示。 ▲迟滞比较器示意图 迟滞比较器具有两个参考电平作为触发电平,VTH和VTL。当输入电压高于VTH......
    部分为数字滤波和裁决器,根据比特流输出数字转换结果。 工作过程如下:输入电压减去DAC输出后的差值经过积分器后和0V电压比较,如果大于等于0V输出1,否则输出0。以一定的频率控制比较器输出形成比特流,控制......
    通过一个低通滤波器来获得我们最终的音频信号。 D 类放大器工作原理图 四、D 类放大器设计所需组件 了解了 D 类放大器的基础知识后,我们可以来 DIY D 类放大器。这是一个比较简单的测试项目,组件也比较通用,你直......
    MAX6457数据手册和产品信息;MAX6457–MAX6460高电源电压、低功耗电压监视器工作于4V至28V电源电压范围内。每款器件都包括一个精密带隙基准、一路或两路低失调电压比较器、内部......
    相控制。为了稳定电压,输出电压必须与初始值匹配。 当电路工作在直流模式时,优先考虑CC电流比较放大器,工作原理与直流模式相同。 电路的工作状态可以自动切换。当负载在标称值回路中发生变化时,电路工作......
    图 3 工作原理 3.1获取故障检测电压 由电磁学理论得,通电导线周嗣有电磁场产生。在供电的电线旁安置两个串联的电磁感应线圈(形状为矩形)来获取由导线电流变化产生的信号电压。 由文......
    系统,片内置通用8位中央处理器和FLASH存储单元。AT89C2051作为AT89C51的简化版虽然去掉了P0,P2等端口,使I/O口减少了,但是却增加了一个电压比较器,因此其功能在某些方面反而有所增强。引脚......
    学子专区—ADALM2000实验:使用窗口比较器实施温度控制;目标 本次实验的目标是使用两个高速电压比较器作为窗口比较器,并采用这种方法对TMP01低功耗可编程温度控制器进行编程。 窗口比较器......
    ,运放工作在非线性区或饱和区。 下图,依然是电压比较器结构,上面已经提到,运放开环增益很大,不带负反馈,工作就如非线性区,当做电压比较器......

我们与500+贴片厂合作,完美满足客户的定制需求。为品牌提供定制化的推广方案、专属产品特色页,多渠道推广,SEM/SEO精准营销以及与公众号的联合推广...详细>>

利用葫芦芯平台的卓越技术服务和新产品推广能力,原厂代理能轻松打入消费物联网(IOT)、信息与通信(ICT)、汽车及新能源汽车、工业自动化及工业物联网、装备及功率电子...详细>>

充分利用其强大的电子元器件采购流量,创新性地为这些物料提供了一个全新的窗口。我们的高效数字营销技术,不仅可以助你轻松识别与连接到需求方,更能够极大地提高“闲置物料”的处理能力,通过葫芦芯平台...详细>>

我们的目标很明确:构建一个全方位的半导体产业生态系统。成为一家全球领先的半导体互联网生态公司。目前,我们已成功打造了智能汽车、智能家居、大健康医疗、机器人和材料等五大生态领域。更为重要的是...详细>>

我们深知加工与定制类服务商的价值和重要性,因此,我们倾力为您提供最顶尖的营销资源。在我们的平台上,您可以直接接触到100万的研发工程师和采购工程师,以及10万的活跃客户群体...详细>>

凭借我们强大的专业流量和尖端的互联网数字营销技术,我们承诺为原厂提供免费的产品资料推广服务。无论是最新的资讯、技术动态还是创新产品,都可以通过我们的平台迅速传达给目标客户...详细>>

我们不止于将线索转化为潜在客户。葫芦芯平台致力于形成业务闭环,从引流、宣传到最终销售,全程跟进,确保每一个potential lead都得到妥善处理,从而大幅提高转化率。不仅如此...详细>>