;ECE331 Quiz 7 10/1/2009  Name:__________________________________ CM#______


;Fill in the missing blanks in the program below that uses the hardware timer 
;      in interrupt-driven fashion to produce a 1 Hz square wave on PT5, 
;       assuming a 2 MHz bus clock (as on our laboratory microcontroller modules.)

            XDEF Entry            ; export 'Entry' symbol
            ABSENTRY Entry        ; for absolute assembly: mark this as application entry point

            INCLUDE 'mc9s12c128.inc'


            ORG   $4000
Entry:      LDS   #$1000          ; Initialize the stack pointer

            MOVB  _______________________     ; Make Timer Tick Interval = 64/(2MHz) = 32 microsec
                                              
            BSET  _______________________     ; Make TC5 an output compare register
            
            BSET  _______________________     ; Enable TC5 interrupts
            
            MOVB  _______________________     ; Make Channel 5 Output Compare Event Toggle PT5
            
            BSET ________________________     ; Enable Timer     
                             
            LDD _________________________     ; 
            
            ADDD TCNT
            
            STD  _______________________      ; Schedule first output compare interrupt
                                              ; to occur in 500 ms.
                                              
            MOVB _______________________      ; Clear TC5 interrupt flag
            
            _______________                   ; Globally enable interrupts
LoopHere:   BRA  LoopHere                     ; Loop here while timer periodically interrupts
;*********** Interrupt Service Routine Starts Here *************

TC5ISR      MOVB _______________________ ; Clear TC5 interrupt flag

            LDD ________________________
            
            ADDD _______________________
            
            STD  _______________________  ;Schedule next output compare event in 0.5 s
            RTI
                        
            ORG   $FFFE           ;
            DC.W  Entry           ; Reset Vector
            ORG   $FFE4           
            DC.W  TC5ISR          ;TC5 Interrupt Vector