110 likes | 289 Views
Interrupt-Driven State Machine. Lecture L4.2a. State Machine with Delay. Use Real-time Interrupt with 50 ms Period. State Machine with Delay. Data Structure. $7B. ; LED state machine example ptp equ $258 ; Port P ddrp equ $25A ; Direction
E N D
Interrupt-DrivenState Machine Lecture L4.2a
; LED state machine example ptp equ $258 ; Port P ddrp equ $25A ; Direction ptj equ $268 ; Port J ddrj equ $26A ; Direction rti_ivec equ $0FF2 crgflg equ $0037 crgint equ $0038 rtictl equ $003b Note: Should be $0FF0. Monitor error
ORG $800 dtime db 1 num_states db 3 cur_state db 3 s0 db $80 ;red led s0t db 10 ;1/2 sec delay s1 db $40 ;yellow led s1t db 20 ;1 sec delay s2 db $20 ;green led s2t db 15 ;3/4 sec delay
ORG $4000 main jsr portp_init jsr rti_init mn1 bra mn1 portp_init ldaa #$E0 ;PP7..PP5 outputs staa ddrp ldaa #0 staa ptp ;leds off rts rti_init sei ;disable interrupts ldaa #$7b staa rtictl ;set rti to 49.15 ms ldaa #$80 staa crgint ;enable r ldx #rti_intser stx rti_ivec ;store rti int vector cli ;enable interrupts rts
rti_intser ldaa dtime deca ;dec dtime bne exit ;if not zero ldab cur_state cmpb num_states ; if cur_state = num_state bne ri1 clrb stab cur_state ; reset cur_state to 0 ri1 lslb ; ptr = cur_state * 2 ldx #s0 ; x -> state 0 abx ; x -> next state ldaa 0,x ; get state value staa ptp ; and display it inc cur_state ; update cur_state ldaa 1,x ; get delay time exit staa dtime ; and store it in dtime ldaa #$80 staa crgflg ;clear rti flag rti
ORG $800 dtime db 1 num_states db 3 cur_state db 3 s0 db $80 ;red led s0t db 10 ;1/2 sec delay s1 db $40 ;yellow led s1t db 20 ;1 sec delay s2 db $20 ;green led s2t db 15 ;3/4 sec delay