Interrupt block with different exit?


+ Reply to Thread
Results 1 to 14 of 14
  1. #1
    Join Date
    Jul 2024
    Posts
    28

    Default Interrupt block with different exit?

    Hi all,

    I'm troubleshooting an issue with an interrupt routine using RBC and Instant Interrupts where it's only detecting the first trigger and not any other following that.
    In my interrupt routine, when the interrupt is detected, the flag is cleared and there's a choice (IF...Then) that can lead the code to one of 2 options using GOTO.
    This means that after the interrupt, the code will not return to the point where the trigger was detected but somewhere else.
    That being said, I replaced the @ INT_RETURN with a couple of GOTOs.

    I found that replacing the @ INT_RETURN with GOTOs was causing the following triggers not being detected.
    If i replace the GOTOs with the @ INT_RETURN, the interrupts will work always.

    My question is...Is there a way i can do the jumps to where i want on the code and not being forced to return to where i was when the interrupt was triggered?

    Thanks
    Last edited by PaulMaker; - 5th February 2025 at 21:19.

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,623


    Did you find this post helpful? Yes | No

    Default Re: Interrupt block with different exit?

    My question is...Is there a way i can do the jumps to where i want on the code and not being forced to return to where i was when the interrupt was triggered?
    no , the isr must return to the point it was triggered from. if you try manipulating the stack to alter the return address without the proper skillset and understanding it will always result in unpredictable behavior.
    if you structure your code to check frequently for a flag set from the isr that causes different processes to be invoked its possible to simulate the sort of result you are looking for
    Warning I'm not a teacher

  3. #3
    Join Date
    Jul 2024
    Posts
    28


    Did you find this post helpful? Yes | No

    Default Re: Interrupt block with different exit?

    Greetings Richard,

    thanks for the reply.
    I thought that the interrupt would still work (at least the detection part) even if we didn't want to go back to the code.
    In that case i will need to do what you are suggesting and add periodic checks (in the normal code sequence) for a flag change done by the interrupts.

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,641


    Did you find this post helpful? Yes | No

    Default Re: Interrupt block with different exit?

    Hi,

    you can return wherever you want at the end of an interrupt stubb ...

    I did it some years ago ... but Darrel did not like it at all !!! ( )

    just have a look to the asm code generated and you will understand why and how !

    the trick lies on the DEFINE INTHAND + RESUME _Label use ...

    RESUME _Label gives

    - bsf Intcon.7
    - GOTO _Label

    and _ Label is a PBP stubb ... where you want to jump to ...

    for the moment, I have to dig out the program I wrote ...

    Alain
    Last edited by Acetronics2; - 6th February 2025 at 20:55.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,098


    Did you find this post helpful? Yes | No

    Default Re: Interrupt block with different exit?

    Yes, if you really, really know what you are doing and spend hours on the asm code to double and triple check the code flow.

    Ioannis
    Last edited by Ioannis; - 7th February 2025 at 08:15.

  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    2,623


    Did you find this post helpful? Yes | No

    Default Re: Interrupt block with different exit?

    it only works for and with ON INTERRUPT, and that's not a real interrupt
    Warning I'm not a teacher

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,641


    Did you find this post helpful? Yes | No

    Default Re: Interrupt block with different exit?

    Quote Originally Posted by richard View Post
    it only works for and with ON INTERRUPT, and that's not a real interrupt
    Hi, Richard

    just open your Holy Manual @ asm interrupts page ...

    as Ioannis states ... It's better to know what you are doing here ...

    Our friend Paul was just asking if it was possible

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  8. #8
    Join Date
    Jul 2024
    Posts
    28


    Did you find this post helpful? Yes | No

    Default Re: Interrupt block with different exit?

    Hi guys,

    dos this makes any sense to you?
    I added a debugin line with timeout and jump label inside my interrupt block and this is causing the code not work as expected as well!

    RBCinterrupts:

    @ INT_DISABLE RBC_INT

    debug "trigger detected...", 13,10

    DEBUGIN 2000,JUMPOUT,[WAIT("MCU-"), DEC MOODCAP]

    debug "debugin passed...", 13,10


    RBIF=0
    INTFLAG=1


    DEBUG "returning...",13,10


    @ INT_RETURN
    Debugin jump block:


    JUMPOUT:


    DEBUG "fail debugin...",13,10

    @ INT_RETURN

  9. #9
    Join Date
    May 2013
    Location
    australia
    Posts
    2,623


    Did you find this post helpful? Yes | No

    Default Re: Interrupt block with different exit?

    dos this makes any sense to you?(sic)
    there are a number of issues here

    @ INT_DISABLE RBC_INT
    this is most likely pointless. a pic can execute one and only one interrupt at a time, only a low priority interrupt can be interrupted
    i will assume this is not one of them. once again code snippets are fairly useless as they never tell the whole story.

    RBIF=0
    once again code snippets are fairly useless they never tell the whole story. what port /pins is debug using. rbif can only be cleared if the portb mismatch condition has been cleared, there is no evidence this is happening.
    see data sheet portb section re clearing mismatch condition.

    performing all that serial comms in an isr is not a good practice.
    if your code can tolerate that lengthy sort of interruption then there are most likely better ways to get a similar result other than by isr

    its unclear which portb pins are inputs, which pin or pins have triggered the interrupt as you make no efforts to distinguish the source of the interrupt. this may or may not be relevant, snippets why bother
    Warning I'm not a teacher

  10. #10
    Join Date
    Jul 2024
    Posts
    28


    Did you find this post helpful? Yes | No

    Default Re: Interrupt block with different exit?

    Greetings Richard,

    thanks for the help.

    The code is still under development...i'm progressing while resolving issues...

    Code:
    ;----[18F2580 Hardware Configuration]-------------------------------------------
    #IF __PROCESSOR__ = "18F2580"
      #DEFINE MCU_FOUND 1
    #CONFIG
      CONFIG  OSC = IRCIO67      ; Internal oscillator block, port function on RA6 and RA7
      CONFIG  FCMEN = OFF        ; Fail-Safe Clock Monitor disabled
      CONFIG  IESO = OFF         ; Oscillator Switchover mode disabled
      CONFIG  PWRT = ON         ; PWRT enabled
      CONFIG  BOREN = OFF        ; Brown-out Reset disabled in hardware and software
      CONFIG  BORV = 3           ; VBOR set to 2.1V
      CONFIG  WDT = OFF          ; WDT disabled (control is placed on the SWDTEN bit)
      CONFIG  WDTPS = 512        ; 1:512
      CONFIG  PBADEN = OFF       ; PORTB<4:0> pins are configured as digital I/O on Reset
      CONFIG  LPT1OSC = OFF      ; Timer1 configured for higher power operation
      CONFIG  MCLRE = OFF        ; RE3 input pin enabled; MCLR disabled
      CONFIG  STVREN = ON        ; Stack full/underflow will cause Reset
      CONFIG  LVP = OFF          ; Single-Supply ICSP disabled
      CONFIG  BBSIZ = 1024       ; 1K words (2K bytes) boot block
      CONFIG  XINST = OFF        ; Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
      CONFIG  DEBUG = OFF        ; Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins
      CONFIG  CP0 = OFF          ; Block 0 (000800-001FFFh) not code-protected
      CONFIG  CP1 = OFF          ; Block 1 (002000-003FFFh) not code-protected
      CONFIG  CP2 = OFF          ; Block 2 (004000-005FFFh) not code-protected
      CONFIG  CP3 = OFF          ; Block 3 (006000-007FFFh) not code-protected
      CONFIG  CPB = OFF          ; Boot block (000000-0007FFh) not code-protected
      CONFIG  CPD = OFF          ; Data EEPROM not code-protected
      CONFIG  WRT0 = OFF         ; Block 0 (000800-001FFFh) not write-protected
      CONFIG  WRT1 = OFF         ; Block 1 (002000-003FFFh) not write-protected
      CONFIG  WRT2 = OFF         ; Block 2 (004000-005FFFh) not write-protected
      CONFIG  WRT3 = OFF         ; Block 3 (006000-007FFFh) not write-protected
      CONFIG  WRTC = OFF         ; Configuration registers (300000-3000FFh) not write-protected
      CONFIG  WRTB = OFF         ; Boot block (000000-0007FFh) not write-protected
      CONFIG  WRTD = OFF         ; Data EEPROM not write-protected
      CONFIG  EBTR0 = OFF        ; Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
      CONFIG  EBTR1 = OFF        ; Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
      CONFIG  EBTR2 = OFF        ; Block 2 (004000-005FFFh) not protected from table reads executed in other blocks
      CONFIG  EBTR3 = OFF        ; Block 3 (006000-007FFFh) not protected from table reads executed in other blocks
      CONFIG  EBTRB = OFF        ; Boot block (000000-0007FFh) not protected from table reads executed in other blocks
    #ENDCONFIG
    
    
    #ENDIF
    
    
    ;----[Verify Configs have been specified for Selected Processor]----------------
    ;       Note: Only include this routine once, after all #CONFIG blocks
    #IFNDEF MCU_FOUND
      #ERROR "No CONFIGs found for [" + __PROCESSOR__ +"]"
    #ENDIF
    
    
    '*****************************************************************************
    
    
    OSCCON =%01110000 '8MHz INTOSC
    OSCTUNE=%11000000 'PLLEN enabled
    
    
    DEFINE OSC 32
    
    
    '*****************************************************************************
    
    
    INCLUDE "ALLDIGITAL.pbp"
    DEFINE SHOWDIGITAL 1
    
    
    '*****************************************************************************
    
    
    INCLUDE "DT_INTS-18.bas"     		; Base Interrupt System
    INCLUDE "ReEnterPBP-18.bas"     	; Include if using PBP interrupts
    
    
    '*****************************************************************************
    INCLUDE "modedefs.bas" 
    
    
    'DEFINE DEBUG_REG PORTC  
    'DEFINE DEBUG_BIT 0
    
    
    DEFINE DEBUGIN_REG PORTB  
    DEFINE DEBUGIN_BIT 5
    
    
    DEFINE DEBUG_BAUD 9600
    DEFINE DEBUG_MODE 0		' Set Debug mode: 0 = true, 1 = inverted
    
    
    'Inverted mode should idle low.
    'True mode should idle high.
    
    
    '*****************************************************************************
    
    
    PORTA=%00000000
    PORTB=%00000000
    PORTC=%00000000
    
    
    TRISA=%00000000				
    TRISB=%00100000
    TRISC=%00000000
    
    
    '*****************************************************************************
    'PORTS & PINS 
    
    
    RED1			var		PORTC.1 
    RED2 			var		PORTC.2 
    IC_TX			var		PORTC.0  'DEBUG OUT
    RED3			var		PORTA.6 	
    RED4			var		PORTB.4 
    RED5			var		PORTA.7 
    RED6 			var 	PORTB.0 
    
    
    GREEN1			var		PORTC.7 
    GREEN2 			var		PORTB.1 
    GREEN3 			var		PORTB.2 
    GREEN4 			var		PORTB.3 
    GREEN5			var		PORTC.3 
    GREEN6			var		PORTC.4 
    GREEN7			var		PORTC.5 
    GREEN8			var		PORTC.6 
    
    
    BLUE1			var		PORTA.5 
    BLUE2			var		PORTA.4 
    BLUE3			var		PORTA.3 
    BLUE4			var		PORTA.2 
    BLUE5			var		PORTA.1 
    BLUE6			var		PORTA.0 
    BLUE7			var		PORTB.7 
    BLUE8			var		PORTB.6 
    
    
    IC_RX			var		PORTB.5	 'INPUT
    
    
    'Communication between MCUs (COMM)---------------------
    'PORTB.5 IC5 COMM (use interrupt on change to detect start of communication)
    
    
    PA1   		VAR 	WORD
    
    
    MOOD		VAR		WORD
    MOODOLD		VAR		WORD
    MOODCAP		VAR		WORD
    INTFLAG		VAR		BYTE
    MOODCHANGE	VAR		WORD
    
    
    '*****************************************************************************
    'PBP RBC Interrupts
    
    
    '---[INT - interrupt handler]---------------------------------------------------
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler  RBC_INT,    _RBCinterrupts,    PBP,  yes
    endm
    INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    
    RBIF var INTCON.0			'alias to RBIF bit of INTCON	
    INTCON2.0=1					'HIGH PRIORITY
    
    
    '*****************************************************************************
    INIT:
    
    
    clear
    
    
    PA1=2000
    
    
    MOOD=1
    MOODCAP=0
    
    
    INTFLAG=0
    MOODCHANGE=0
    moodold=mood
    
    
    GOSUB SYNC_ICS
    
    
    pause 1000
    
    
    GOTO START
    
    
    '-----------------------------------------------------------------
    SYNC_ICS:
    
    
    debug "Init pulse check...", 13,10
    
    
    IF IC_RX=1 THEN
    	WHILE IC_RX
    	WEND
    	RETURN
    ELSE
    	GOTO SYNC_ICS
    ENDIF
    
    
    RETURN
    
    
    '--------------------------------------------------------
    START:
    
    
    pause 400
    
    
    HIGH RED1
    HIGH GREEN1
    HIGH BLUE1
    
    
    pause 400
    
    
    GOTO RED
    
    
    '-----------------------------------------------------------------
    RBCinterrupts:
    
    
    @ INT_DISABLE RBC_INT
    
    
    debug "trigger detected...", 13,10
    
    
    DEBUGIN 2000,JUMPOUT,[WAIT("MCU-"), DEC MOODCAP]
    
    
    debug "debugin passed...", 13,10
    
    
    IF MOODCAP>0 AND MOODCAP<6 THEN
    	MOOD=MOODCAP
    ENDIF
    
    
    IF MOOD=MOODOLD THEN
    	MOODCHANGE=0
    ELSE
    	MOODCHANGE=1
    	MOODOLD=MOOD
    ENDIF
    
    
    RBIF=0
    INTFLAG=1
    
    
    DEBUG "returning...",13,10
    
    
    @ INT_RETURN
    
    
    '--------------------------------------------------------
    JUMPOUT:
    
    
    DEBUG "fail debugin...",13,10
    
    
    RBIF=0
    INTFLAG=0
    
    
    @ INT_RETURN
    
    
    '--------------------------------------------------------
    MOODCHECK:
    
    
    SELECT CASE MOOD
    
    
    CASE  1
    		GOTO RED
    CASE  2
    		GOTO GREEN
    CASE  3
    		GOTO BLUE
    CASE  4
    		GOTO SHUTDOWN
    CASE  5
    		GOTO LIGHT_TEST
    	
    END SELECT
    
    
    '--------------------------------------------------------
    VALIDAT:
    
    
    IF INTFLAG=1 THEN
    	INTFLAG=0
    	if MOODCHANGE=1 then
    		MOODCHANGE=0
    		goto MOODCHECK
    	endif
    	return
    else
    	return
    ENDIF
    
    
    '-----------------------------------------------------------------
    
    
    LIGHT_TEST:
    
    
    'INTCON=%11000000
    'INTCON.0=0
    RBIF=0
    
    
    'enable interrupt
    @ INT_ENABLE RBC_INT
    
    
    LOW GREEN1
    LOW GREEN2
    LOW GREEN3
    LOW GREEN4
    LOW GREEN5
    LOW GREEN6
    LOW GREEN7
    LOW GREEN8
    
    
    LOW BLUE1
    LOW BLUE2
    LOW BLUE3
    LOW BLUE4
    LOW BLUE5
    LOW BLUE6
    LOW BLUE7
    LOW BLUE8
    
    
    LOW RED1
    LOW RED2
    LOW RED3
    LOW RED4
    LOW RED5
    LOW RED6
    
    
    gosub validat
    
    
    PAUSE PA1
    
    
    HIGH GREEN1
    HIGH GREEN2
    HIGH GREEN3
    HIGH GREEN4
    HIGH GREEN5
    HIGH GREEN6
    HIGH GREEN7
    HIGH GREEN8
    
    
    HIGH BLUE1
    HIGH BLUE2
    HIGH BLUE3
    HIGH BLUE4
    HIGH BLUE5
    HIGH BLUE6
    HIGH BLUE7
    HIGH BLUE8
    
    
    HIGH RED1
    HIGH RED2
    HIGH RED3
    HIGH RED4
    HIGH RED5
    HIGH RED6
    
    
    gosub validat
    
    
    PAUSE PA1
    
    
    GOTO LIGHT_TEST
    
    
    '-----------------------------------------------------------------
    
    
    RED:
    
    
    'INTCON=%11000000
    'INTCON.0=0
    RBIF=0
    
    
    'enable interrupt
    @ INT_ENABLE RBC_INT
    
    
    LOW GREEN1
    LOW GREEN2
    LOW GREEN3
    LOW GREEN4
    LOW GREEN5
    LOW GREEN6
    LOW GREEN7
    LOW GREEN8
    
    
    LOW BLUE1
    LOW BLUE2
    LOW BLUE3
    LOW BLUE4
    LOW BLUE5
    LOW BLUE6
    LOW BLUE7
    LOW BLUE8
    
    
    HIGH RED1
    HIGH RED2
    HIGH RED3
    HIGH RED4
    HIGH RED5
    HIGH RED6
    
    
    gosub validat
    
    
    GOTO RED
    
    
    '--------------------------------------------------------
    SHUTDOWN:
    
    
    'INTCON=%11000000
    'INTCON.0=0
    RBIF=0
    
    
    'enable interrupt
    @ INT_ENABLE RBC_INT
    
    
    PAUSE 10000
    
    
    LOW GREEN1
    LOW GREEN2
    LOW GREEN3
    LOW GREEN4
    LOW GREEN5
    LOW GREEN6
    LOW GREEN7
    LOW GREEN8
    
    
    LOW BLUE1
    LOW BLUE2
    LOW BLUE3
    LOW BLUE4
    LOW BLUE5
    LOW BLUE6
    LOW BLUE7
    LOW BLUE8
    
    
    LOW RED1
    LOW RED2
    LOW RED3
    LOW RED4
    LOW RED5
    LOW RED6
    
    
    end
    
    
    
    
    '--------------------------------------------------------
    GREEN:
    
    
    DEBUG "GREEN ON...",13,10
    
    
    'INTCON=%11000000
    'INTCON.0=0
    RBIF=0
    
    
    'enable interrupt
    @ INT_ENABLE RBC_INT
    
    
    HIGH GREEN1
    HIGH GREEN2
    HIGH GREEN3
    HIGH GREEN4
    HIGH GREEN5
    HIGH GREEN6
    HIGH GREEN7
    HIGH GREEN8
    
    
    LOW BLUE1
    LOW BLUE2
    LOW BLUE3
    LOW BLUE4
    LOW BLUE5
    LOW BLUE6
    LOW BLUE7
    LOW BLUE8
    
    
    LOW RED1
    LOW RED2
    LOW RED3
    LOW RED4
    LOW RED5
    LOW RED6
    
    
    gosub validat
    
    
    GOTO GREEN
    
    
    '--------------------------------------------------------
    BLUE:
    
    
    DEBUG "BLUE ON...",13,10
    
    
    'INTCON=%11000000
    'INTCON.0=0
    RBIF=0
    
    
    'enable interrupt
    @ INT_ENABLE RBC_INT
    
    
    LOW GREEN1
    LOW GREEN2
    LOW GREEN3
    LOW GREEN4
    LOW GREEN5
    LOW GREEN6
    LOW GREEN7
    LOW GREEN8
    
    
    HIGH BLUE1
    HIGH BLUE2
    HIGH BLUE3
    HIGH BLUE4
    HIGH BLUE5
    HIGH BLUE6
    HIGH BLUE7
    HIGH BLUE8
    
    
    LOW RED1
    LOW RED2
    LOW RED3
    LOW RED4
    LOW RED5
    LOW RED6
    
    
    gosub validat
    
    
    GOTO BLUE
    '--------------------------------------------------------
    Last edited by Ioannis; - 11th February 2025 at 14:37.

  11. #11
    Join Date
    May 2013
    Location
    australia
    Posts
    2,623


    Did you find this post helpful? Yes | No

    Default Re: Interrupt block with different exit?

    just a few comments

    trying to capture a serial stream with a bit-banged routine triggered from an isr is difficult to make reliable far better to use the eusart module.
    to reset rbcif flag you need to make sure the pin involved is in a steady state[ not still receiving data] and do a read of portb immediately before exiting isr
    alias your leds to lat regs not ports, dont use high/low
    be aware that a pic-chip is not a power supply there is a maximum total pin current
    your code seems to call validat over and over an over yet never returns , the stack won't be happy about that

    Name:  Untitled.jpg
