Interrupt usage


Closed Thread
Results 1 to 10 of 10

Thread: Interrupt usage

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Oh, I see what you're saying. But it's still not a typo.

    You can have multiple ON INTERRUPT statements, but it gets a little tricky.
    This will be hard to explain, so give me a little time.
    <br>
    DT

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Multiple ON INTERRUPT GOTO's

    This example should show how you can use multiple ON INTERRUPTS.
    But it's not much use for anything else.

    The key thing to remember here, is that the assignments of the Interrupt Handlers only happens at Compile-Time. Attempting to execute an ON INTERRUPT statement at Run-Time to change the handler will not work.

    As the program gets compiled, starting from the top, the interrupts are considered DISABLED, and no interrupt checks will be placed between the PBP lines of code.

    When it encounters an ON INTERRUPT statement, the status changes to ENABLED, and in between every PBP statement, it will place an Interrupt Check, that jumps to the last assigned Handler.

    In the example below, if an interrupt occurs while the program flow is within the Main loop, then the Handler0 will be jumped to.

    Then when it encounters the second ON INTERRUPT statement, all lines following that assignment will interrupt to Handler1.

    It does not matter if they are subroutines, main routines, or whatever, ANY lines following an ON INTERRUPT will jump to the last known handler (if interrupted).

    It really does get tricky, because then each handler must be capable of handling any interrupt, which leads to multiple copies of the same handler or gosubs to common handlers. Or you have to make sure that before switching modes, ONLY the interrupts that the next mode can handle are enabled, I mean SERIOUSLY Tricky!

    Just remember, It all happens at Compile-Time.

    Code:
    Mode   VAR BYTE
    Mode = 0
    
    ON INTERRUPT GOTO Handler0
    
    Main:
        R0 = R0 ; just some stuff to put int checks between
        R1 = R1
        IF Mode = 1 then DoMode1
        IF Mode = 2 then DoMode2
    GOTO Main
    
    DISABLE
    Handler0:
        ; Interrupt handler for the Main Loop
    RESUME
    ENABLE
    
    ;--------------------------------------------------------
    ON INTERRUPT GOTO Handler1
    
    DoMode1:
        ; Do Mode 1 tasks here
        
        IF Mode = 0 then Main
        IF Mode = 2 then DoMode2
    GOTO DoMode1
    
    DISABLE
    Handler1:
        ; Interrupt handler for Mode 1
    RESUME
    ENABLE
    
    ;--------------------------------------------------------
    ON INTERRUPT GOTO Handler2
    
    DoMode2:
        ; Do Mode 2 tasks here
        
        IF Mode = 0 then Main
        IF Mode = 1 then DoMode1
    GOTO DoMode2
    
    DISABLE
    Handler2:
        ; Interrupt handler for Mode 2
    RESUME
    ENABLE
    hth,
    DT

  3. #3


    Did you find this post helpful? Yes | No

    Default Multiple ON INTERRUPT GOTOs

    Thanks Darrel. That's quite an explanation!

    Regards,

    Brian Walsh.

Similar Threads

  1. Won't go back to SLEEP after 1st Interrupt
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 29th June 2009, 10:00
  2. Can't ID interrupt source with this IntHandler??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd June 2009, 03:35
  3. Help with Analog Interrupt
    By brid0030 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th February 2008, 19:14
  4. NEWBIE: Some basic questions using interrupts
    By JackPollack in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 8th March 2006, 03:59
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 02:07

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