vicky001.iith
Advanced Member level 4
- Joined
- Aug 5, 2013
- Messages
- 113
- Helped
- 37
- Reputation
- 74
- Reaction score
- 31
- Trophy points
- 48
- Location
- INDIA
- Activity points
- 721
Hello everyone,I am facing a problem.The code given below is not working properly.
Code is whenever i gets an interrupt at PIN B2.Led should blink.But it is not working in the expected way.It doesn't enter in this loop.
I am giving interrupt to pin B2 a 5V pulse.
CODE :-
Code is whenever i gets an interrupt at PIN B2.Led should blink.But it is not working in the expected way.It doesn't enter in this loop.
Code:
if (INTCON3bits.INT2IF == 1)
{
blink_RA();
delay(200);
INTCON3bits.INT2IF = 0;
}
}
I am giving interrupt to pin B2 a 5V pulse.
CODE :-
Code:
include <p18f26k22.h>
//#include <adc.h>
#pragma config PLLDIV=1,IESO=OFF
#pragma config WDT=OFF,PWRT=ON,BOR=OFF,PBADEN=OFF
#pragma config DEBUG=OFF,STVREN=ON,FCMEN=OFF
#pragma config LVP=OFF,MCLRE = OFF,XINST=OFF
#pragma config EBTR0=OFF,EBTR1=OFF,EBTRB=OFF
#pragma config WRT0=OFF,WRT1=OFF,WRTB=OFF,WRTC=OFF,WRTD=OFF
#pragma config CP0=OFF,CP1=OFF,CPB=OFF,CPD=OFF
#define FOSC_FREQ (unsigned long)11059200 // 11.0592 MHz
void chk_isr(void); //checks if int1 set the interrupt
void INT1_ISR(void);
void blink_RA();
#pragma code My_HiPrio_Int = 0x08 // high-priority interrupt location
void My_HiPrio_Int (void)
{
_asm
GOTO chk_isr
_endasm
}
#pragma code
#pragma interrupt chk_isr // used for high-priority interrupt only
void chk_isr (void)
{
if (INTCON3bits.INT1IF==1) //INT1 causes interrupt?
INT1_ISR(); //YES. Execute INT1 program
}
void INT1_ISR(void)
{
blink_RA();
INTCON3bits.INT1IF=0; //clear INT1 flag
}
void delay(unsigned char time);
void blink_RA2();
void blink_RA1();
void delay(unsigned char time)
{
unsigned char i,j;
for(i=0;i<250;i++)
{
for(j=0;j<250;j++);
}
}
void blink_RA2()
{
TRISCbits.TRISC0 = 0;
TRISCbits.TRISC1 = 0;
LATCbits.LATC1 = 1 ;\
LATCbits.LATC0=0;
delay(50);
}
void blink_RA1()
{
TRISCbits.TRISC0 = 0;
TRISCbits.TRISC1 = 0;
LATCbits.LATC1 = 0 ;\
LATCbits.LATC0=1;
delay(50);
}
void blink_RA()
{
TRISCbits.TRISC0 = 0;
TRISCbits.TRISC1 = 0;
LATCbits.LATC1 = 1 ;\
LATCbits.LATC0 = 1;
delay(50);
}
void main()
{
TRISBbits.TRISB2 = 1; // pir input
INTCON3bits.INT1IF=0; // clear int1
INTCON3bits.INT1IE=1; // enable int1 interrupt
//INTCON2bits.INTEDG1=0; // make it positive edge
INTCON2bits.RBPU=1;
INTCONbits.GIE=1; // enable all interrupts
INTCONbits.GIE=0; // Disable all interrupts
ADCON1 = 0x0F; //all digital I/O
blink_RA2();
delay(50);
blink_RA2();
delay(50);
while(1)
{
blink_RA1();
blink_RA2();
// blink_RA();
if (INTCON3bits.INT2IF == 1)
{
blink_RA();
delay(200);
INTCON3bits.INT2IF = 0;
}
}
}