Views: 713
Size:  230.0 KB
    Warning I'm not a teacher

  12. #12
    Join Date
    Jul 2024
    Posts
    28


    Did you find this post helpful? Yes | No

    Default Re: Interrupt block with different exit?

    Greetings Richard,

    sorry for the late reply... Been busy lately...

    Will check all your suggestions, thanks for that.

    Just one question regarding this one: "alias your leds to lat regs not ports, dont use high/low"

    You mean using "Green var LATC.0" instead of "Green var PORTC.0" and use "Green=1" instead of "high Green" ?

    Thanks

    Best regards

  13. #13
    Join Date
    May 2013
    Location
    australia
    Posts
    2,623


    Did you find this post helpful? Yes | No

    Default Re: Interrupt block with different exit?

    you mean using "Green var LATC.0" instead of "Green var PORTC.0" and use "Green=1" instead of "high Green" ?
    that's it

    just to keep my hand in i made this, one with the lot [ slight differences in led pins]

    Code:
    #CONFIG
        CONFIG OSC = IRCIO67 ; Internal oscillator block, port function on RA6 and RA7
        CONFIG FCMEN = OFF ; Fail-Safe Clock Monitor disabled
        CONFIG IESO = OFF ; Oscillator Switchover mode disabled
        CONFIG PWRT = ON ; PWRT enabled
        CONFIG BOREN = OFF ; Brown-out Reset disabled in hardware and software
        CONFIG BORV = 3 ; VBOR set to 2.1V
        CONFIG WDT = OFF ; WDT disabled (control is placed on the SWDTEN bit)
        CONFIG WDTPS = 512 ; 1:512
        CONFIG PBADEN = OFF ; PORTB<4:0> pins are configured as digital I/O on Reset
        CONFIG LPT1OSC = OFF ; Timer1 configured for higher power operation
        CONFIG MCLRE = OFF ; RE3 input pin enabled; MCLR disabled
        CONFIG STVREN = ON ; Stack full/underflow will cause Reset
        CONFIG LVP = OFF ; Single-Supply ICSP disabled
        CONFIG BBSIZ = 1024 ; 1K words (2K bytes) boot block
        CONFIG XINST = OFF ; Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
        CONFIG DEBUG = OFF ; Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins
        CONFIG CP0 = OFF ; Block 0 (000800-001FFFh) not code-protected
        CONFIG CP1 = OFF ; Block 1 (002000-003FFFh) not code-protected
        CONFIG CP2 = OFF ; Block 2 (004000-005FFFh) not code-protected
        CONFIG CP3 = OFF ; Block 3 (006000-007FFFh) not code-protected
        CONFIG CPB = OFF ; Boot block (000000-0007FFh) not code-protected
        CONFIG CPD = OFF ; Data EEPROM not code-protected
        CONFIG WRT0 = OFF ; Block 0 (000800-001FFFh) not write-protected
        CONFIG WRT1 = OFF ; Block 1 (002000-003FFFh) not write-protected
        CONFIG WRT2 = OFF ; Block 2 (004000-005FFFh) not write-protected
        CONFIG WRT3 = OFF ; Block 3 (006000-007FFFh) not write-protected
        CONFIG WRTC = OFF ; Configuration registers (300000-3000FFh) not write-protected
        CONFIG WRTB = OFF ; Boot block (000000-0007FFh) not write-protected
        CONFIG WRTD = OFF ; Data EEPROM not write-protected
        CONFIG EBTR0 = OFF ; Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
        CONFIG EBTR1 = OFF ; Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
        CONFIG EBTR2 = OFF ; Block 2 (004000-005FFFh) not protected from table reads executed in other blocks
        CONFIG EBTR3 = OFF ; Block 3 (006000-007FFFh) not protected from table reads executed in other blocks
        CONFIG EBTRB = OFF ; Boot block (000000-0007FFh) not protected from table reads executed in other blocks
    #ENDCONFIG
    
    
    DEFINE OSC 32
    
    
    INCLUDE "DT_INTS-18.bas" ; Base Interrupt System
    INCLUDE "ReEnterPBP-18.bas" ; Include if using PBP interrupts
    
    
    
    
     
        OSCCON = %01110000 '8MHz INTOSC
        OSCTUNE.6 = 1 'PLLEN enabled
        LATA = % 00000000
        LATB = % 00000000
        LATC = % 00000000
        
        TRISA = % 00000000
        TRISB = % 00000000
        TRISC = % 11000000
        ADCON1 = 15
        RCSTA = $90   ' Enable serial port & continuous receive
        TXSTA = $24   ' Enable transmit, BRGH = 1
        SPBRG = 64    ' 9600 Baud @ 32MHz, 0.04%
        SPBRGH = 3
        BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
        
        IC_TX  var PORTC.6 'DEBUG OUT
        IC_RX  var PORTC.7 'INPUT
    RED1			var		PORTC.1 
    RED2 			var		PORTC.2
    RED3			var		PORTA.6 	
    RED4			var		PORTB.4 
    RED5			var		PORTA.7 
    RED6 			var 	PORTB.0 
    
    
    GREEN1			var		PORTB.5
    GREEN2 			var		PORTB.1 
    GREEN3 			var		PORTB.2 
    GREEN4 			var		PORTB.3 
    GREEN5			var		PORTC.3 
    GREEN6			var		PORTC.4 
    GREEN7			var		PORTC.5 
    GREEN8			var		PORTC.0 
    
    
    BLUE1			var		PORTA.5 
    BLUE2			var		PORTA.4 
    BLUE3			var		PORTA.3 
    BLUE4			var		PORTA.2 
    BLUE5			var		PORTA.1 
    BLUE6			var		PORTA.0 
    BLUE7			var		PORTB.7 
    BLUE8			var		PORTB.6
        
        PA1        VAR WORD
        BUFFERB    VAR BYTE[10]
        MOOD       VAR BYTE
        MOODCAP    VAR BYTE
        rxb_B_C    VAR BYTE
        INTFLAG    VAR BYTE
        MOODCHANGE VAR BYTE
        
        maxq con 32
        prnb var byte[maxq] 
        spos var byte bank0
        rpos var byte bank0
        HEAD VAR BYTE [32]
        I VAR BYTE
        J VAR BYTE 
        K VAR BYTE
        
        
        
    
    
    @milies  = _TICKS       ; LOW 16
    @seconds = _TICKS+1     ;UPPER 16
        
        FLG               var byte   
        milies            var word ext  ;4mS TICKS
        seconds           var word ext  ;COUNTS IN SECONDS     3.906mS*256
        now               var word 
        seconds_changed   VAR FLG.0
        TICKS             var byte[3]     ;24 BIT TIME KEEPING   ticks[1]+[2] is in seconds
        Timer3Reload      CON 49914     ;3906uS          1/256 second  @32mHz clk div2         
        clear
    
    
    '---[INT - interrupt handler]---------------------------------------------------
    ASM
    INT_LIST macro ; IntSource, Label, Type, ResetFlag?
         INT_Handler RX_INT, _RXB, PBP, yes
         INT_Handler TMR3_INT,  TICK,  ASM,  YES
         INT_Handler TX_INT  , _do_tx, asm,no
         endm
         INT_CREATE ; Creates the interrupt processor
    ENDASM
        pause 1000
        ARRAYWRITE head, ["READY", 13,10 ]
        GOSUB MYPRINT
        pause 400
        GOSUB setrgb1 
        pause 400
    
    
    START:
        rxb_B_C = 0
        MOOD = 1
        MOODCHANGE = 1
        MOODCAP = 1
        RCSTA.4 = 0  ;clear any rcsta error
        RCSTA.4 = 1
        INTCON = $C0
        PIR2.1=0
        @ INT_ENABLE RX_INT
        @ INT_ENABLE TMR3_INT
        PIE2.1=1
        t3con = $11 
              
           
    main:
        GOsub get_now
        GOsub   MOODCHECK
       
        IF INTFLAG = 1 THEN
        INTFLAG = 0
        rxb_B_C = 0
        RCSTA.4 = 0  ;clear any rcsta error
        RCSTA.4 = 1
        @ INT_ENABLE RX_INT
        ARRAYREAD BUFFERB,10,dud,[wait("MCU-"), DEC1 MOODCAP  ]
        IF  MOODCAP != MOOD  THEN MOODCHANGE = 1
            ARRAYWRITE head, [10,"NEW MOOD ",DEC MOODCAP, 13,10]
            GOSUB MYPRINT
        endif
        if MOODCHANGE = 1 then
            IF  MOODCAP < 6 THEN
                MOOD = MOODCAP
                MOODCHANGE = 0
                gosub clr_rgb
            ELSE
               MOODCHANGE = 0
               GOTO DUD 
            endif
        endif
        PAUSE 10
    goto main
            dud: 
            ARRAYWRITE head, ["DUD MOOD", 13,10]
            GOSUB MYPRINT
    goto main
    
    
    
    
    END
    
    
    
    
    MOODCHECK:
        SELECT CASE MOOD
        CASE 1
            GOsub RED
        CASE 2
            GOsub GREEN
        CASE 3
            GOsub BLUE
        CASE 4
            GOsub SHUTDOWN
        CASE 5
             PA1 = NOW
             MOOD = 6
             GOsub LIGHT_ONTEST
        CASE 6     
             IF NOW - PA1 > 250 THEN  
             GOsub LIGHT_OFFTEST
             MOOD = 7
             PA1 = NOW
             ENDIF
        CASE 7     
             IF NOW - PA1 > 250 THEN MOOD = 5
        END SELECT
    return
    
    
    LIGHT_ONTEST:
            gosub red
            gosub BLUE
            gosub GREEN
    return    
    
    
    LIGHT_OFFTEST:
            gosub clr_rgb
    return
    	
    	
    RED: ; PORTC.1    PORTC.2  PORTA.6 PORTB.4  PORTA.7  PORTB.0
        LATA = LATA |  192
        LATB = LATB |  17
        LATC = LATC |  6
    return
    
    
    SHUTDOWN:
        gosub clr_rgb
    return
    	
    GREEN: ; PORTB.5 PORTB.1 PORTB.2 PORTB.3 PORTC.3 PORTC.4 PORTC.5 PORTC.0 
        LATB = LATB | 46 
        LATC = LATC | 57
    return
    		
    BLUE: ; PORTA.5  PORTA.4 PORTA.3 PORTA.2  PORTA.1 PORTA.0 PORTB.7 PORTB.6
        LATA = LATA |  63
        LATB = LATB |  192
    return
    
    
    setrgb1:
        LATA = 32
        LATB = 32
        LATC = 2
    RETURN
    
    
    clr_rgb:
        LATA = 0
        LATB = 0
        LATC = LATC & ~63
    RETURN 
       
    
    
    RXB:
        WHILE PIR1.5
            BUFFERB[rxb_B_C] = RCREG
            IF (rxb_B_C >= 9)|| (BUFFERB[rxb_B_C] == 13)  THEN 
            PIE1.5 = 0
            INTFLAG = 1
            BUFFERB[rxb_B_C] = 0
            else
            rxb_B_C = rxb_B_C + 1
            endif   
        WEND
    @ INT_RETURN 
              
    asm 
    TICK            ;isr
        BANKSEL   T3CON
        MOVE?CT 0, T3CON, TMR3ON ; stop timer
        MOVLW LOW(_Timer3Reload) ; Add TimerReload
        ADDWF TMR3L,F
        BTFSC STATUS,C
        INCF TMR3H,F
        MOVLW HIGH(_Timer3Reload)
        ADDWF TMR3H,F
        MOVE?CT 1, T3CON, TMR3ON ; start timer
        MOVLW LOW(  _TICKS)      ;inc 24
        movwf FSR0L
        MOVLW HIGH(  _TICKS)
        movwf FSR0H
        BCF STATUS,Z
        incfsz  POSTINC0,F
        BRA I24D
        BANKSEL _FLG
        BSF  _FLG ,0             ;seconds_changed
        incfsz  POSTINC0,F
        BRA I24D
        incf  INDF0,F
    I24D 
        INT_RETURN
    endASM 
    
    
    
    
    do_tx:
    asm  
        BANKSEL  _rpos
        movf   _spos,W    ;if rpos==spos then buffer is empty 
        subwf  _rpos,W 
        btfsC  STATUS,Z   
        bra    LX
    txb movlw   High _prnb  ;Store the High byte of buffer to FSR0H
        movwf   FSR0H
        movlw   Low _prnb ; Get the Low byte of buffer
        addwf   _rpos,W  ; Add rpos to pointer 
        movwf   FSR0L        ; Store Low byte of pointer in FSR0
        movf    INDF0,W
        btfsc  STATUS,Z       ; if its not a null send it
        bra     ex_prn
        movwf  TXREG    
        incf   _rpos,F   ; Increment  rpos  
        movf   _rpos,W   ; Move new rpos to W
        sublw  _maxq -1      ; Subtract rposfrom buffer_size
        btfsS  STATUS, C     ; If rpos > buffer_size
        clrf   _rpos     ; Clear rpos
        BRA ex_prn  
    LX           ;if buffer empty turn ofF interrupt
        bcf    PIE1,TXIF
    ex_prn 
        ;RST?RP
        INT_RETURN  
    endasm     
     
    
    
    MYPRINT:
        J=0
        WHILE HEAD[J]
            INTCON=0
            I=SPOS+1
            K=RPOS
            INTCON=$C0
            IF ((I)==K) || ((I== MAXQ )&& (K==0) )  THEN 
                PAUSE 1
            ELSE 
                PRNB[SPOS]= HEAD[J]
                SPOS=SPOS+1
                IF SPOS=MAXQ THEN SPOS=0
                PIE1.4=1
                J=J+1
            ENDIF 
        WEND 
     RETURN 
    
    
    
    
    
    
    
    
    get_now:
        pie2.1 = 0
        NOW = milies
        pie2.1 = 1
    return
    Warning I'm not a teacher

  14. #14
    Join Date
    Jul 2024
    Posts
    28


    Did you find this post helpful? Yes | No

    Default Re: Interrupt block with different exit?

    Greetings Richard,

    thank you so much for your time. Your code looks impressive.
    There are lots of bits that I don't understand yet but it's great because I like to learn.
    Will study your code and implement the changes.

    Best regards

Similar Threads

  1. Exit from an IF/ENDIF loop with a GOTO
    By aratti in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 17th February 2014, 14:05
  2. Capture loop exit
    By spcw1234 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 10th February 2012, 21:29
  3. ASM block does not compile
    By efarook in forum mel PIC BASIC
    Replies: 2
    Last Post: - 31st May 2008, 22:42
  4. Timer Interrupt to exit a closed loop
    By duncan303 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 16th December 2007, 17:45
  5. block comment?
    By eoasap in forum General
    Replies: 5
    Last Post: - 13th October 2005, 01:32

Members who have read this thread : 11

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