首页 > 解决方案 > 简单回路(读取温度 - MC68HC)

问题描述

我正在阅读有关使用MC68HC11的 I/O 的章节;这本书展示了一个建议的练习(不是一个很难的练习),但我无法通过使用汇编来解决它:

图片

我一直在想,我可以通过使用一些基本逻辑来做到这一点(我用 C 和 C++ 编写程序),但我在尝试在汇编中做到这一点时被卡住了。

逻辑是这样的:

Loop:

value = ReadSensorValue()

if (value condition 1) // do action else if (value condition 2) // do something end if

go to Loop

可以帮助我解决它,但在汇编中使用真实的指令吗?



编辑:

错误

错误2

标签: assembly68hc11

解决方案


这是一种方法(使用ASM11)。我知道你正在努力学习,但你没有表现出任何努力。(这是我在没有先看到你的努力的情况下做的最后一个。)

;*******************************************************************************
; MCU specific
;*******************************************************************************

REGS                equ       $1000               ;register base
PORTB               equ       REGS+$04            ;port B (output only)
PORTC               equ       REGS+$03            ;port C
STACKTOP            equ       $01FF               ;Top of Stack
ROM                 equ       $F800               ;beginning of ROM
Vreset              equ       $FFFE               ;reset vector

;*******************************************************************************
; Application specific
;*******************************************************************************

TEMPERATURE         equ       PORTC               ;temperature is available here

CONTROL             equ       PORTB
HEATER.             equ       1                   ;bit that controls heater
COMPRESSOR.         equ       2                   ;bit that controls cooler

MIN_TEMP            equ       20                  ;min allowed temp in C
MAX_TEMP            equ       22                  ;max allowed temp in C

;*******************************************************************************
                    org       ROM
;*******************************************************************************

;*******************************************************************************
; Purpose: Get temperature as Centigrade degrees
; Input  : None
; Output : A = temperature in whole degrees (fractional part discarded)
; Note(s): Formula is TEMPERATURE*5/10 using integer arithmetic
;        : Simplifies to TEMPERATURE/2

GetTemperature      proc
                    ldaa      TEMPERATURE         ;A = temperature
                    lsra                          ;A = temperature/2
                    adca      #0                  ;(optional) round up
                    rts

;*******************************************************************************

CoolIt              proc
                    pshx
                    ldx       #CONTROL
                    bclr      ,x,HEATER.
                    bset      ,x,COMPRESSOR.
                    pulx
                    rts

;*******************************************************************************

HeatIt              proc
                    pshx
                    ldx       #CONTROL
                    bclr      ,x,COMPRESSOR.
                    bset      ,x,HEATER.
                    pulx
                    rts

;*******************************************************************************

AllOff              proc
                    pshx
                    ldx       #CONTROL
                    bclr      ,x,COMPRESSOR.|HEATER.
                    pulx
                    rts

;*******************************************************************************

Start               proc
                    lds       #STACKTOP
                    bsr       AllOff

Loop@@              bsr       GetTemperature      ;A = temperature in degrees

                    cmpa      #MIN_TEMP           ;if below minimum
                    blo       HeatIt@@            ; go heat it up

                    cmpa      #MAX_TEMP           ;if above maximum
                    bhi       CoolIt@@            ; go cool it down

                    bsr       AllOff              ;if within range turn all off
                    bra       Loop@@              ;go check temperature again

CoolIt@@            bsr       CoolIt
                    bra       Loop@@              ;go check temperature again

HeatIt@@            bsr       HeatIt
                    bra       Loop@@              ;go check temperature again

;*******************************************************************************
                    org       Vreset
                    dw        Start
;*******************************************************************************

推荐阅读