| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328 |
- ;export symbols
- XDEF RTI_ISR
-
- XREF __SEG_END_SSTACK,disp,CRGFLG,read_pot
- ;clock
- XREF display_time,wall_timer
- ;password
- XREF pw_set,pw_reset,pw_required
- ;keypad
- XREF pressed_key,pressed_num
- ;menu
- XREF menu_timer,menu_option_num,menu_active,menu_selection
- ;circulation
- XREF dc_on,circulation_count,fan_speed
- ;temperature
- XREF show_temperature,toast_timer
- ;watering
- XREF is_watering,watering_timer,sprinkler_event,sprinkler_timer
- ;wall clock
- XREF second_passed,ms_counter
- ;debug
- XREF word_out
-
- RTI_ISR:
- EventLoop:
- ;***************** NOTE ****************
- ; the menu timer is a general timer for
- ; what to display
- ;***************************************
- ; ========= wall clock ==========
- ;the event loop is configured (in main.asm) to run every 4 milliseconds
- LDD ms_counter ;counts the milliseconds for the wall clock
- ADDD #04 ;add 4 milleseconds evey time the event loop runs (effectively the count starts at 4)
- STD ms_counter ;store the ms_counter in memory (mostly for debugging)
- CPD #1004 ;check if one second has passed (accounting for the start at 4)
- BLE LessThanSec ;less than one second has passed, continue to other functions
- ;one second has passed
- MOVB #$FF,second_passed ;this flag is set here and cleared in wall.asm
- CLR ms_counter
-
- LessThanSec:;less than one second has passwed (do not fire a second passed event)
- ;don't do anything (except track the time) if the password is not set
- LDAA pw_set
- CMPA #$FF
- LBNE Return
-
- ;========= circualtion ===========
- ;circulation is always happening (if the password is set)
- ;the motor should spin as soon as the password is set
- JSR read_pot ;read the value of the pot into D
- STD word_out
- LDX #8 ;load the bottom part of the divide (forget what it's called)
- ;dividing 128 pot val. by 8 wields 16 different speeds possible
- IDIV ;value 1 through 16 is now in X
- XGDX ;put the value in D
- STAB fan_speed ;the lower byte of D is the fan speed, higher value for faster speed
-
- ;counter is in A
- LDAA circulation_count
- INCA
- STAA circulation_count
-
- ;from lab 6.3
- ;here, fan speed has replaced the pressed value
- CMPA fan_speed ;compare the counter to the fan speed
- LBGT FanOff ;turn the fan off (low PWM)
- FanOn: ;if the PWM should be high
- MOVB #$FF,dc_on ;set the PWM high
- BRA FanReset ;skip setting the pulse low
- ;LBLE SpinDC ;branch to the stepper spinner
-
- FanOff: ;turn off the motor's PWM (low cycle)
- CLR dc_on
- FanReset: ;check if the fan counter needsd to be reset
- ;acc. A still has the circulation count
- CMPA #15 ;16 is the max value of fan_speed
- LBLE DidMotor ;do not clear the count if the count is in line with the speed
- CLR circulation_count
- DidMotor: ;branch here if the motor PWM has been applied
- ;exit if the password is resetting
- LDAA pw_reset
- CMPA #$FF
- LBEQ Return
-
- ;exit if the password is required
- ;LDAA pw_required
- ;CMPA #$FF
- ;LBEQ Return
- ;======== menu ===============
- ;delay the menu change
- LDX menu_timer
- INX
- STX menu_timer
-
- ;the menu should change here
- LDX menu_timer
- CPX #300
- LBGE CycleMenu
-
- ;==========================
- LDX toast_timer
- INX
- STX toast_timer
-
- LDX toast_timer
- CPX #200
- LBGE HideTemperature
- ;====== watering ============
- ;delay the watering stop
- LDX watering_timer
- INX
- STX watering_timer
-
- ;run sprinker
- LDAA sprinkler_timer
- INCA
- STAA sprinkler_timer
-
- LDAA sprinkler_timer
- CMPA #7
- LBGE Sprinkle
-
- ;watering stop
- LDX watering_timer
- CPX #500
- LBGE StopWatering
-
- ;======= wall clock display ========
-
- LDX wall_timer
- INX
- STX wall_timer
-
- LDX wall_timer
- CPX #200
- LBGE HideTime
-
- ;======= menu options ===========
- ;call these here so that the counters can increment
- ;watering start
- LDAA pressed_num
- CMPA #$01
- BEQ StartWatering
-
- ;show temperature
- LDAA pressed_num
- CMPA #$02
- LBEQ DisplayTemperature
-
- ;show wall clock
- LDAA pressed_num
- CMPA #$03
- LBEQ DisplayTime
-
- ;set time and date
- LDAA pressed_num
- CMPA #$04
- LBEQ SetTime
-
- ;trigger password reset
- LDAA pressed_num
- CMPA #$05
- LBEQ ResetPassword
-
- ;======= temperature ========
- ;delay the temperature display stoppage
- ;LDX temp_timer
- ;INX
- ;STX temp_timer
-
- ;hide temperature
- ;LDX watering_timer
- ;CPX #750
- ;BEQ HideTemperature
-
- ;
- ;
- ;LDAA pressed_num ;input into A for comparison
- ;==================== menu items ======================
- ;CMPA #$01
- ;BEQ WaterPlants
-
- ;CMPA #$02 ;pressed_num is the selected menu option
- ;BEQ ShowTemperature ;menu option 1 is temperature
- ;======================================================
- ;
- ;
- ;
-
- ;return by default
- LBRA Return
- CycleMenu:
- ;reset the timer (s) and go to the next menu option
- MOVW #$0000,menu_timer ;reset menu timer
- ;track the menu option (this resets to 1 in menu.asm)
- LDAA menu_option_num
- INCA
- STAA menu_option_num
-
- ;exit
- LBRA Return
-
-
- StartWatering:
- ;water for a certain amount of time
- MOVW #$0000,watering_timer ;reset the watering timer
- MOVB #$FF,is_watering ;turn on the water
-
- ;hide the other options
- MOVB #$00,show_temperature
- MOVB #$00,display_time
-
- MOVB #$FF,pressed_num ;clear the pressed number value
- MOVB #$00,menu_active ;turn off the menu (dispay watering...)
- LBRA Return ;exit
-
- StopWatering:
- MOVW #$0000,watering_timer ;reset the watering timer
-
- LDAA is_watering ;check that watering needs to be stopped
- CMPA #$00
- LBEQ Return
-
- MOVB #$00,is_watering ;turn off the water
- MOVB #$FF,menu_active ;restore the menu display
- LBRA Return ;exit
- Sprinkle:
- ;the sprinkler timer controls the speed of the stepper motor
- CLR sprinkler_timer
-
- ;check that the watering state is active before firing an event
- LDAA is_watering
- CMPA #$FF
- LBNE Return
-
- ;instruct the watering subroutine to send a signal to the stepper motor
- MOVB #$FF,sprinkler_event
- ;exit
- LBRA Return
-
-
- DisplayTemperature:
- MOVW #$0000,toast_timer ;clear the temperature timer
-
- ;do not disrupt watering
- LDAA is_watering
- CMPA #$FF
- BEQ Return
- ;hide the other options
- MOVB #$00,menu_active ;hide the menu
- MOVB #$00,display_time ;hide the time
-
- MOVB #$FF,pressed_num ;clear the pressed number value
- MOVB #$FF,show_temperature ;set the show temperature flag
-
- BRA Return
-
- HideTemperature:
- MOVW #$0000,toast_timer ;clear the temperature timer
-
- LDAA show_temperature ;do nothing if temperature is not showing
- CMPA #$00
- LBEQ Return
- MOVB #$00,show_temperature ;clear the show temperature flag
- MOVB #$FF,menu_active ;restore the menu
- BRA Return
-
- DisplayTime:
- MOVW #$0000,wall_timer ;clear the clock display timer
-
- ;do not disrupt watering
- LDAA is_watering
- CMPA #$FF
- BEQ Return
-
- ;hide the other display options
- MOVB #$00,show_temperature ;hide the temperature
- MOVB #$00,menu_active ;hide the menu
-
- MOVB #$FF,display_time ;set the time display flag
- MOVB #$FF,pressed_num ;clear the pressed number
-
- BRA Return
-
- HideTime:
- MOVW #$0000,wall_timer ;clear the clock display timer
-
- LDAA display_time
- CMPA #$00
- LBEQ Return
- MOVB #$00,display_time ;clear the time display flag
- MOVB #$FF,menu_active ;re-activate the menu
-
- BRA Return
-
- SetTime:
- MOVB #$FF,pw_required
- BRA Return
-
- ResetPassword:
- MOVB #$FF,pw_reset
- BRA Return
-
- Return:
- BSET CRGFLG,$80
- RTI
-
-
-
|