PIC MCU: Triggered Counter from ADC
Ok, first a few things. TRISA=1 doesn't put all the PORTA as input as written in the comment, it is equivalent to 0b00000001 so to put all the port as input you have to do TRISA=255 or TRISA=0xFF which equals to 0b11111111.

I don't know how you connected the button to the micro controller but looking to your program it should be something like this:







simulate this circuit &ndash; Schematic created using CircuitLab

On this way it should work, you get 5V when the button is pressed and 0V when it is open. However you still can get some inestable voltage at the moment the button is pressed (called bouncing), it looks like this:



So it may seems like the button is pressed multiple times due to this bouncing effect, to solve this you have to take more samples and average them, then use the average result to decide what to do.

But there is another way, which is easier in this case, you just want to read if the switch is pressed ('1') or not ('0') so you don't need and ADC, you can do it just with a digital input, you don't need an analog one. The schematic would be same but the C program would be something like this (let's suppose the switch is connected to RA0):

int main() {
    TRISA=1;                    // Set RA0 as input
    TRISD=0x00;
    PORTD=0x00;

    while(1){
        if(TRISAbits.RA0) {
            PORTD += 1;
            delay();     // We use the delay to avoid the bouncing effect (some milliseconds)
            while(TRISAbits.RA0);
        }
    }
}


Analog inputs are sometimes useful when you have to read a lot of buttons and you want to save some MCU inputs:



In this circuit each button produces a different voltage in the ADC input. So with the analog input you read that voltage and determine which button was pressed.