简单循环(读取温度-MC68HC) [英] Simple loop (reading temperature - MC68HC)
问题描述
我正在使用 MC68HC11 阅读与I/O相关的一章;这本书展示了一个建议的练习(不是很难的练习),但是我无法通过使用汇编来解决它:
I was reading a chapter related to I/O using the MC68HC11; this book showed a suggested exercise (not really a hard one) but i was not able to solve it by using assembly:
我一直在思考,我可以通过使用一些基本逻辑来做到这一点(我使用C和C ++进行编程),但是在尝试进行汇编时遇到了困难.
I've been thinking and i can do it by using some basic logic (i do program in C and C++ ) but i got stuck while trying to do it in assembly.
逻辑如下:
Loop:
value = ReadSensorValue()
if (value condition 1) // do action else if (value condition 2) // do something end if
go to Loop
可以帮助我解决问题,但要在汇编中使用真实的说明吗?
Can help me to solve it but using real instructions in assembly?
推荐答案
这是一种方法(使用 ASM11 ).我了解您正在尝试学习,但是您不付出任何努力. (这是我正在做的最后一个,没有先看到您的努力.)
Here's one way to do it (using ASM11). I understand you're trying to learn but you don't show any effort. (This is the last one I'm doing without seeing some effort from you first.)
;*******************************************************************************
; 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
;*******************************************************************************
这篇关于简单循环(读取温度-MC68HC)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!