assembly - 简单回路(读取温度 - 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
可以帮助我解决它,但在汇编中使用真实的指令吗?
编辑:
解决方案
这是一种方法(使用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
;*******************************************************************************
推荐阅读
- ios - 扩展 UIViewController 以访问应用程序委托是一种反模式吗?
- python - 将所有年份的车型总和相加
- radio-button - 仅返回单选按钮选择的第一个单词
- html - 我拥有的特定 div 的 css 不起作用
- c# - Xamarin 方向传感器四元数
- shell - 为 npm login 命令行提供凭据
- php - MongoDB:一次操作更新多个文档
- debugging - int3 指令和调用 __debugbreak 有什么区别?
- reactjs - 将 Mobx 与 React typescript 一起使用时,如何删除错误“ReferenceError: 'Symbol' is undefined”?
- android - BaseAdapter 上下文中的自定义共享首选项 null