I have to use two interrupt services of the controller. The interrupts are of External interrupt and Serial Receive.
But the problem is code is not working on hardware. I guess there is something wrong with my code. Following is the code snippet.
void interrupt()
{
if (INTCON.INTF = 1) //If external interrupt
{
TRISB.F0 = 1; //Making it input for picking up states at reqiured delays
start_delay; //delay of 444 uS
start1 = ip;
bit_delay;
start2 = ip;
bit_delay; //Delay of 1778 uS
toggle = ip;
for (i = 0; i <= 4; i ++) //Address bits
{
bit_delay;
addr = ip;
}
for (i = 0; i <= 5; i ++) //Command bits
{
bit_delay;
comm = ip;
}
test_inst(); //Calling the function to process instruction
} //Interrupt flag is cleared in the called instruction.
else if (PIR1.RCIF = 1) //If in PC then
{
x = Usart_Read(); //Receiving data from PC
switch(x)
{
case 'A': {forward(); break;}
case 'B': {backward(); break;}
case 'C': {right(); break;}
case 'D': {left(); break;}
case 'E': {stop(); break;}
}
PIR1.RCIF = 0; //Clearing USART receive interrupt flag bit
}
}
//Start of main program
void main()
{
TRISA.F0 = 0; //Making PORTA as output
TRISA.F1 = 0;
TRISA.F2 = 0;
TRISA.F3 = 0;
Please tell us what output you are expecting and what you are getting now. How frequently is your external interrupt occuring? I think interrupt service routine for external interrupt is consuming some time and if an interrupt occurs during this period it won't be serviced.
Thank you very much matfob for replying. But the good news is problem has been trouble shooted. Checking the interrupt flag in the ISR was givig trouble and i have found a way to do the same thing but with other piece of code.