Simple interrupt


Results 1 to 11 of 11

Threaded View

  1. #5
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Simple interrupt

    I would normally use Steve's solution above, but you won't be able to check button pushes in the
    2.5 second COUNT command that way.

    Let's hope I remember everything, and I'm assuming registers for 16F877A are the same for your chip.

    Near the start of your program, after any defines:

    Code:
    Define  INTHAND _Brake    ' Tell PBP Where the code starts on an interrupt
    INTCON.4 = 1                                    'enable portb.0 interrupt
    intoccured var byte
    Then straight after that:

    Code:
    '****************************************************************
    '*  Name    : ASM_INTS.PBP                                      *
    '*  Author  : Darrel Taylor                                     *
    '*  Notice  : Copyright (c) 2003                                *
    '*  Date    : JAN 4, 2003                                       *
    '****************************************************************
    
    wsave       var byte    $20     SYSTEM          ' location for W if in bank0
    
    ' --- IF any of these three lines cause an error ??  Simply Comment them out to fix the problem ----
    wsave1      var byte    $A0     SYSTEM          ' location for W if in bank1
    wsave2      var byte    $120    SYSTEM          ' location for W if in bank2
    wsave3      var byte    $1A0    SYSTEM          ' location for W if in bank3
    ' ------------------------------------------------------------------------------
    
    ssave       var byte    BANK0   SYSTEM          ' location for STATUS register
    psave       var byte    BANK0   SYSTEM          ' location for PCLATH register
    fsave       var byte    BANK0   SYSTEM          ' location for FSR register
    
    Asm
    INT_START  macro
        IF (CODE_SIZE <= 2)
            movwf   wsave            ; copy W to wsave register
            swapf   STATUS,W         ; swap status reg to be saved into W
            clrf    STATUS           ; change to bank 0 regardless of current bank
            movwf   ssave            ; save status reg to a bank 0 register
            movf    PCLATH,w         ; move PCLATH reg to be saved into W reg
            movwf   psave            ; save PCLATH reg to a bank 0 register
        EndIF
        movf      FSR,W              ; move FSR reg to be saved into W reg
        movwf     fsave              ; save FSR reg to a bank 0 register
        endm
    EndAsm
    
    Asm
    INT_RETURN   macro
        MOVF    fsave,W              ; Restore the FSR reg 
        MOVWF   FSR
        Movf    psave,w              ; Restore the PCLATH reg
        Movwf   PCLATH
        swapf   ssave,w              ; Restore the STATUS reg            
        movwf   STATUS
        swapf   wsave,f
        swapf   wsave,w              ; Restore W reg
        Retfie                       ; Exit the interrupt routine    
        endm
    EndAsm
    Then this:

    Code:
    '*********************** ISR *****************************
    Brake:
    @ INT_START                    
    '
      R0save = R0                     ; Save 2 PBP system vars that are used during
      R1save = R1                     ; the interrupt
    '
    IF INTCON.1 = 1 THEN        'handle portb.0 interrupt
    INTCON.1 = 0            'clear portb.0 interrupt flag
    goto overextint            'skip over timer interrupt handler
    ENDIF                '
    '
    overextint:
    '
      R1 = R1save                     ; Restore the PBP system vars
      R0 = R0save
    @ INT_RETURN                      ; Restore context and return from interrupt
    '
    '*********************************************************
    Now this would usually jump back to the point of execution it left from,
    but you want to reset, and need not bother with resoring context,
    so I'd create a routine that resets all vars and goes to the start of your program,
    name it overextint: and delete the overextint label from this code.

    If this works, thank Darrel, if it's broken, blame me!
    Last edited by Art; - 1st March 2012 at 23:38.

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