//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) //Modified from example 11-18C of HCS12 textbook by Mazidi & Causey. //Remember RTI uses the XTAL freq. (not the bus Freq) which is XTAL=8 MHz on Dragon12+ board //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); unsigned int COUNT; void main(void) { DDRB = 0xFF; //PORTB =output for LEDs DDRJ=0xFF; //PTJ = output for LEDs DDRT = 0xFF; //PTT = output for Buzzer PTJ = 0x0; //Needed by Dragon12+ board //Real time Interrupt (RTI) setup CRGINT = CRGINT | CRGINT_RTIE_MASK; //enable RTI RTICTL = 0b01111111; //(longest RTI is about 0.13 sec) Change this number to see toggling rate for RTI COUNT = 0; __asm CLI; //Enable interrupts globally for(;;) // Sound the Buzzer at PTT5 forever and wait for interrupt { //do something PTT = PTT ^ 0b00100000; //sound the buzzer continuously MSDelay(100); } //stay here in this loop until an interrupt comes in. } //------ Real Time Interrupt ISR (Toggling the PORTB4 every Sec.) interrupt (((0x10000-Vrti)/2)-1) void RTI_ISR(void) { COUNT++; if(COUNT==8) //8 x 0.13 sec = 1 sec also change this number for shorter or longer durations { PORTB = PORTB ^ PORTB_BIT4_MASK; //Toggle PORTB.4 COUNT = 0; } CRGFLG = CRGFLG | CRGFLG_RTIF_MASK; //clear it for next round } //-------end of ISR void MSDelay(unsigned int itime) { unsigned int i; unsigned int j; for(i=0;i