raja_karthick
raja_karthick
Branch Unspecified
18 Mar 2016

INTERRUPTS- PIC16F877A

hi frnds. i am working on pic16f877a controller. i have a doubt, can we use both RB0/EXT interrupt and RB PORT CHANGE interrupt in the same isr, with each interrupt signal triggering different processes??
lal

lal

Branch Unspecified
3 years ago
Yes, you can. For all the interrupts, PC will point to 04h and you will need to further check the flags to see what action caused interrupt and execute instructions corresponding to that.
raja_karthick

raja_karthick

Branch Unspecified
3 years ago
lal
Yes, you can. For all the interrupts, PC will point to 04h and you will need to further check the flags to see what action caused interrupt and execute instructions corresponding to that.
yep. i tried it using mikroc and i got a perfect output in proteus simulation. but for the same code, the ic does not responds. there is some real time issue
raja_karthick

raja_karthick

Branch Unspecified
3 years ago
raja_karthick
yep. i tried it using mikroc and i got a perfect output in proteus simulation. but for the same code, the ic does not responds. there is some real time issue
raja_karthick

raja_karthick

Branch Unspecified
3 years ago
this is my code. what could be my possible issue??
***********************************************************************
int count=0; //initialise count variable
int a; //initialise temp variable
void motor()
{
//consider RD0 and RD1 be input to motors
PORTC.F0=1;
PORTC.F1=0; //door open
Delay_ms(5000);
PORTC.F0=0;
PORTC.F1=0; //door stop
Delay_ms(20000);
PORTC.F0=0;
PORTC.F1=1; //door close
Delay_ms(5000);
PORTC=0X00;
PORTC.F6=0; //rf low signal
}

void main()
{
//general register direction configuration
TRISC=0X00;
TRISD=0XFF;
//general port configuration
PORTC=0X00;
PORTD=0X00;
OPTION_REG.INTEDG = 1; //rising egde is taken as interrupt
INTCON.GIE = 1;//enable global interrupt (INTCON is interrupt register)
INTCON.INTE = 1;//enable external interrupt pin i.e RB0
INTCON.RBIE = 1;//enable port change interrupt in port B (pins 4 to7)
while(1)
{
if(PORTD.F0==1) //RFID TRUE VALUE
{
while(PORTD.F0); //hold the value
PORTC.F6=1; //RD3 be RF at engine
motor(); //function call
}
}
}
//interrupt service routine
void interrupt()
{

if(INTCON.INTF==1) //check rb0 int flag
{
count++; //increment count
INTCON.INTF=0; //clear rb0 int flag
}
if(INTCON.RBIF==1) //check rb port change int flag
{
while(PORTB.F4==1); //hold the value
count--; //decrement count
a=PORTB; //read portb to eliminate mismatch conditon after triggering
INTCON.RBIF=0; //clear rb port change int flag
}
if (count>2)
{
PORTC.F7=1; //send high pulse to 2nd rf pin
}
else if(count<=2)
{
PORTC.F7=0; //send low pulse to 2nd rf pin
}


}
***********************************************************************
lal

lal

Branch Unspecified
3 years ago
I cannot comment on the code. I never had experience coding in MikroC. I write in assembly.

By the way, does PIC respond to external interrupt?
Harshad Italiya

Harshad Italiya

Electronics and Communication
3 years ago
Not 100% sure as I have to look into datasheet for that more but if you have enabled,

Pin Change Notification and EXT interrupt together.
Means you are getting EXT interrupt when pin goes HIGH or LOW and you also get interrupt when status of the pin change So it should trigger both interrupt but you also have to check about priority.
raja_karthick

raja_karthick

Branch Unspecified
3 years ago
lal
I cannot comment on the code. I never had experience coding in MikroC. I write in assembly.

By the way, does PIC respond to external interrupt?
yep, it responds sometimes with issues like a delayed output when checked with a simple blink program, but for the code mentioned above, there is no response from the pic, even the main function does not occur
raja_karthick

raja_karthick

Branch Unspecified
3 years ago
Harshad Italiya
Not 100% sure as I have to look into datasheet for that more but if you have enabled,

Pin Change Notification and EXT interrupt together.
Means you are getting EXT interrupt when pin goes HIGH or LOW and you also get interrupt when status of the pin change So it should trigger both interrupt but you also have to check about priority.
i am using two different flags for RB0 and PORT change interrupt and checking them with a "if" condition. and also pin change interrupts occur only in pins RB4 to RB7. EXT interrupt occurs at RB0.
Harshad Italiya

Harshad Italiya

Electronics and Communication
3 years ago
raja_karthick
yep. i tried it using mikroc and i got a perfect output in proteus simulation. but for the same code, the ic does not responds. there is some real time issue
Ok, Then you might check with the hardware you have. when you are changing the input pin have you measured with DMM if that pin really goes HIGH or LOW or not?
Also one more point you might have to look have you configured your that Pin in Input direction or not. From above code it is not looking like you have make it input. It's worth trying to setup as input along with measuring with DMM if it is switching the logic HIGH and LOW really or not.
raja_karthick

raja_karthick

Branch Unspecified
3 years ago
Harshad Italiya
Ok, Then you might check with the hardware you have. when you are changing the input pin have you measured with DMM if that pin really goes HIGH or LOW or not?
Also one more point you might have to look have you configured your that Pin in Input direction or not. From above code it is not looking like you have make it input. It's worth trying to setup as input along with measuring with DMM if it is switching the logic HIGH and LOW really or not.
I will try configuring the direction flow of register and also the DMM and then i will reply😀

Share this content on your social channels -

Only logged in users can reply.