in detail explain each line of this code and how it works. #include Reg9S12.h UserTimerCh5 equ $3E64 hi_freq equ 1500 ;delay count for 1000 Hz with 1:8 precaler lo_freq equ 5000 ;delay count for 300 Hz with 1:8 prescaler org $1500 delay ds.w 1 ;store the delay for output-compare org $2000 lds #$2000 movw #OC5_isr,UserTimerCh5 ;initialize the interrupt vector entry movb #$90,TSCR1 ;enable TCNT, fast timer flage clear movb #$03,TSCR2 ;set main timer prescaler to 8 bset TIOS,#$20 ;enable Ch.5 for output compare movb #$04,TCTL1 ;select toggle for OC5 pin action(OM5:OL5=01) ldd #hi_freq ;use high frequency delay count first std delay ;bw use high-frequency delay count first ldd TCNT ;start the high frequency sound addd delay std TC5 bset TIE,#$20 ;enable OC5 interrupt (TIE is equivalent to TMSK1 in REG9S12.h) cli ;enables i-bit interrupts forever ldy #50 ;wait for 1 second jsr delay10ms movb #$00, TCTL1 ; clear all channels ldy #50 ; hold it for 0.5 channel jsr delay10ms movb #$04, TCTL1 ;open up channel 5 movw #lo_freq,delay ;switch to low-frequency delay count ldy #100 ;wait for 0.5 second jsr delay10ms movb #$00, TCTL1 ; clear all channels ldy #50 jsr delay10ms movb #$04, TCTL1 movw #hi_freq,delay ;switch to high-frequency delay count bra forever OC5_isr ldd TC5 addd delay std TC5 rti ;*************************************************** ;The following subroutine creates a time delay that ;is equal to [y] x 10 ms. The timer prescaler is 1:8 ;*************************************************** delay10ms pshd ;save Accumulator D bset TIOS,#$01 ;enable OC0 ldd TCNT again1 addd #30000 ;start an output compare operation std TC0 ;with 10 ms time delay brclr TFLG1,#$01,* ldd TC0 dbne y,again1 bclr TIOS,#$01 ;disable OC0 puld ;restore Accumulator D rts end
in detail explain each line of this code and how it works.
#include Reg9S12.h
UserTimerCh5 equ $3E64
hi_freq equ 1500 ;delay count for 1000 Hz with 1:8 precaler
lo_freq equ 5000 ;delay count for 300 Hz with 1:8 prescaler
org $1500
delay ds.w 1 ;store the delay for output-compare
org $2000
lds #$2000
movw #OC5_isr,UserTimerCh5 ;initialize the interrupt
movb #$90,TSCR1 ;enable TCNT, fast timer flage clear
movb #$03,TSCR2 ;set main timer prescaler to 8
bset TIOS,#$20 ;enable Ch.5 for output compare
movb #$04,TCTL1 ;select toggle for OC5 pin action(OM5:OL5=01)
ldd #hi_freq ;use high frequency delay count first
std delay ;bw use high-frequency delay count first
ldd TCNT ;start the high frequency sound
addd delay
std TC5
bset TIE,#$20 ;enable OC5 interrupt (TIE is equivalent to TMSK1 in REG9S12.h)
cli ;enables i-bit interrupts
forever ldy #50 ;wait for 1 second
jsr delay10ms
movb #$00, TCTL1 ; clear all channels
ldy #50 ; hold it for 0.5 channel
jsr delay10ms
movb #$04, TCTL1 ;open up channel 5
movw #lo_freq,delay ;switch to low-frequency delay count
ldy #100 ;wait for 0.5 second
jsr delay10ms
movb #$00, TCTL1 ; clear all channels
ldy #50
jsr delay10ms
movb #$04, TCTL1
movw #hi_freq,delay ;switch to high-frequency delay count
bra forever
OC5_isr ldd TC5
addd delay
std TC5
rti
;***************************************************
;The following subroutine creates a time delay that
;is equal to [y] x 10 ms. The timer prescaler is 1:8
;***************************************************
delay10ms pshd ;save Accumulator D
bset TIOS,#$01 ;enable OC0
ldd TCNT
again1 addd #30000 ;start an output compare operation
std TC0 ;with 10 ms time delay
brclr TFLG1,#$01,*
ldd TC0
dbne y,again1
bclr TIOS,#$01 ;disable OC0
puld ;restore Accumulator D
rts
end

Step by step
Solved in 2 steps









