OK. Leave everything...
What i am trying to do is to provide a backup power to my digital clock.
I have connected main power voltage to RB7 pin. Whenever RB7 goes down, i am enabling RBIE ( portb change-on-interrupt) and putting the PIC to sleep mode using SLEEP() instruction. Whenever power comes back, PIC will get a voltage on RB7. I am expecting a interrupt at this time. But this interrupt routine is not calling.
So I tested only this interrupt feature using below sample code.
//include file
#include <pic.h>
__CONFIG ( 0x3FB1 );
volatile unsigned char temp, value = 0;
unsigned char alarm = 0;
void showNumber ( unsigned char num );
//main function
void main ( void )
{
PEIE = 1;
GIE = 1;
TRISA = 0x0;
TRISC = 0x0;
TRISB = 0x0;
PORTB = 0;
PORTA = 0b00000001;
TRISB = 0b10000000;
temp = PORTB;
RBIF = 0;
RBIE = 1;
while ( 1 )
{
if ( value != 1 )
{
PORTC = 0b11111100;
}
else
{
PORTC = 0b00011000;
}
}
}
/*
Interrupt routine.
*/
void interrupt
isr( void )
{
if ( RBIF )
{
value = 1 - value; // Toggle value
temp = PORTB;
RBIF = 0;
}
}
Description of the test program:
For this test pgm, To portb RB7 pin I have connected a on/off switch which gives a +5V when its in ON condition. When i start the circuit, the value of variable value is 0 then it should display value 0 in the 7-segment-display using PORTC. When i turn on the switch, it should generate a portB change-on-interrupt and toggle the value of variable value to 1. This will inturn change the display value to 1 in the main program.
But what is actually happening is when the switch is in OFF condition, the interrupt routine is keep on calling. When switch is in ON condition, the interrupt is not calling. What actually i want here is to get only 1 intterrupt when any change in RB7 happens instead of continues intterrupts. Why the interrupt is not working when RB7 pin changes from 0 to 1?