calcolo della media di 20 valori in assembler
Mi potete consigliare qualche link per capire come posso scrivere una routine in assembler per fare la media di 20 campinamenti del valore analogico di un registro del PIC 16F876a
La comunità del mondo elettrico: elettronica, elettrotecnica, impianti, pic, plc, automazione
https://www.electroyou.it/forum/
; Calculate the average of the values contained in the table
; The table contains 16 values of 12 bits, contained in 16 bits.
; Therefore, calculating the sum with 16 bits is sufficient.
; The result is unsigned.
tableavg
BANKSEL TableS
clrf SumL ; Null the sum registers
clrf SumH
clrf TableC
looptableavg
movfw TableC
addlw TableS
movwf FSR
movfw INDF
addwf SumL,f ; Sum the least significative 8 bits
btfsc STATUS,C ; Adjust carry from the LSBs sum
incf SumH,f
incf TableC,f
incf FSR,f
movfw INDF
addwf SumH,f ; Sum the most significative 2 bits
incf TableC,f
movfw TableC
xorlw TABLESIZE
btfss STATUS,Z ; Loop through all the table
goto looptableavg
movfw SumL
andlw 0x0F
movwf TableC ; TableC is not used anymore in this context
call divide16sum
movfw SumH
movwf NumH
movfw SumL
movwf NumL
return; Divide by 16 the sum
divide16sum
bcf STATUS,C
rrf SumH,f
rrf SumL,f
bcf STATUS,C
rrf SumH,f
rrf SumL,f
bcf STATUS,C
rrf SumH,f
rrf SumL,f
bcf STATUS,C
rrf SumH,f
rrf SumL,f
return ; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 3 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program. If not, see <http://www.gnu.org/licenses/>.
fairyvilje ha scritto:Evviva la propagazione degli errori D:
fairyvilje ha scritto:la propagazione degli errori