Good day
I am currently experiencing problem with the PIC, it can be recognized by the PIC-kit2 and programmed but I cant see anything at the output.
All the TRIS Reg for output and input pin are configured correctly, I even tried to write a simple blinking LED program it also does not work.
I am using CCS compiler C language with PIC 16f877A this was working correctly before i staterd with the Sensors.
The other thing I have realized is that the MPlab was not able to get to debugging mode when I tried it, then I uninstalled everything and installed it again but still setting at the problem. May you please help me, I have tried different new PIC already.
Here is the program code:
All regardCode:#include<16f877A.h> #fuses HS,NOWDT,NOPROTECT,NOLVP #use delay(clock = 8000000, INT_OSC) //page 130, datasheet //choosing frequency = 4.90khz -> period = 204us //t2DIV = 4 //timer2 prescaler, PR2 = 0x65 //to setup the value for the pwm function: //Duty = duty cycle/(t2DIV(1/8000000)) void main() { int remember = -1; long DutyR = 204; //50% duty cycle long DutyL = 204; //50% duty cycle set_tris_B(0xFF); set_tris_A(0x00); set_tris_D(0x00); setup_ccp1(CCP_PWM); // Confiqure CCP1 as a PWM setup_ccp2(CCP_PWM); // // setup_timer_2(T2_DIV_BY_4, 0x65, 1); //sets the frequency of the pwm set_pwm1_duty(DutyL); set_pwm2_duty(DutyR); //delay_ms(1000); while(TRUE) { //if DutyL>=DutyR remember is equal to 1 else remember = 0 //stop All High if (input(PIN_B0) == 1 && input(PIN_B1)==1 && input(PIN_B2)==1 && input(PIN_B3)== 1 && input(PIN_B4)==1 && input(PIN_B5)==1 && input(PIN_B6 )==1) { DutyR= 0; DutyL= 0; output_low(PIN_d3); output_low(PIN_d2); // remember = 1; } // Stop else if (input(PIN_B0) == 0 && input(PIN_B1)==0 && input(PIN_B2)==0 && input(PIN_B3)== 0 && input(PIN_B4)==0 && input(PIN_B5)==0 && input(PIN_B6 )==0) { DutyR= 0; DutyL= 0; output_low (PIN_d3); output_low(PIN_d2); //remember = 0; } // sharp turn left "A" else if (input(PIN_B0) == 1 && input(PIN_B1)==0 && input(PIN_B2)==0 && input(PIN_B3)== 1 && input(PIN_B4)==0 && input(PIN_B5)==0 && input(PIN_B6 )==0) { DutyR= 408; DutyL= 408; output_high(PIN_d3); output_low (PIN_d2); // remember = 1; } // sharp turn left "with no B3" else if (input(PIN_B0) == 1 && input(PIN_B1)==0 && input(PIN_B2)==0 && input(PIN_B3)== 0 && input(PIN_B4)==0 && input(PIN_B5)==0 && input(PIN_B6 )==0) { DutyR= 408; DutyL= 408; output_high(PIN_d3); output_low (PIN_d2); // remember = 1; } //Sharp turn Right "B" else if (input(PIN_B0) == 0 && input(PIN_B1)==0 && input(PIN_B2)==0 && input(PIN_B3)== 1 && input(PIN_B4)==0 && input(PIN_B5)==0 && input(PIN_B6 )==1) { DutyR= 408; DutyL= 408; output_low(PIN_d3); output_high(PIN_d2); // remember = 1; } //Sharp turn Right "B" else if (input(PIN_B0) == 0 && input(PIN_B1)==0 && input(PIN_B2)==0 && input(PIN_B3)== 0 && input(PIN_B4)==0 && input(PIN_B5)==0 && input(PIN_B6 )==1) { DutyR= 408; DutyL= 408; output_low(PIN_d3); output_high(PIN_d2); // remember = 1; } // turn moderately to Left1 "C" else if (input(PIN_B0) == 0 && input(PIN_B1)==0 && input(PIN_B2)==1 && input(PIN_B3)== 1 && input(PIN_B4)==0 && input(PIN_B5)==0 && input(PIN_B6 )==0) { DutyR= 306; DutyL= 204; output_high(PIN_d3); output_low(PIN_d2); remember = 0; } // turn moderately to Left2 "C" else if (input(PIN_B0) == 0 && input(PIN_B1)==0 && input(PIN_B2)==1 && input(PIN_B3)== 0 && input(PIN_B4)==0 && input(PIN_B5)==0 && input(PIN_B6 )==0) { DutyR= 306; DutyL= 204; output_high(PIN_d3); output_low(PIN_d2); // remember = 0; } // Turn moderately to Right1 "D" else if (input(PIN_B0) == 0 && input(PIN_B1)==0 && input(PIN_B2)==0 && input(PIN_B3)== 1 && input(PIN_B4)==1 && input(PIN_B5)==0 && input(PIN_B6 )==0) { DutyR=204; DutyL=306; output_low(PIN_d3); output_high(PIN_d2); remember = 0; } // Turn moderately to Right2 "D" else if (input(PIN_B0) == 0 && input(PIN_B1)==0 && input(PIN_B2)==0 && input(PIN_B3)== 0 && input(PIN_B4)==1 && input(PIN_B5)==0 && input(PIN_B6 )==0) { DutyR=204; DutyL=306; output_low(PIN_d3); output_high(PIN_d2); remember = 0; } // turn Left1 "E" else if (input(PIN_B0) == 0 && input(PIN_B1)==0 && input(PIN_B2)==1 && input(PIN_B3)== 1 && input(PIN_B4)==0 && input(PIN_B5)==0 && input(PIN_B6 )==0) { DutyR= 306; DutyL= 102; output_high(PIN_d3); output_low(PIN_d2); remember = 0; } // turn Left2 "E" else if (input(PIN_B0) == 0 && input(PIN_B1)==0 && input(PIN_B2)==1 && input(PIN_B3)== 0 && input(PIN_B4)==0 && input(PIN_B5)==0 && input(PIN_B6 )==0) { DutyR= 306; DutyL= 102; output_high(PIN_d3); output_low(PIN_d2); // remember = 0; } // turn Left3 "E" else if (input(PIN_B0) == 0 && input(PIN_B1)==1 && input(PIN_B2)==1 && input(PIN_B3)== 1 && input(PIN_B4)==0 && input(PIN_B5)==0 && input(PIN_B6 )==0) { DutyR= 306; DutyL= 102; output_high(PIN_d3); output_low(PIN_d2); // remember = 0; } // turn Left4 "E" else if (input(PIN_B0) == 0 && input(PIN_B1)==1 && input(PIN_B2)==1 && input(PIN_B3)== 0 && input(PIN_B4)==0 && input(PIN_B5)==0 && input(PIN_B6 )==0) { DutyR= 306; DutyL= 102; output_high(PIN_d3); output_low(PIN_d2); // remember = 0; } //turn Right1 "F" else if (input(PIN_B0) == 0 && input(PIN_B1)==0 && input(PIN_B2)==0 && input(PIN_B3)== 1 && input(PIN_B4)==1 && input(PIN_B5)==0 && input(PIN_B6 )==0) { DutyR= 306; DutyL= 102; output_low(PIN_d3); output_high(PIN_d2); remember = 0; } //turn Right2 "F" else if (input(PIN_B0) == 0 && input(PIN_B1)==0 && input(PIN_B2)==0 && input(PIN_B3)== 0 && input(PIN_B4)==1 && input(PIN_B5)==0 && input(PIN_B6 )==0) { DutyR= 306; DutyL= 102; output_low(PIN_d3); output_high(PIN_d2); remember = 0; } //turn Right3 "F" else if (input(PIN_B0) == 0 && input(PIN_B1)==0 && input(PIN_B2)==0 && input(PIN_B3)== 1 && input(PIN_B4)==1 && input(PIN_B5)==1 && input(PIN_B6 )==0) { DutyR= 306; DutyL= 102; output_low(PIN_d3); output_high(PIN_d2); remember = 0; } //turn Right4 "F" else if (input(PIN_B0) == 0 && input(PIN_B1)==0 && input(PIN_B2)==0 && input(PIN_B3)== 0 && input(PIN_B4)==1 && input(PIN_B5)==1 && input(PIN_B6 )==0) { DutyR= 306; DutyL= 102; output_low(PIN_d3); output_high(PIN_d2); remember = 0; } // Go Straight "D" else if (input(PIN_B0) == 0 && input(PIN_B1)==0 && input(PIN_B2)==0 && input(PIN_B3)== 1 && input(PIN_B4)==0 && input(PIN_B5)==0 && input(PIN_B6 )==0) { DutyR= 204; DutyL= 204; output_high (PIN_d3); output_high(PIN_d2); remember = 0; } // Go Straight "2" possibility else if (input(PIN_B0) == 0 && input(PIN_B1)==0 && input(PIN_B2)==1 && input(PIN_B3)== 1 && input(PIN_B4)==1 && input(PIN_B5)==0 && input(PIN_B6 )==0) { DutyR= 204; DutyL= 204; output_high (PIN_d3); output_high(PIN_d2); remember = 0; } /*else if (remember==1) //{ DutyR = 306; DutyL = 102; }*/ set_pwm1_duty(DutyL); set_pwm2_duty(DutyR); } }





Bookmarks