这是一种方法(使用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
;*******************************************************************************