//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. 7 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 #include /* common defines and macros */ #include "derivative.h" /* derivative-specific definitions */ void MSDelay(unsigned int); void main(void) { /* put your own code here */ DDRA = 0xFF; //PORTA as output since LEDs are connected to it DDRP = DDRP | 0b00110000; //PP4 and PP5 as output. On the Project Board, a)the lower 4 pins of PA3-PA0 are connected to LEDs(LED1-LED4) PTP = PTP & 0b11001111; //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) DDRT = DDRT | 0b00000001; // PTT0 as output for Buzzzer on Project Board PIEP = 0xFF; //enable PTP interrupt PPSP = 0xFF; //Make it rising Edge-Trig (change to 0 to see the falling-edge. __asm CLI; //Enable interrupts globally for(;;) { //do something PORTA = PORTA ^ 0b00000001; //Toggle PORTA0 while waiting for Interrupt MSDelay(100); } //stay here until interrupt come. } //PTP Interrupt, Moving any of Push Button Switches of PB1 and PB2 will sound the buzzer for short period of time interrupt (((0x10000-Vportp)/2)-1) void PORTP_ISR(void) { unsigned char x; for (x=0;x<100;x++) //Upon PTP Interrupt (any of push Button PB1 and PB2 switch going from H-to-L) will sound the buzzer for a short period { PTT = PTT ^ 0b00000001; //toggle PT0 for Buzzer MSDelay(10); //how long the Buzzer should sound. During the buzzer sound PORTA0 stops toggling. Why? } PIFP = PIFP | 0xFF; //clear PTP 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