precision,
Give this a try.
Code:
DEFINE OSC 20
INCLUDE "MODEDEFS.BAS"
INCLUDE "MYLCD.BAS"
ANSEL = 0 'SELECT ANALOG INPUTS 0 = NONE AND ALL DIGITAL
ADCON0 = 0 'AD MODULE OFF & CONSUMES NO CURRENT
CMCON = 7 'COMPARATORS OFF
TRISA = %00000
TRISB = %00000011 ' INT0 = ENCODER CH. A
' PORTB.1 = ENCODER CH. B
W0 VAR WORD
LastW0 VAR WORD
B1 var word
W0 = 0
B1 = 0
PAUSE 500
'-------------------------------------------------------------------------
INCLUDE "DT_INTS-14.bas" ; Base Interrupt System
INCLUDE "ReEnterPBP.bas" ; Include if using PBP interrupts
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT_INT, _ToggleLED1, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
OPTION_REG.6 = 0 ; 1 = Interrupt on rising edge of INT pin
; 0 = Interrupt on falling edge of INT pin
@ INT_ENABLE INT_INT ; enable external (INT) interrupts
'-------------------------------------------------------------------------
LCDOUT $FE,1
LOOP:
IF W0 <> LastW0 then
LastW0 = W0
' (Peak-Hold), Hold the last value of W0 in B1
if ABS(LastW0) > ABS(B1) then B1 = LastW0
LCDOUT $FE,2
LCDOUT "Length = ", Sdec LastW0, " mm "
lcdout $FE, $C0
lcdout "Peak- Value ",Sdec B1, " mm "
ENDIF
GOTO LOOP
ToggleLED1:
if PORTB.1 = 0 then
W0 = W0+1
else
w0 = w0-1
ENDIF
@ INT_RETURN
The range will be +/-32767.
Added: Modified slightly to eliminate changes while displaying.
Modified again to simplify. ABS() works for both pos and neg numbers. Doh!
It also fixes a problem if it moves slightly negative before going positive.
I'll get it right one of these times 
<br>
Bookmarks