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 )
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 */
#pragma CODE_SEG NON_BANKED
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
}
return;
}
#pragma CODE_SEG DEFAULT
/* The main code starts here */
int main()
{
unsigned char cha='c';
unsigned char *p;
int i,j;
p=&cha;
LCDInit();
INIT_PBMCUSLK_LEDs;
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?
while(1)
{
LCDClearDisplay();
LCDPutString(p);
}
DisableInterrupts;
return 0;
}
I just made a correction to the interrupt intialization, the vector # must be 56 in decimal (since it is 38 hexa). Even then, my code never enters into the interrupt routine.
Change made:- interrupt 0x38 void my_interrupt(void) instead of
interrupt 38 void my_interrupt(void)