Luciano,
I switched to portB.6 and 7 for interrupt on change and modified the code
However i cannot decode direction now.I use LEDs to display direction..Now only one of them lights for both directions.Thanks.
**
i'm sorry abt my code being all garbled.Ive done my best this time.
**
Code:movf PORTB,W movlw _old ;Strip off all but the last 2 MSBs in OLD. movlw 0xc0 andwf _old,F ;Read latest input from ENCODER & put the value in NEW. movf PORTB,W movwf _new ;Strip off all but the 2 MSBs in NEW movlw 0xc0 andwf _new,F movf _new,W ;Move the contents of NEW to TEMP and OLD to W movwf _temp ;in order to compare them with XOR. movf _old,W xorwf _temp,F ;XOR previous inputs (in W) with latest inputs ;(in TEMP) to see if they are equal. btfss STATUS,Z ;Test result and skip next line if 0. GoTo rtrn ;Result is 0. Previous inputs equal latest ;inputs. Rotary encoder did not move. Return ;to loop bcf STATUS,C ;Clear the carry bit in the status register and rlf _old,F ;left shift it into OLD to align bit6 of OLD ;with bit7 of NEW. movf _new,W ;Move the contents ofNEW to W in order to XOR. xrwf _old,F ;XOR previous inputs (in OLD) with latest ;inputs (in W) to determine CW or CCW. btfss _old,7 ;Test bit 1 of result (in OLD). Skip next line ;if it is 0 (direction is CCW). GoTo Up ;Bit is 1 (direction is CW). Go around Down Down ;Decrements COUNTER because encoder moved CCW. decf _enc_counter,F bsf _led ;light CCW LED GoTo rtrn ;Branch around UP. Up ;Increments COUNTER because encoder moved CW. incf _enc_counter,F ;and increment counter. bsf _led2 ;light CW LED rtrn bcf intcon.0 ;clear interrupt flag on portBinT




Bookmarks