Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

?Add comments for each assembly line used and explain its operation. What is the

ID: 3679324 • Letter: #

Question

?Add comments for each assembly line used and explain its operation. What is the rate that Timer Interrupt happens? Modify the program to change the flash rates to 1 second and 60 seconds. Can we make a clock using this timer?

Function: 500 Hz square wave routine using output comparator 6 It generates a 500Hz square wave on PBO LED (pin 24 of the MCU) and a 2Hz square wave on PB7 LED (pin 31 of the MCU). PBO: equ 1 DB6: equ $40 TB1MS: eq 24000;1ms time base of 24,000 instruction cycles : 24.000 x 1124MHz = 1ms at 24 MHz bus speed REGBLK: eq $0 #include reg9s12.h include register equates STACK: equ 2000 org $1000 count250: mb 1 org $2000 start: lds #STACK Idx #timerG st 3E62 ldx #REGBLK ldaa #Sff staa ddrb,x staa ddrp,x staa ddrj,x ; initialize the intvetctor ; make port B an output port make port P an output port make port J an output port ;make PJ1 low to enable LEDs ldaa #50f staa ptp,x turn off 7-segment display and RGB LED ldaa #S80 staa tscr,x ldaa #DB6 staa tios,x staa msk1,x cli back: Idaa count250 ; portp 00001111 ;enable timer ; select t6 as an output compare cmpa #250 bne back clr count250 Idaa portb eora #$80 staa portb jmp back timer6: ldx #REGBLK inc count250 Idd #TBIMS ; reload the count for 1 ms time base addd tc6,x std tc6,x ldaa #DB6 staa lg1,x Idaa portb eora #1 staa portb rti toggle the PB7 ever 250ms ; clear flag ; toggle the PB0 org $3E62 fdb timer6 end

Explanation / Answer

PB0:    equ      1     :left byte one unit

DB6:   equ      $40   : data byte at memory location

;

TB1MS:                      equ      24000 ; 1ms time base of 24,000 instruction cycles

;                                               ; 24,000 x 1/24MHz = 1ms at 24 MHz bus speed

;DELAY_TIME:        equ      36000 ; 36000 X 5 ms= 180 sec = 3 min

DELAY_TIME:         equ      5000    ; 5000 X 1 ms= 5 sec

REGBLK:                   equ      $0

#include        reg9s12.h           ; include register equates

            org       $1000

;

flag_5s:           rmb      1

cnt_5s:             rmb      2

STACK:          equ      $2000

            org       $2000

start:

            lds       #STACK

            ldx       #timer6

            stx       $3E62              ; initialize the int vetctor

            ldx       #REGBLK

            ldaa     #$ff

            staa      ddrb,x             ; make port B an output port

            staa      ddrp,x             ; make port P an output port

            staa      ptp,x                ; turn off 7-segment LED display

          staa      ddrj,x              ; make port J an output port

        clr     ptj,x                        ; make PJ1 low to enable LEDs

            ldaa     #$80

            staa      tscr,x               ; enable timer

            ldaa     #DB6

            staa      tios,x               ; select t6 as an output compare         

            staa      tmsk1,x

            cli

        bset    portb,x PB0     ; turn on LED PB0

            jsr        delay_5s

            bclr    portb,x PB0     ; turn off LED PB0

stp:      jmp      stp

delay_5s:

            clr        cnt_5s

            clr        cnt_5s+1

            clr        flag_5s

delay: ldaa     flag_5s

            beq      delay

            rts

timer6:

            ldx       cnt_5s

            inx

            stx       cnt_5s

            cpx      #DELAY_TIME

            bne      tmr6

            clr        cnt_5s

            clr        cnt_5s+1

            ldaa     #1

            staa      flag_5s

            rti

tmr6:    ldx       #REGBLK                 

            ldd       #TB1MS                     ; reload the count for 1 ms time base

            addd    tc6,x   

            std       tc6,x

            ldaa     #DB6

            staa      tflg1,x             ; clear flag

        rti

            org       $3E62

            fdb      timer6

            end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote