# PIC 16F877A interrupt handling [closed]

I am trying to write a simple code to receive and resend data using USART but the code is not working.

Could someone give suggestions on possible flaws in the code?

I am using USART at baud rate 9600 with clock frequency 4MHz.

#include<pic.h>
void main()
{
TRISB=0X00;
TXEN=1;
SYNC=0;
BRGH=1;
SPEN=1;
CREN=1;
//RCEN=1;
SPBRG=0X19;
INTCON=0X80;
TRISC7=1;
TRISC6=0;
RCIE=1;
TXIE=1;
while(1);
}

void interrupt rectrans()
{
if(RCIF==1)
{
TXREG=RCREG;
while(!TRMT);
RCIF=0;
}
else if(TXIF==1)
{
TXIF=0;
}
}


## closed as unclear what you're asking by Leon Heller, Ricardo, nidhin, Daniel Grillo, Chetan BhargavaJan 30 '15 at 6:49

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• What exactly is not working? And what compiler are you using? Are you sure the interrupt gets called? To check, you could temporarily use an unused pin as debug signal and attach an LED to it. Then, in the beginning of main you turn it off and in the interrupt you turn it on. Are you even sure that the PIC is working, executing the program, etc.? (same way to check) – user17592 Jan 28 '15 at 16:50
• @CamilStaps , thanks for attending my question. I simulated the setup using isis but could not see any changes in the RCREG register(ISIS>>watch window).I am using XC8 compiler.Regarding the interrupts, I could not see any changes in the PIR1 register. I am a beginner when it comes to PIC and interrupts. so probably I have done some mistake at the concept level. – user2745976 Jan 28 '15 at 17:03
• You haven't enabled Peripheral Interrupts in your INTCON register (bit 6). Try setting INTCON to 0xC0 instead of 0x80. – brhans Jan 28 '15 at 17:06
• Thank you very much @CamilStaps. I understood my mistake.Its working perfectly now. – user2745976 Jan 28 '15 at 17:14
• Thank you very much @brhans. I understood my mistake. The issue has been resolved. – user2745976 Jan 28 '15 at 17:29