Hi,
I wrote this code for my temperature sensor project. It results in a stable display of temperature on an lcd. Don't know if it will work for your project, it may depend on the magnitude of the individual sample values, adding 32 times may result in too big a number. I use 10bit A/D
Code:
A2D
start_sampling
bsf ADCON0,1 ;start conversion
btfsc ADCON0,1
goto $-2
incf Avg_cnt ;sample counter
;add 32 samples
movf ADRESL,w
addwf read1_low,f
btfsc STATUS,C
incf read1_high
movf ADRESH,w
addwf read1_high,f
movlw .32
subwf Avg_cnt,w
btfss STATUS,Z
goto start_sampling
clrf Avg_cnt
;divide by 32
bcf STATUS,C
rrcf read1_high
rrcf read1_low ;/2
bcf STATUS,C
rrcf read1_high
rrcf read1_low ;/4
bcf STATUS,C
rrcf read1_high
rrcf read1_low ;/8
bcf STATUS,C
rrcf read1_high
rrcf read1_low ;/16
bcf STATUS,C
rrcf read1_high
rrcf read1_low ;/32