ZNorQ's playground

Stationeer MIPS - Temperature controller

# HQ Temperature controller
####################################################
alias led d0
alias base db
alias sensor d1
alias heaterA d2
alias heaterB d3
alias coolerA d4
alias coolerB d5
alias state r0
alias result r1
alias return r2
alias command r3
alias color r4
alias heater r5
alias cooler r6
alias isRunning r7
####################################################
define true 1
define false 0
define cmdStop 0
define cmdStart 1
define cmdNothing -1
define colorRed 4
define colorBlue 0
define colorWhite 6
define k2c 273.15                    # Zero celicus
define tempMin 20
define tempTgt 25                    # Target temp.
define tempMax 30
####################################################
jal doInit
loop:
  jal getState
  jal evalState
  beq command cmdNothing loop
  jal setSystem
j loop
####################################################
getState:
l state sensor Temperature
sub state state k2c            # Convert to celcius
round state state
l return heaterA On
l result coolerA On
or isRunning result return
s base Setting state
j ra
####################################################
evalState:
sle result state tempMin
nor return isRunning isRunning       # NOT isRunning
and result result return
  select result cooler false cooler
  select result heater true heater
  select result color colorBlue color
  select result command cmdStart cmdNothing
seq result state tempTgt
and result result isRunning
  select result cooler false cooler
  select result heater false heater
  select result color colorWhite color
  select result command cmdStop command
sge result state tempMax
nor return isRunning isRunning       # NOT isRunning
and result result return
  select result cooler true cooler
  select result heater false heater
  select result color colorRed color
  select result command cmdStart command
j ra
####################################################
setSystem:
s led Color color
s coolerA On cooler
s coolerB On cooler
s heaterA On heater
s heaterB On heater
j ra
####################################################
doInit:
move cooler false
move heater false
move color colorWhite
move command cmdNothing
s led On true
s led Lock true
s coolerA Lock false # TRUE!
s coolerB Lock false # TRUE!
s heaterA Lock false # TRUE!
s heaterB Lock false # TRUE!
push ra
jal setSystem
pop ra
j ra
####################################################