//RTI (Real Time Interrupt) programming with CodeWarrior on HCS12G128 Tower Module //PTT4 toggles continuously while waiting for an Interrupt from RTI //PTT7 Toggle every Second using RTI (real time interrupt) //By default RTI uses an internal 1 MHz oscillator as clock source //Make sure the jumers for LED1 and LED4 are set //Modified from example 11-18C of HCS12 textbook by Mazidi & Causey. //Thanks to Shu-Jen Chen for his contribution //See Chapter 10 of HCS12G Ref. Manual for RTI register name and information. //The HCS12G series has different name for the RTI registers than the HCS12D covered in the Mazidi textbook //Make sure to choose "minimal startup code" and "Small" for memory model(no banked) when creating project for Interrupts #include /* common defines and macros */ #include "derivative.h" /* derivative-specific definitions */ void MSDelay(unsigned int); unsigned int COUNT; void main(void) { DDRT = 0b10010000; //PT7 and PT4 = output //Real Time Interrupt (RTI) setup. See chapter 10 section 10.3.2 for registers. //Notice Register names for RTI in HCS12G128 are different from what is in the Mazidi textbook //Notice from Table 10-11 the HCS12G128 also supports Decimal Freq Divide for RTI. //The decimal option for RTI divide did not exist in HCS12Dxx. Table 11-5 in Mazidi textbook is for HCs12D chips. CPMUINT = CPMUINT | CPMUINT_RTIE_MASK; //enable RTI. See chapter 10.2 for HCS12G register names CPMURTI = 0x80 + 0x39; // 1 MHz / (10 * 10 * 10^3) = 10 Hz (Change this number to see toggling rate for RTI) COUNT = 0; __asm CLI; //Enable interrupts globally //EnableInterrupts; //another way to Enable interrupts globally for(;;) // Toggle PTT4 forever and wait for interrupt { //do something PTT = PTT ^ 0b00010000; //toggle PT4 continuously MSDelay(100); } //stay here in this loop until an interrupt comes in. } //------ Real Time Interrupt ISR (Toggling the PORTT7 every one Sec.) interrupt (((0x10000-Vrti)/2)-1) void RTI_ISR(void) //interrupt VectorNumber_Vrti void RTI_ISR(void) //another way to declare interrupt { COUNT++; if(COUNT == 10) //10 x 0.1 sec = 1 sec, also change this number for shorter or longer RTI toggling durations { PTT = PTT ^ 0x80; //Toggle PTT7 COUNT = 0; } CPMUFLG = CPMUFLG | CPMUFLG_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