#include <htc.h>
__CONFIG(LVP_OFF & BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_HS);
#define _XTAL_FREQ 20000000
unsigned char digits[] = { 0b00010000,0b01111101,0b00100010,0b00101000,0b01001101,0b10001000,
0b10000000, 0b00111101,0X00,0b00001000};
void main(){
TRISD=0X00;
TRISB=0X00;
PORTB=0X00;
TRISA = 0xff ;
ADCON1=0b00000000;
ADCON0=0b10000001;//000 = channel 0, (RA0/AN0)
ADIF=0;
ADIE=1;
PEIE=1;
while(1){
__delay_us(10);
GO_DONE=1;
__delay_us(10);
unsigned char x=0;
x=ADRESH;
PORTD = 8;
x=x%10;
PORTB=digits[x];
__delay_ms(5);
PORTB=0X00;
x=ADRESH;
PORTD = 4;
x=(x/10)%10;
PORTB=digits[x];
__delay_ms(5);
PORTB=0X00;
x=ADRESH;
PORTD = 2;
x=x/100;
PORTB=digits[x];
__delay_ms(5);
PORTB=0X00;
x=ADRESL;
x=x%10;
PORTD = 1;
PORTB=digits[ADRESL]; // just for test on display working or not
__delay_ms(5);
PORTB=0X00;
}
}