Quick thoughts: DT Ints with encoders


Results 1 to 20 of 20

Threaded View

  1. #12
    Join Date
    Dec 2005
    Location
    Salt Lake City, Ut, USA
    Posts
    108


    Did you find this post helpful? Yes | No

    Default

    Here's what I've got so far... for the "slave" pics anyhow.

    Critiques are definitely welcome!

    16F688 w/20Mhz

    Code:
    INCLUDE "DT_INTS-14-MOD.bas"
    INCLUDE "ReEnterPBP.bas"
    
    'Clock setup
        Define OSC 20
    'Pin setups
        ANSEL = %00000000       'No analog input
        TRISA = %00000111       'PortA: TRISA = %00XXXXXX
        TRISC = %00000000       'PortC: TRISC = %00XXXXXX
    'Usart setups
        DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
        DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
        DEFINE HSER_CLROERR 1 ' Clear overflow automatically
        DEFINE HSER_SPBRG 86  ' 57600 Baud @ SPBRGH = 0
        BAUDCTL.3 = 1         ' Enable 16 bit baudrate generator
    '----------------------------------------------------------------------------
    
    MaxCount con 21600
    BtnZeroCount var PORTA.0
    APin var PORTA.1
    BPin var PORTA.2
    AOld var byte
    BOld var byte
    CurCount var word
    
    ASM
    INT_LIST  macro    ; IntSource,  Label,  Type, ResetFlag?
            INT_Handler   RAC_INT,  _ABInt,   PBP,  yes
        endm
        INT_CREATE           ; Creates the interrupt processor
    
        INT_ENABLE  RAC_INT  ; Enable RA change interrupt
    ENDASM
    
    curcount = 0
    
    Start:
    
    if btnzerocount = 0 then    'btnzerocount (A.0) has pullup res
        curcount = 0
    endif
    
    aold = apin
    bold = bpin
    
    hserout ["$", dec5 curcount]
    
    goto start
    
    ABInt:
    
    '\\\ A caused the interrupt ///
    IF apin != aold THEN                       'APin IS NOT equal to AOld
        IF apin != bpin THEN                   'If A and B are different,
            GOTO CW                                 'it was clockwise rotation
        ELSE                                   'Otherwise,
            GOTO CCW                                'it was counter-clockwise rotation
        ENDIF
    ENDIF
    
    '\\\ B caused the interrupt ///
    IF Bpin != Bold THEN                       'BPin IS NOT equal to BOld
        IF apin == bpin THEN                   'If A and B are the same,
            GOTO CW                                 'it was clockwise rotation
        ELSE                                   'Otherwise,
            GOTO CCW                                'it was counter-clockwise rotation
        ENDIF
    ENDIF
    
    CW:                 ' -1
    if curcount > 0 then
        curcount = curcount -1
    else
        curcount = MaxCount
    endif
    @ INT_RETURN
    
    CCW:                ' +1
    if curcount < maxcount then
        curcount = curcount +1
    else
        curcount = 0
    endif
    @ INT_RETURN
    Thanks again guys,
    Chris
    Last edited by kevlar129bp; - 6th January 2010 at 03:22. Reason: Added Pic part#, fixed TRIS reg's...Doh!

Similar Threads

  1. DT Ints work around for IOCA Register?
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 6th January 2010, 02:20
  2. Problem with Dt Ints Interrupts
    By Quin in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th July 2008, 20:21
  3. Big characters on HD44780 4x20
    By erpalma in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 7th January 2007, 03:21

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts