eventloop.dbg 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. ;export symbols
  2. XDEF RTI_ISR
  3. XREF __SEG_END_SSTACK,disp,CRGFLG,read_pot
  4. ;clock
  5. XREF display_time,wall_timer
  6. ;password
  7. XREF pw_set,pw_reset,pw_required
  8. ;keypad
  9. XREF pressed_key,pressed_num
  10. ;menu
  11. XREF menu_timer,menu_option_num,menu_active,menu_selection
  12. ;circulation
  13. XREF dc_on,circulation_count,fan_speed
  14. ;temperature
  15. XREF show_temperature,toast_timer
  16. ;watering
  17. XREF is_watering,watering_timer,sprinkler_event,sprinkler_timer
  18. ;wall clock
  19. XREF second_passed,ms_counter
  20. ;debug
  21. XREF word_out
  22. RTI_ISR:
  23. EventLoop:
  24. ;***************** NOTE ****************
  25. ; the menu timer is a general timer for
  26. ; what to display
  27. ;***************************************
  28. ; ========= wall clock ==========
  29. ;the event loop is configured (in main.asm) to run every 4 milliseconds
  30. LDD ms_counter ;counts the milliseconds for the wall clock
  31. ADDD #04 ;add 4 milleseconds evey time the event loop runs (effectively the count starts at 4)
  32. STD ms_counter ;store the ms_counter in memory (mostly for debugging)
  33. CPD #1004 ;check if one second has passed (accounting for the start at 4)
  34. BLE LessThanSec ;less than one second has passed, continue to other functions
  35. ;one second has passed
  36. MOVB #$FF,second_passed ;this flag is set here and cleared in wall.asm
  37. CLR ms_counter
  38. LessThanSec:;less than one second has passwed (do not fire a second passed event)
  39. ;don't do anything (except track the time) if the password is not set
  40. LDAA pw_set
  41. CMPA #$FF
  42. LBNE Return
  43. ;========= circualtion ===========
  44. ;circulation is always happening (if the password is set)
  45. ;the motor should spin as soon as the password is set
  46. JSR read_pot ;read the value of the pot into D
  47. STD word_out
  48. LDX #8 ;load the bottom part of the divide (forget what it's called)
  49. ;dividing 128 pot val. by 8 wields 16 different speeds possible
  50. IDIV ;value 1 through 16 is now in X
  51. XGDX ;put the value in D
  52. STAB fan_speed ;the lower byte of D is the fan speed, higher value for faster speed
  53. ;counter is in A
  54. LDAA circulation_count
  55. INCA
  56. STAA circulation_count
  57. ;from lab 6.3
  58. ;here, fan speed has replaced the pressed value
  59. CMPA fan_speed ;compare the counter to the fan speed
  60. LBGT FanOff ;turn the fan off (low PWM)
  61. FanOn: ;if the PWM should be high
  62. MOVB #$FF,dc_on ;set the PWM high
  63. BRA FanReset ;skip setting the pulse low
  64. ;LBLE SpinDC ;branch to the stepper spinner
  65. FanOff: ;turn off the motor's PWM (low cycle)
  66. CLR dc_on
  67. FanReset: ;check if the fan counter needsd to be reset
  68. ;acc. A still has the circulation count
  69. CMPA #15 ;16 is the max value of fan_speed
  70. LBLE DidMotor ;do not clear the count if the count is in line with the speed
  71. CLR circulation_count
  72. DidMotor: ;branch here if the motor PWM has been applied
  73. ;exit if the password is resetting
  74. LDAA pw_reset
  75. CMPA #$FF
  76. LBEQ Return
  77. ;exit if the password is required
  78. ;LDAA pw_required
  79. ;CMPA #$FF
  80. ;LBEQ Return
  81. ;======== menu ===============
  82. ;delay the menu change
  83. LDX menu_timer
  84. INX
  85. STX menu_timer
  86. ;the menu should change here
  87. LDX menu_timer
  88. CPX #300
  89. LBGE CycleMenu
  90. ;==========================
  91. LDX toast_timer
  92. INX
  93. STX toast_timer
  94. LDX toast_timer
  95. CPX #200
  96. LBGE HideTemperature
  97. ;====== watering ============
  98. ;delay the watering stop
  99. LDX watering_timer
  100. INX
  101. STX watering_timer
  102. ;run sprinker
  103. LDAA sprinkler_timer
  104. INCA
  105. STAA sprinkler_timer
  106. LDAA sprinkler_timer
  107. CMPA #7
  108. LBGE Sprinkle
  109. ;watering stop
  110. LDX watering_timer
  111. CPX #500
  112. LBGE StopWatering
  113. ;======= wall clock display ========
  114. LDX wall_timer
  115. INX
  116. STX wall_timer
  117. LDX wall_timer
  118. CPX #200
  119. LBGE HideTime
  120. ;======= menu options ===========
  121. ;call these here so that the counters can increment
  122. ;watering start
  123. LDAA pressed_num
  124. CMPA #$01
  125. BEQ StartWatering
  126. ;show temperature
  127. LDAA pressed_num
  128. CMPA #$02
  129. LBEQ DisplayTemperature
  130. ;show wall clock
  131. LDAA pressed_num
  132. CMPA #$03
  133. LBEQ DisplayTime
  134. ;set time and date
  135. LDAA pressed_num
  136. CMPA #$04
  137. LBEQ SetTime
  138. ;trigger password reset
  139. LDAA pressed_num
  140. CMPA #$05
  141. LBEQ ResetPassword
  142. ;======= temperature ========
  143. ;delay the temperature display stoppage
  144. ;LDX temp_timer
  145. ;INX
  146. ;STX temp_timer
  147. ;hide temperature
  148. ;LDX watering_timer
  149. ;CPX #750
  150. ;BEQ HideTemperature
  151. ;
  152. ;
  153. ;LDAA pressed_num ;input into A for comparison
  154. ;==================== menu items ======================
  155. ;CMPA #$01
  156. ;BEQ WaterPlants
  157. ;CMPA #$02 ;pressed_num is the selected menu option
  158. ;BEQ ShowTemperature ;menu option 1 is temperature
  159. ;======================================================
  160. ;
  161. ;
  162. ;
  163. ;return by default
  164. LBRA Return
  165. CycleMenu:
  166. ;reset the timer (s) and go to the next menu option
  167. MOVW #$0000,menu_timer ;reset menu timer
  168. ;track the menu option (this resets to 1 in menu.asm)
  169. LDAA menu_option_num
  170. INCA
  171. STAA menu_option_num
  172. ;exit
  173. LBRA Return
  174. StartWatering:
  175. ;water for a certain amount of time
  176. MOVW #$0000,watering_timer ;reset the watering timer
  177. MOVB #$FF,is_watering ;turn on the water
  178. ;hide the other options
  179. MOVB #$00,show_temperature
  180. MOVB #$00,display_time
  181. MOVB #$FF,pressed_num ;clear the pressed number value
  182. MOVB #$00,menu_active ;turn off the menu (dispay watering...)
  183. LBRA Return ;exit
  184. StopWatering:
  185. MOVW #$0000,watering_timer ;reset the watering timer
  186. LDAA is_watering ;check that watering needs to be stopped
  187. CMPA #$00
  188. LBEQ Return
  189. MOVB #$00,is_watering ;turn off the water
  190. MOVB #$FF,menu_active ;restore the menu display
  191. LBRA Return ;exit
  192. Sprinkle:
  193. ;the sprinkler timer controls the speed of the stepper motor
  194. CLR sprinkler_timer
  195. ;check that the watering state is active before firing an event
  196. LDAA is_watering
  197. CMPA #$FF
  198. LBNE Return
  199. ;instruct the watering subroutine to send a signal to the stepper motor
  200. MOVB #$FF,sprinkler_event
  201. ;exit
  202. LBRA Return
  203. DisplayTemperature:
  204. MOVW #$0000,toast_timer ;clear the temperature timer
  205. ;do not disrupt watering
  206. LDAA is_watering
  207. CMPA #$FF
  208. BEQ Return
  209. ;hide the other options
  210. MOVB #$00,menu_active ;hide the menu
  211. MOVB #$00,display_time ;hide the time
  212. MOVB #$FF,pressed_num ;clear the pressed number value
  213. MOVB #$FF,show_temperature ;set the show temperature flag
  214. BRA Return
  215. HideTemperature:
  216. MOVW #$0000,toast_timer ;clear the temperature timer
  217. LDAA show_temperature ;do nothing if temperature is not showing
  218. CMPA #$00
  219. LBEQ Return
  220. MOVB #$00,show_temperature ;clear the show temperature flag
  221. MOVB #$FF,menu_active ;restore the menu
  222. BRA Return
  223. DisplayTime:
  224. MOVW #$0000,wall_timer ;clear the clock display timer
  225. ;do not disrupt watering
  226. LDAA is_watering
  227. CMPA #$FF
  228. BEQ Return
  229. ;hide the other display options
  230. MOVB #$00,show_temperature ;hide the temperature
  231. MOVB #$00,menu_active ;hide the menu
  232. MOVB #$FF,display_time ;set the time display flag
  233. MOVB #$FF,pressed_num ;clear the pressed number
  234. BRA Return
  235. HideTime:
  236. MOVW #$0000,wall_timer ;clear the clock display timer
  237. LDAA display_time
  238. CMPA #$00
  239. LBEQ Return
  240. MOVB #$00,display_time ;clear the time display flag
  241. MOVB #$FF,menu_active ;re-activate the menu
  242. BRA Return
  243. SetTime:
  244. MOVB #$FF,pw_required
  245. BRA Return
  246. ResetPassword:
  247. MOVB #$FF,pw_reset
  248. BRA Return
  249. Return:
  250. BSET CRGFLG,$80
  251. RTI