// IntrptEx.c // // Motorola 68HC12 IRQ Interrupt Example Program // RPK // January 13, 1999 // // This program uses the IRQ to interrupt the main routine. // The IRQ pin - PE1 (# 44 on J8) will generate an interrupt // when it is pulled low (grounded). Each time it makes a // high to low transition, the interrupt service routine // IRQInt() is called and a message is printed. If PE1 is // held low, the routine will not be called again until the // pin goes high and is then pull low. // // This code was written and tested using Introl C 4.0. // #includes #include #include #include // interrupt service routine declaration __mod2__ void IRQInt(); void __main () { int choice; long i; // The IRQ is used to interrupt this module // Set up interrupt vectors DB12->SetUserVector(IRQ, IRQInt); DB12->printf("Use the EVB RESET button to exit. \n\n\r"); _H12INTCR=0xC0; // IRQ falling edge triggered choice=0; while(1) { // The strange overlap (overwriting the first output of choice seems to be necessary // to get around a bug in printf. The first parameter value is always wrong! DB12->printf("%i\rWaiting for an IRQ interrupt. %i \n\r",choice,choice); DB12->printf("\n\r"); choice=choice+1; for (i=0;i<65536;i++) // waste some time { ; } } } // IRQ interrupt routine // NOTE: this is an example of what NOT to do in an interrupt handler. No I/O should // be done in interrupt handlers since they are slow and the handler must be quick __mod2__ void IRQInt() { DB12->printf(" *** IRQI triggered ***\n\r"); // display message when triggered }