I am writing a program for a robot and I am having trouble with the program for the interrupt system. The robot uses a pair of bumpers that when pushed, sensors that are connected to port E bit 0 and 1 cause a signal the transitions form high to low. The code builds, but when executing the program the robot does not respond to the interrupt. I cannot seem to find what is wrong with the program and I'm hoping someone can help me!
Code:
#include<htc.h>
#include<PICinit.h>
#include<PICinit.c>
void motorsOff ();
void forwardMotion ();
void leftPivot ();
void rightPivot ();
void backwardMotion ();
void backwardLeft ();
void backwardRight ();
main(void)
{
motorspeed (1,10);
motorspeed (2,10);
configurePIC ();
INTE =1;
GIE= 1;
while(1)
{
forwardMotion ();
}
}
void motorsOff (){ output_low ('C',0);
output_low ('C', 5);
output_low ('C',4);
output_low ('C',3);
return;
}
void forwardMotion (){ output_low ('C',0);
output_high ('C', 5);
output_high ('C',4);
output_low ('C',3);
return;
}
void leftPivot (){ output_low ('C',0);
output_high ('C', 5);
output_low ('C',4);
output_high ('C',3);
return;
}
void rightPivot (){ output_high ('C',0);
output_low ('C', 5);
output_high ('C',4);
output_low ('C',3);
return;
}
void backwardMotion (){ output_high ('C',0);
output_low ('C', 5);
output_low ('C',4);
output_high ('C',3);
return;
}
void backwardLeft (){ output_high ('C',0);
output_high('C', 5);
output_low ('C',4);
output_high ('C',3);
return;
}
void backwardRight ()
{ output_high ('C',0);
output_high ('C', 5);
output_high ('C',4);
output_low ('C',3);
return;
}
void interrupt isr (void)
{
if(save_data ()==0){
return;
}
pause(5);
if((PORTB & 0x01)==1)
{ INTF = 0;
restore_data ();
return;
}
motorsOff ();
pause (50);
if((read_input('E',0))==0) //bit 0 port E is right bumper
{ backwardMotion ();
pause (10);
backwardRight ();
pause (10);
forwardMotion ();
}
else if((read_input('E',1))==0) //bit 1 port E is right bumper
{ backwardMotion();
pause (10);
backwardLeft ();
pause (10);
forwardMotion ();
}
else { backwardMotion();
pause (20);
backwardLeft ();
pause (10);
forwardMotion ();
}
if((PORTB & 0x01)==1)
{
INTF = 0;
}
restore_data ();
return;
}