;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
c_set rrf w,w ; rotate accu right 1 (div by 2), put in w
addlw b'10000000' ; add to existing value of w (due to carry)
goto c_done ; by-pass 'rrf' if c isn't set.
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
measure movlw d'100' ;
movwf cnt ;
movfw _adres ; take the very first sample
movwf avg ; put it in avg
loop movfw avg
movwf sample1
movfw _adres ; sample 2
addwf sample1,w ; add sample1 to sample2, store result in w.
btfsc _status,0 ; if carry is set...
goto c_set
rrf w,w
c_done movwf avg
decfsz cnt,f ;
goto loop ; loop till cnt=0
movfw avg ; copy the final avg sample to accu
return ; return without altering accu value