BANKSEL TRISA ; MOVLW B'11001101' ; MOVWF TRISA ;Set PORTA is input or output MOVLW B'11111011' ; MOVWF TRISB ;Set PORTB is input or output MOVLW B'10100110' ; MOVWF TRISC ;Set PORTC is input or output BSF TRISE,3 ;Set RE3 to input CLRF PIE1 ;Init PIE1 MOVLW B'00000001' ; MOVWF PIE2 ;EEIE turn on $ CCP2IE turn on
;***********INT************************************************************** INT: MOVWF W_TEMP ;Copy W to TEMP register SWAPF STATUS,W ;Swap status to be saved into W ;Swaps are used because they do not affect the status bits MOVWF STATUS_TEMP ;Save status to bank zero STATUS_TEMP register BTFSS HALL2 ;Is int_CW? GOTO $+2 ; CALL INT_CW ; BTFSC HALL2 ;Is int_CCW? GOTO $+2 ; CALL INT_CCW ; SWAPF STATUS_TEMP,W ;Swap STATUS_TEMP register into W ;(sets bank to original state) MOVWF STATUS ;Move W into STATUS register SWAPF W_TEMP,F ;Swap W_TEMP SWAPF W_TEMP,W ;Swap W_TEMP into W BCF PIR2,CCP2IF RETFIE ;***********Motor is CW and CNT will -1*************************************** INT_CW: DECF MT_POS_LO,1 ; BTFSS STATUS,C ; GOTO $+2 ; DECF MT_POS_HI,1 ; RETURN ;***********Motor is CCW and CNT will +1************************************** INT_CCW: INCF MT_POS_LO,1 ; BTFSS STATUS,C ; GOTO $+2 ; INCF MT_POS_HI,1 ; RETURN