;Interrupt Programming with CodeWarrior on Freescale Project Board with HCS12 module ;Buzzer sounds continuously while waiting for AN Interrupt from Real Time Interrupt (RTI) ;PORTA.4 Toggle every Second using RTI (real time interrupt) ;Modified and tested by M. Mazidi from Example 11-18 of HCS12 textbook by Mazidi & Causey ;Remember RTI uses the XTAL freq. (not the bus Freq) which is XTAL=4 MHz on HCS12 MCU Module ;MAKE SURE to choose "absolute" for memory model(NO relocatable) when creating porject for Interrupts ;In CodeWarrior,Make sure you are in TBDML Mode before downloading ;Press F7 (to Make), then F5(Debug) to downLOAD,and F5 once more to start the program execution ABSENTRY Entry ; for absolute assembly: mark this as application entry point ; Include derivative-specific definitions INCLUDE 'mc9s12dp256.inc' ;CPU used by HCS12 MCU Module 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 Entry: LDS #$4000 ;Stack LDAA #$FF STAA DDRA ;Make PA7-PA0 as output BSET DDRP, %00010000 ;on the Project Board, the lower 4 bits of PA3-PA0 are connected to LEDs(LED1-LED4) permanently BCLR PTP, %00010000 ; and must be enabled by clearing bit P4 of PORTP ;We need connect 4 wires from LED5-LED8 to pins PA4-PA7 via J6 connector BSET DDRT,%00000001 ;PTT0 as Output pin for Buzzer on Project Board ;INTERRUPT SET-UP FOR RTI BSET CRGINT,%10000000 LDAA #%01111111 ;longest RTI is about 0.26 sec. Change this number to see toggling rate for RTI STAA RTICTL CLR TEMP CLR COUNT BSET DDRA,%00010000 ;Make PA4 and output CLI ;ENABLE INTERRUPTS GLOBALLY ;-------Sound the Buzzer at PTT0 forever and wait for interrupt BACK BSET PTT,%00000001 ;PTT0=1 JSR DELAY BCLR PTT,%00000001 ;PTT0=0 JSR DELAY BRA BACK ;Keep sounding buzzer ;--------------RTI INTERRUPT SERVICE ROUTINE. Toggle the PORTA4 every second RTI_ISR INC COUNT LDAA COUNT CMPA #4 ; 4 x 0.26 sec = 1 sec. Also change this number to see what happens BNE OVER LDAA TEMP EORA #%00010000 STAA TEMP STAA PORTA CLR COUNT OVER BSET CRGFLG,%10000000 ;clear the RTI flag for next round RTI ;Return from RTI ISR ;----------END OF ISR ;----------DELAY DELAY PSHA ;Save Reg A on Stack LDAA #10 ;Change this value to hear STAA R3 ;different buzzer sound ;--10 msec delay. The HCS12 MCU Module works with XTAL=4MHz ;Freq. for Instruction Clock Cycle is 2MHz (1/2 of 4MHz). ;(1/2MHz) x 10 Clk x10x200=10 msec. Overheads are excluded in this calculation. L3 LDAA #10 STAA R2 L2 LDAA #200 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