Hi friend,
Please excuse me, I didn't get you. actually what your doing there?
I guess you need two signals from op-amps (using two external interrupt.. please note it external interrupt is only a trigger like rising or falling edge of the signal).you wish to calculate time difference between both interrupt events. am I right friend?
configure both interrupt and timer function.
set a higher priority to any one of external interrupt. give second high priority to 2nd external interrupt.give lowest priority to timer interrupt.please enable timer when first external interrupt service routine occurs and stop timer in second external interrupt end.or else read timer value from TMR register.
Programming External Interrupts[/SIZE]
The external interrupts are the interrupts received from the (external) devices interfaced with the microcontroller. They are received at INTx pins of the controller. These can be level triggered or edge triggered. In level triggered, interrupt is enabled for a low at INTx pin; while in case of edge triggering, interrupt is enabled for a high to low transition at INTx pin. The edge or level trigger is decided by the TCON register. The TCON register has following bits:
Setting the IT0 and IT1 bits make the external interrupt 0 and 1 edge triggered respectively. By default these bits are cleared and so external interrupt is level triggered.
Note : For a level trigger interrupt, the INTx pin must remain low until the start of the ISR and should return to high before the end of ISR. If the low at INTx pin goes high before the start of ISR, interrupt will not be generated. Also if the INTx pin remains low even after the end of ISR, the interrupt will be generated once again. This is the reason why level trigger interrupt (low) at INTx pin must be four machine cycles long and not greater than or smaller than this.
Following are the steps for using external interrupt :
1. Enable external interrupt by configuring IE register.
2. Write routine for external interrupt. The interrupt number is 0 for EX0 and 2 for EX1 respectively.
Example code
//Level trigger external interrupt
void main()
{
IE = 0x81;
while(1);
}
void ISR_ex0(void) interrupt 0
{
<body of interrupt>
}
Example code
//Edge trigger external interrupt
void main()
{
IE = 0x84;
IT1 = 1;
while(1);
}
void ISR_ex1(void) interrupt 2
{
<body of interrupt>
}
a small demo
pfa)
one more external interrupt example
https://saeedsolutions.blogspot.in/2012/06/8051-at89c51-external-interrupt-int0.html
Best wishes,