;Interrupt Programming with CodeWarrior on Project Board with HCS12 MCU Module Using PTP Interrupt. ;An LED on PORTA toggles continuously while waiting for Interrupt to come in from push Button Switches on PB1 or PB2 ;Pressing any of PB1 or PB2 Push Button switches will interrupt the main and sound the buzzer for a short period of time. ;before you run this program, run the Push Button PB1-PB2 program on this website to establish the fact that the PB1 and PB2 work. ;See Chapter 11 of HCS12 textbook by Mazidi & Causey ;The lower 4 bits of PA3-PA0 (pins of HCS12 CPU) are connected to LEDs(LED1-LED4 on J10) permanently ;and must be enabled by clearing bit P4 of PORTP. Also set the LED jumper on UFEA jumpers next to Buzzer ;We also need to connect 4 wires from LED5-LED8 (J10) to pins PA7-PA4 via J6 connector ;The lower 2 bits of PP1-PP0 (pins of HCS12 CPU) are connected to Push Buttons of PB1 and PB2 permanently ;and must be enabled by clearing bit P5 of PORTP. Also set the PB jumper on UFEA jumpers next to Buzzer ;On HCS12 MCU Module itself ;a)MAKE SURE BOTH jumpers for PP0 and PP1 are removed (SW1 and SW2). ;b)Also Make sure 8 Jumpers (SW3-1 to SW3-4 and LED1-LED4) on HCS12 MCU module are also removed ;Written and tested by M. Mazidi using Examples in chap. 11 of HCS12 textbook by Mazidi & Causey. ;Make sure to choose "minimal startup code" and "Small" for memory model(no banked) 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 board ;----------------------USE $1000-$2FFF for Scratch Pad R1 EQU $1001 R2 EQU $1002 R3 EQU $1003 R4 EQU $1004 ;how long to sound the buzzer. During the buzzer sound LED stops toggleing. Why? ;code section ORG $4000 ;Flash ROM address Entry: LDS #$4000 ;Stack LDAA #$FF STAA DDRA ;Make PA7-PA0 as output BSET DDRP, %00110000 ;the lower 4 bits of PA3-PA0 are connected to LEDs(LED1-LED4) permanently BCLR PTP, %00110000 ; Make PP4 and PP5 as output. On the Project Board, a)the lower 4 pins of PA3-PA0 are connected to LEDs(LED1-LED4) ;and b)the PP0 and PP1 pins are connected to PB1 and PB2 push buttons. c) They mut be enabled by clearing pins P4 and P5 of PORTP ;on Project Board,we need to connect 4 wires from LED5-LED8 (J10) to pins PA4-PA7 via J6 connector (pins 25,27,29,31) ;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 ; INTERRUPT SET-UP FOR PTP Interrupt LDAA #$FF ; STAA PIEP ;Enable PTP interrupt LDAA #$00 STAA PPSP ;Make PTP positive Edge-Trigger. CLI ;ENABLE INTERRUPTS GLOBALLY ;-------Toggle PA0 forever and wait for interrupt BACK BSET PORTA,%00000001 ;PORTA0=1 JSR DELAY BCLR PORTA,%00000001 ;PORTA0=0 JSR DELAY BRA BACK ;Keep Toggling PA0, while waiting for Interrupt to come in ;---end of main program ;------------------------------------------------------- ;---PTP INTERRUPT SERVICE ROUTINE. Pressing any of Push Button Switches of PB1 and PB2 will sound the buzzer for short period of time PTP_ISR LDAA #5 STAA R4 ;how long the buzzer should sound OVER BSET PTT, %00000001 ;PTT0 as output for Buzzzer on Project Board JSR DELAY BCLR PTT, %00000001 JSR DELAY ;Upon PTP Interrupt (any of push Button PB1 and PB2 switch going from H-to-L) will sound the buzzer for a short period DEC R4 BNE OVER LDAA #$FF ;Clear the PTP Interrupt flags for next round STAA PIFP ;Writing HIGH will clear the Interrupt Flag. RTI ;Return from ISR to main program ;----------DELAY DELAY PSHA ;Save Reg A on Stack LDAA #10 ; STAA R3 ; ;--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 $FF8E ;Vector table location for PTP interupt DC.W PTP_ISR ORG $FFFE DC.W Entry ;Reset Vector. CPU wakes here and it is sent to start of the code at $4000