
dir:			dbit	1
.......

READPot:
        CALL READADC        ; Read ADC Value in A
        MOV TH,A
        MOV TP,@R0          ; Remember previous value
        CLR C
        SUBB A,TP           ; Current - Previous
        
        MOV dir,C
        
        JNC ABSEND          ; If carry: result was negative, CPL IT!
        CPL A
        INC A


ABSEND: CJNE A,#2,TRESADC   ; Compare change to deadzone
TRESADC:JC INCI             ; less than value. ignore
        
        MOV A,lin
        
        CJNE A,#0,LinearControl
        MOV A,TH
        JMP SEND0

LinearControl:        
        MOV A,TP

        JNB dir,IncV
        CLR C
        SUBB A,#2
        JMP SEND0

IncV:   ADD A,#2

        
SEND0:  MOV @R0,A           ; Update ram value with new one
        CALL SEND

