//Interrupt Programming with CodeWarrior on 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 by M. Mazidi from Example 11-18C 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 "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 #include /* common defines and macros */ #include "derivative.h" /* derivative-specific definitions */ void MSDelay(unsigned int); unsigned int COUNT; void main(void) { DDRA = 0xFF; //PORTA as output since LEDs are connected to it DDRP = DDRP | 0b00010000; //on Project Board, the lower 4 bits of PA3-PA0 are connected to LEDs(LED1-LED4) permanently PTP = PTP & 0b11101111; //and must be enabled by clearing bit P4 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) DDRT = 0b00000001; //PT0 = output for Buzzer //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 PTT0 forever and wait for interrupt { //do something PTT = PTT ^ 0b00000001; //sound the buzzer continuously MSDelay(100); //chnage this delay to hear different sound } //stay here in this loop until an interrupt comes in. } //------ Real Time Interrupt ISR (Toggling the PORTA4 every Sec.) interrupt (((0x10000-Vrti)/2)-1) void RTI_ISR(void) { COUNT++; if(COUNT==2) //4 x 0.26 sec = 1 sec also change this number for shorter or longer durations { PORTA = PORTA ^ PORTA_BIT4_MASK; //Toggle PORTA.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