

; if |current-previous| > slack
; 	if (current-previous) > 0
; 		previous = current - slack
; 	else
; 		previous = current + slack

			bseg

dir:			dbit	1

			dseg

current:			db	1
previous:			db	1

			cseg

			mov	a,current		; current should be a buffered reading
			clr	c
			subb	a,previous		; current - previous = change
			mov	dir,c			; dir set if change was down
			jnc	absignend		; calculate absolute value of change
			cpl	a
			inc	a
absignend:		cjne	a,#slack,tresadc	; Compare change to slack
tresadc:		jc	endadc			; if not changed more than slack, ignore
			mov	a,current		; remember current value
			jb	dir,addtresh		; If change is up, compensate down
			clr	c
			subb	a,#slack
			sjmp	storeprevious
addtresh:		add	a,#slack		; If change is up, compensate up
storeprevious:		mov	previous,a		; Store calculated value

endadc:							; Your new value now in a.

