I am using PIC16F628A, MPLAB IDE to coding and Pickit3 to write the code into MCU. The code works on Proteus but does not in real world. I setted A0 pin as input. It should count up normally and count down when button pressed. It count down when button pressed but don't count up. So the pin don't recognize 5 V input or something else.
//CONFIG
#pragma config FOSC = XT // Oscillator Selection bits (XT oscillator: Crystal/resonator on RA6/OSC2/CLKOUT and RA7/OSC1/CLKIN)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = ON // RA5/MCLR/VPP Pin Function Select bit (RA5/MCLR/VPP pin function is MCLR)
#pragma config BOREN = ON // Brown-out Detect Enable bit (BOD enabled)
#pragma config LVP = OFF // Low-Voltage Programming Enable bit (RB4/PGM pin has digital I/O function, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EE Memory Code Protection bit (Data memory code protection off)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
#include <xc.h>
#define _XTAL_FREQ 4000000
void main(void){
int count=0;
TRISB = 0x00;
TRISAbits.TRISA0 = 1;
PORTB = count;
while(1){
if (RA0==1){
count = count+1;
PORTB = count;
__delay_ms(100);
}
else {
count = count-1;
PORTB = count;
__delay_ms(100);
}
}
}