| ??? 09/13/07 09:28 Read: times |
#144557 - Averaging Responding to: ???'s previous message |
As Steve mentions, your method of assembly could be an issue. Even though you're running on batteries, the i.cs are creating noise on the power simply by operating, so you need to have capacitors on the power to take care of this.
; ; simple averaging code ; uses R2,6,7,A ; adc_avg: mov r2,#8 ;loop count clr r6 clr r7 ;zero avg accumulator aa_1 acall get_adc ;returns adc value in A add a,r6 mov r6,a mov a,r7 addc a,#0 mov r7,a ;16bit add djnz r2,aa_1 ; ; divide by 8 by shifting right 3 times ; clr c mov a,r7 rrc a mov r7,a mov a,r6 rrc a mov r6,a clr c mov a,r7 rrc a mov r7,a mov a,r6 rrc a mov r6,a clr c mov a,r7 rrc a mov r7,a mov a,r6 rrc a mov r6,a ; ; return result in A ; mov a,r6 ret Please excuse my simple code, it's been a while since I've written 8051 asm, so I'm a little rusty (choke!). |



