PORTB interrupt on change

Thread Starter

olvine

Joined Mar 10, 2014
99
why it is not working ??

Please Help!!

//// PIC16F887
//// MikroC


Rich (BB code):
void interrupt()
{
INTCON.PEIE=0;
INTCON.GIE=0;

if(INTCON.RBIF==1){
PORTA.RA5=~PORTA.RA5;
INTCON.RBIF=0;
}

INTCON.PEIE=1;
}


void main(){

PORTB=0;
TRISB.RB5=1;
TRISA.RA5=0;
PORTA.RA5=0;

IOCB=1;
WPUB=1;

INTCON.RBIF=0;
INTCON.PEIE=1;
INTCON.GIE=1;
INTCON.RBIE=1;



while(1){
}
}

[\code]
 
Last edited:

GopherT

Joined Nov 23, 2012
8,009
why it is not working ??

Please Help!!

//// PIC16F887
//// MikroC



void interrupt()
{
INTCON.PEIE=0;
INTCON.GIE=0;

if(INTCON.RBIF==1){
PORTA.RA5=~PORTA.RA5;
INTCON.RBIF=0;
}

INTCON.PEIE=1;
}


void main(){

PORTB=0;
TRISB.RB5=1;
TRISA.RA5=0;
PORTA.RA5=0;

IOCB=1;
WPUB=1;

INTCON.RBIF=0;
INTCON.PEIE=1;
INTCON.GIE=1;
INTCON.RBIE=1;



while(1){
}
}
Define "working" and tell is what is happening instead of "working".
 

Thread Starter

olvine

Joined Mar 10, 2014
99
Ra5 is not changing its value and compiler is not going into interrupt routine..
input is a square wave of 1khz
 

THE_RB

Joined Feb 11, 2008
5,438
void interrupt()
{
INTCON.PEIE=0;
INTCON.GIE=0;

After the first interrupt, GIE is turned off and you have no way to turn it back on. GIE kills all interrupts after that point.

You should remove that line from your interrupt code. You are already switching PEIE off and back on so messing with GIE is probably not needed.
 
Top