Aditya kiran R.S Mangipudi

Basic interrupt handling in MC9S12DT256B

Discussion created by Aditya kiran R.S Mangipudi on Mar 10, 2009
Latest reply on Mar 10, 2009 by Aditya kiran R.S Mangipudi

Hello, I'm new to microprocessors and I just began writing interrupt handling for MC9S12DT256B. I contacted freescale and with their assistance, I was able to manage to generate my code for handling interrupts. (with a lot of mistakes though :smileyhappy:)


My requirement:- The aim is to generate external interrupts on pins 0 and 1 of PORT P of MC9S12DT256B. The figure is shown in the attachment. The outputs of 2 NAND gates (Q and Q^) are given as inputs to pins 0 and 1 of PORT P respectively (so if 1 is high, the other is obviously low). So if the switch is pressed, say interrupt was generated on pin 1 and vice versa. So if pin 1 of PORT P interrupts, I want LED 2 to flash up and if pin 0 interrupts, I want LED 1 to flash up. In my code, I am printing character 'c' on the LCD and I just wanted to make sure that when an interrupt occurs, I show some way that I'll be able to handle it and for the same sake, I tried to stop the printing of 'c' temporarily and show the LED that was lit and resume printing 'c' after a few seconds to ensure that the interrupt was handled correctly. I'm even displaying my source code beneath, kindly help me with your expertise. This is my source code :-



#include <hidef.h>    
#include <mc9s12dt256.h>
#include "pbs12dslk.h" 
#include "lcd.h"        
#include "SCI.h"        
#pragma LINK_INFO DERIVATIVE "mc9s12dt256"
 /* I think I'm handling the interrupts here */


 interrupt 38 void my_interrupt(void)
   if((PIFP & 0x01) > 0)  // if interrupt occurs on pin 0   
      PBMCUSLK_LED1 = 1;
      PBMCUSLK_LED2 = 0;  
      PIFP = 0x01; // clearing the flag register
   else if((PIFP & 0x02) > 0) // if interrupt occurs on pin 1   
    PBMCUSLK_LED1 = 0;
    PBMCUSLK_LED2 = 1;
    PIFP = 0x02;  // clearing the flag register
 /* The main code starts here */


int main()
   unsigned char cha='c';
   unsigned char *p;
   int i,j;
   DDRP = 0x00;  //  Using all the pins of PORT P as input
   PERP = 0x03;  //
   PPSP = 0x03;  //  pins 0 and 1 set to be pulled down and interrupt occurs on rising edge
   PIEP = 0x03;  //  pins 0 and 1 set to enable the interrupts
   EnableInterrupts;   // This is the part that I'm confused of, will saying EnableInterrupts; take me to the ISR mentioned above?
   return 0;