Download presentation
Presentation is loading. Please wait.
1
Interrupt-Driven State Machine
Lecture L4.2a
2
State Machine with Delay
3
Use Real-time Interrupt with 50 ms Period
State LED Delay (sec) S0 Red 0.5 S1 Yellow 1.0 S2 Green 0.75
4
State Machine with Delay
5
Data Structure Variable Value Dtime 1 Num_states 3 Cur_state S0 $80
10 S1 $40 S1t 20 S2 $20 S2t 15
6
$7B
7
; LED state machine example
ptp equ $ ; Port P ddrp equ $25A ; Direction ptj equ $ ; 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
8
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
9
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 ms ldaa #$80 staa crgint ;enable r ldx #rti_intser stx rti_ivec ;store rti int vector cli ;enable interrupts
10
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
11
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.