I'm facing a really struggling issue with input reading.
I just wanted to use a push button to active several led but i don't know why the specific PORT doesn't change to 0 to 1 when i press the button.
I've seen that it could be related to the analog but i turned it to digital
- PIC16F18875
- Using Mplabx v5.40
Here is the code
#define _XTAL_FREQ 4000000
#define button TRISDbits.RD7
#include <xc.h>
ledLoop(void){
char run = 1;
while(1){
if(PORTDbits.RD7==1){
LATB=run;
run *= 2;
__delay_ms(200);
}
else{
LATB=0;
}
}
}
void main(void)
{
ANSELDbits.ANSD7=0;
TRISDbits.TRISD7=1;
TRISA=0;
LATA=0x00;
ledLoop();
}
Also my push button is connected as it follow:
3V -> LED -> 10 Ohm resistance -> push button -> to mass and to RD7 port
EDIT
The 4 leds works if the if condition for RD==0 so its working. And for the button part, if i press on the button the led works, but dont change PORTDbits.RD7 to 1


LATB=0;toLATB=~LATB; __delay_ms(500);and see if things flash that way.