/ use PIC16F676 
#include <16F676.h> 
// ADC resolution is 10 bits 
#device adc=10 
// Define fuses !! 
#fuses INTRC_IO,NOWDT,PUT,NOPROTECT,BROWNOUT,NOMCLR 
// Define clock used for this MCU 
#use delay (clock=4000000) // 4MHz clock 
// No need for that any way !! 
#rom  0x3ff={0x3444} 
// Define PIC Ports 
#byte PORTA = 0x05 
#byte PORTC = 0x07 
#byte TRISA = 0x85 
#byte TRISC = 0x87 
// I don't see it necessary to redifne ports in another  name 
#define SPORTA PORTA 
#define SPORTC PORTC 
// Define some constants for interuupts 
#define  TICKS_BETWEEN_INTERRUPTS      5000 //5000 
#define  INTERRUPT_OVERHEAD            35 
#define  TMR1RESET (0xFFFF-(TICKS_BETWEEN_INTERRUPTS-INTERRUPT_OVERHEAD)) 
// Here the 7 segment decoder values reside 
const char SegCode[11] = {0x40,0x57,0x22,0x06,0x15,0x0C,0x08,0x56,0x00,0x04,0xFF}; 
   //                       0    1    2    3    4    5    6    7    8    9 
// Used to output manipulate digits, one at a time (MUX) 
const char Column[3]   = {0x02,0x01,0x04}; 
static char Segment[3] = {0x7f,0x7f,0x7f};    
static unsigned char ColCount=0x00; 
// PIC CPU intialization function protoype 
void CPU_SETUP(void); 
// Display function protoype 
void Display(void); 
// ADC result manipulation function protoype 
void HTO7S(unsigned int32 Num); 

byte i; 
unsigned int32 result; 
// Interrupt handler routine, use timer 1 interrupt 
#INT_TIMER1 
void Timer1(void) 
{ 
// Set timer 1 to use its interrupt for display    muxing 
set_timer1(TMR1RESET);    
// Display the result on 7 seg digits 
Display();    
}    

void main() 
{       
   unsigned char i; 
Initialize PIC configuration, nice way to do that in deed    
CPU_SETUP(); 
    
while(true) 
{          
result=0; 
// Read adc result 20 times using this for loop 
for (i=0;i<20;i++) 
{ 
set_adc_channel(3); 
delay_ms(1); 
// finally, the reslt will contain 20 ADC readings 
result=result+read_adc(); 
} 
//result = 0x3fe; 
// Take the average of the 20 ADC results readings, and 
// use it to manipulate this to be able to display it on 7 digits    
HTO7S(result/20);    
delay_ms(200);          
} 
    
} 

void CPU_SETUP() 
{ 
// not use comparator module     
setup_comparator(NC_NC_NC_NC); 
// A3 as analog input, refrences are Vss, and Vdd    
setup_adc_ports( sAN3 | VSS_VDD); 
//Divide the internal clock for use ADC on 64 = 1000000/64 
setup_adc(ADC_CLOCK_DIV_64); 
TRISA=0b00011000; 
PORTA=0x27; 
TRISC=0b00000000; 
PORTC=0x37; 
    
// Use internal clock, prescalar ratio is 1    
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1); 
// Reset timer 1 now 
set_timer1(TMR1RESET); 
// Set the global interrupt bit in options register 
enable_interrupts(GLOBAL); 
// enable timer 1 interrupt now 
enable_interrupts(INT_TIMER1);    
} 

//------------------------------------- 
// Display routine 
//------------------------------------- 
void Display() 
{ 
// off all digits column and Segment G 
PORTA = 0b00100111; 
// off segment a-f        
PORTC = 0b00111111;    
delay_cycles(2); 
    
// for loop could be used here, but it will cause a stack overflow !! 
if (ColCount>=3) 
ColCount=0; 
// Display corresponding digit        
SPORTC = Segment[ColCount]; 
// maniplate digit value in order to put the bits on portc and porta.5 
// XOR it with 7, solve this your self, its easy 
SPORTA = ((Segment[ColCount] & 0b01000000)>>1) | (Column[ColCount]^0x07); 
ColCount++;             
}    

//-------------------------------------- 
// Convet HEX 2 byte to 7-Segment code 
//-------------------------------------- 
void HTO7S(unsigned int32 Num) 
{ 

unsigned int32 res; 

    
Segment[0]=SegCode[30*Num/10230]; 
// If first digit is 0, turn it off 
if (Segment[0]==0x40) 
Segment[0]=0xFF; 
// manipulate the result in order to display it on digits, maths trick, but smart one. 
// needs another post in deed for me to explain    
res = 30*Num%10230; 
Segment[1]=SegCode[10*res/10230]; 
res=10*res%10230; 
Segment[2]=SegCode[10*res/10230]; 
}   