Code ignores IF Statement
Here is my code:
Code:
char adc(unsigned char);
unsigned char temp, temp1, temp2,temp3,temp4,temp5,send;
unsigned int temp_res;
void Forward (void){
RC3_bit=1;//right forward
RC4_bit=0;//right reverse
RC6_bit=1;//Left forward
RC7_bit=0;//Left Reverse
RC0_bit=1;//right enable
RC1_bit=1; //Left enable
}
void Reverse (void){
RC3_bit=0;//right forward
RC4_bit=1;//right reverse
RC6_bit=0;//Left forward
RC7_bit=1;//Left Reverse
RC0_bit=1;//right enable
RC1_bit=1; //Left enable
}
void Right (void){
RC3_bit=1;//right forward
RC4_bit=0;//right reverse
RC6_bit=0;//Left forward
RC7_bit=0;//Left Reverse
RC0_bit=1;//right enable
RC1_bit=1; //Left enable
}
void Left (void){
RC3_bit=0;//right forward
RC4_bit=0;//right reverse
RC6_bit=1;//Left forward
RC7_bit=0;//Left Reverse
RC0_bit=1;//right enable
RC1_bit=1; //Left enable
}
void STOP (void){
RC3_bit=0;//right forward
RC4_bit=0;//right reverse
RC6_bit=0;//Left forward
RC7_bit=0;//Left Reverse
RC0_bit=1;//right enable
RC1_bit=1; //Left enable
}
void main(void) {
ANSELH = 0x00;
ANSEL = 0x00; // Set AN2 pin for A/D
TRISC = 0x00; // Set data Direction on Port C (output)
PORTC = 0x00; // Start with zero on Port C
TRISB = 0xF0; // Set Port B as an input port
PORTB = 0x00;
C1ON_bit = 0; // Disable comparators
C2ON_bit = 0;
PWM1_Init(8000);
PWM1_Start();
while(1){
temp_res = ADC_Read(2); // Get 10-bit results of AD conversion
temp1 = temp_res >>2;
PWM1_Set_Duty(temp1);
delay_ms(100);
if (RB4_bit == 1)
{
Forward();
}
}
}
The code is for a PIC16F690 which is connected to an H-Bridge. The intent of the code is to drive the robot forward whenever RB4 is high.
Whenever I run the code it ignores the IF statement and the Forward() function is called and the robot immediately goes forward.
Any ideas?