//Example of using C with interrupts
//Bounceless SW connected to Pin 2 (PE1/IRQ input)
//LED connected to PT1
//Interrupt count set up on PortM.
//Interrupt vector for IRQ is initialized to 
// point to the IRQISR routine at the end of 
// the .PRM file.
#include <hidef.h>      /* common defines and macros */
#include <mc9s12c32.h>     /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12c32"
void 	IRQISR(void);
unsigned char cnt;      /* This is global variable is used for
                        communicating between main program
                        and ISR, so it MUST be defined outside
                        of the main program   */
void main(void) {
    	DDRM    	= 0xFF;
    	cnt     	= 0;
    	PTM       = 0;
    	DDRT    	= 0x02;    	  /* configure PT1 pin for output */
    	PTT     	= 0x02;   	  /* enable LEDs to light */
    	INTCR   	= 0xC0;     	/* enable IRQ (PE1/IRQ, Pin2) interrupt
    	                           on falling edge */
    	asm("cli");         		/* enable interrupt globally */
    	while(1);           		/* wait for interrupt forever */
}

interrupt void IRQISR(void)
{
     	cnt++;
     	PTM = cnt;   //Increment count on Port M
     	PTT = ~PTT;  // Toggle LED on PT1
     	//Since IRQ input is made edge sensitive,
     	//The IRQ interrupt is automatically
     	//relaxed after the interrupt routine is 
     	//entered, so there is no need to "shut the
     	//baby up" as with most other"I-bit related"
     	//interrupts.  Upon return from IRQISR, the
     	//interrupt is already inactive.
}