PoS080
Junior Member level 3
Hello EE friends,
I am trying to pick up input from a push button connected to RB5, and toggle an LED based on that input. I am not getting a response by pressed or releasing the button. Not sure how my code is wrong.
Compiler: XC8
PIC:16f1829
Button pressed = logic 0;
Button not pressed = logic 1;
Button location RB 5;
LED Location RA5;
thanks
I am trying to pick up input from a push button connected to RB5, and toggle an LED based on that input. I am not getting a response by pressed or releasing the button. Not sure how my code is wrong.
Compiler: XC8
PIC:16f1829
Button pressed = logic 0;
Button not pressed = logic 1;
Button location RB 5;
LED Location RA5;
Code:
int main(int argc, char** argv) {
TRISA = 0x00; //All of A to output
ANSELB = 0x00; // All of B to digital
TRISB = 0b00100000; // RB5 to Input
while(1){
if(RB5 == 1){ //if button pressed turn on light
RA5 = 1;
__delay_ms(2000);
}
else{ //else off light
RA5 = 0;
__delay_ms(2000);
}
}
return (EXIT_SUCCESS);
}
thanks
Last edited: