First of all, PORTB has pullup resistors. You need to clear this pull up resister using RBPU register or you can refer Control registers which contains information about this RBPU.
If Pull up is off, you can try the below method.
You can find where the problem exists by doing this.
Apply break point in main function before while(1) while debugging.
For sake, I would suggest you to put break point in TRISB=0 line.
void main() {
// set PORTB to be digital output
TRISB = 0; // Apply your break point here.
// Turn OFF LEDs on PORTB
PORTB= 0;
while(1) {
// Toggle LEDs on PORTB
PORTB = ~PORTB;
// Delay 1000 ms
Delay_ms(1000);
}
}
If the program hits that break point more than one time, you are having some problem with your reset connection. Else, try to increase the delay function. say for 3 seconds.
while(1) {
// Toggle LEDs on PORTB
PORTB|=0x01; //If LED is connected in RB0
Delay(500);
PORTB&=~0x01;
}