Advertisement
Guest User

Untitled

a guest
Feb 17th, 2014
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pic 16 1.41 KB | None | 0 0
  1.         ; ISR vector (only TMR0)
  2.     org 4
  3.         movwf    isr_w               ; Save context
  4.         movfw    STATUS
  5.         movwf    isr_status
  6.         bcf      INTCON, T0IF        ; Clear interrupt flag
  7.  
  8.         rrf      rotaryEncoder, w    ; Shift old encoder A value to the right
  9.         andlw    01                  ; Get rid of extra garbage (incl carry bit)
  10.         movwf    rotaryEncoder
  11.  
  12.         swapf    PORTB, w            ; Get new encoder A and B (RB5 and RB6)
  13.         andlw    06
  14.         iorwf    rotaryEncoder, w    ; OR in new values
  15.         movwf    rotaryEncoder
  16.  
  17.         ; Only transisions on A count, B determines which way to go
  18.         addwf    PCL, f              ; Jump into table
  19.         b        ISREncNop
  20.         b        ISREncDec
  21.         b        ISREncInc
  22.         b        ISREncNop
  23.         b        ISREncNop
  24.         b        ISREncInc
  25.         b        ISREncDec
  26.         b        ISREncNop
  27.  
  28. ISREncNop:
  29.         b        ISREncEnd           ; Chew up one cycle for equal timing
  30. ISREncInc:
  31.         incf     encoderCount, f
  32. ISREncEnd:
  33.         movfw    isr_status          ; Restore context
  34.         movwf    STATUS
  35.         swapf    isr_w, f
  36.         swapf    isr_w, w
  37.         retfie
  38. ISREncDec:
  39.         decf     encoderCount, f
  40.         movfw    isr_status          ; Restore context
  41.         movwf    STATUS
  42.         swapf    isr_w, f
  43.         swapf    isr_w, w
  44.         retfie
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement