;Interrupt Programming with CodeWarrior on Dragon12+ with Real Time Interrupt (RTI) ;Buzzer sounds continuously while waiting for AN Interrupt ;PORTB.4 Toggle every Second using RTI (real time interrupt) ;Remember RTI uses the XTAL freq. (not the bus Freq) which is XTAL=8 MHz on Dragon12+ board ;MAKE SURE to choose "absolute" for memory model(NO relocatable) when creating porject for Interrupts ;Modified from example 11-18 by Mazidi & Causey ABSENTRY Entry ; for absolute assembly: mark this as application entry point ; Include derivative-specific definitions INCLUDE 'mc9s12dp256.inc' ;CPU used by Dragon12+ board ;----------------------USE $1000-$2FFF for Scratch Pad R1 EQU $1001 R2 EQU $1002 R3 EQU $1003 ORG $1200 TEMP DC.B 1 COUNT DC.B 1 ;code section ORG $4000 ;Flash ROM address for Dragon12+ Entry: LDS #$4000 ;Stack LDAA #$FF STAA DDRB ;MAKE PORTB AN OUTPUT PORT BSET DDRJ,%00000010 ;MAKE PORTJ1 AN OUTPUT PIN BCLR PTJ,%00000010 ;TURN OFF PORTJ1 TO ALLOW LEDs ON PORTB TO SHOW DATA BSET DDRT,%00100000 ;PTT5 as Output pin for buzzer ;INTERRUPT SET-UP FOR RTI BSET CRGINT,%10000000 LDAA #%01111111 ;longest RTI is about 0.13 sec Change this number to see toggling rate for RTI STAA RTICTL CLR TEMP CLR COUNT BSET DDRB,%00010000 ;Make PB4 and output CLI ;ENABLE INTERRUPTS GLOBALLY ;-------Sound the Buzzer at PTT5 forever and wait for interrupt BACK BSET PTT,%00100000 ;PTT5=1 JSR DELAY BCLR PTT,%00100000 ;PTT5=0 JSR DELAY BRA BACK ;Keep sounding buzzer ;--------------RTI INTERRUPT SERVICE ROUTINE. Toggle the PORTB4 every second RTI_ISR INC COUNT LDAA COUNT CMPA #8 ; 8 x 0.13 sec = 1 sec. Also change this number for shorter or long BNE OVER LDAA TEMP EORA #%00010000 STAA TEMP STAA PORTB CLR COUNT OVER BSET CRGFLG,%10000000 ;clear the RTI flag for next round RTI ;Return from RTI ISR ;----------DELAY DELAY PSHA ;Save Reg A on Stack LDAA #100 ;Change this value to hear STAA R3 ;different Buzzer sounds ;--1 msec delay. The Serial Monitor works at speed of 48MHz with XTAL=8MHz on Dragon12+ board ;Freq. for Instruction Clock Cycle is 24MHz (1/2 of 48Mhz). ;(1/24MHz) x 10 Clk x240x10=1 msec. Overheads are excluded in this calculation. L3 LDAA #10 STAA R2 L2 LDAA #240 STAA R1 L1 NOP ;1 Intruction Clk Cycle NOP ;1 NOP ;1 DEC R1 ;4 BNE L1 ;3 DEC R2 ;Total Instr.Clk=10 BNE L2 DEC R3 BNE L3 ;-------------- PULA ;Restore Reg A RTS ;------------------- ;************************************************************** ;* Interrupt Vectors * ;************************************************************** ORG $FFF0 ;Vector table location for RTI interupt DC.W RTI_ISR ORG $FFFE DC.W Entry ;Reset Vector. CPU wakes here and it is sent to start of the code at $4000