//Interrupt Programming with CodeWarrior on Dragon12+ Using PTH Interrupt. //An LED on PORTB toggles continuously while waiting for Interrupt to come in from DIP Switches on PTH //Moving any bit of PTH DIP switch from H-to-L will interrupt the main and sound the buzzer for a short period of time. //See Chapter 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 #include /* common defines and macros */ #include "derivative.h" /* derivative-specific definitions */ void MSDelay(unsigned int); void main(void) { DDRB = 0xFF; //PTB as output for LEDs DDRJ = 0xFF; //PTJ as output DDRT = 0xFF; //PORTT as output PTJ = 0x0; //Let PTB show data. Needed by Dragon12+ board //PORTH interrupt setup DDRH = 0x00; //PTH as input PIEH = 0xFF; //enable PTH interrupt PPSH = 0x0; //Make it Edge-Trig. __asm CLI; //Enable interrupts globally for(;;) { //do something PORTB = PORTB ^ 0b00000001; //Toggle PB0 while waiting for Interrupt MSDelay(100); } //stay here until interrupt come. } //PTH Interrupt, Moving any of DIP Switches of PORTH from High-to-Low, will sound the buzzer for short period of time interrupt (((0x10000-Vporth)/2)-1) void PORTH_ISR(void) { unsigned char x; for (x=0;x<100;x++) //Upon PTH Interrupt (any of DIP SWitch going from H-to-L) will sound the buzzer for a short period { PTT = PTT ^ 0b00100000; //toggle PT5 for Buzzer MSDelay(10); //how long the Buzzer should sound. During the buzzer sound PB0 stops toggling. Why? } PIFH = PIFH | 0xFF; //clear PTH Interupt Flags for the next round. Writing HIGH will clear the Interrupt flags } void MSDelay(unsigned int itime) { unsigned int i; unsigned int j; for(i=0;i