Jump from ISR


Closed Thread
Results 1 to 16 of 16

Thread: Jump from ISR

  1. #1

    Default Jump from ISR

    Hi anyone.
    I am working on project and I've confronted with a problem. I want to jump from Interrupt service routine to subroutine and return from it and continue ISR.
    In other words is it possible in PBP to call a subrotine when program is executing ISR. Thanks for your reply.

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Yes it's possible... case by case, just post your code here, tell us what you want to do, and we will be able to tell you better.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3


    Did you find this post helpful? Yes | No

    Default My Code and Jump from ISR

    Hi dear Mister_e
    Thanks for your reply. Excuse me for delaying in my reply. I was too busy.
    Suppose that we have this program:

    Code:
    '*****************************************************************
    '*                         LCD Deifnes                           *
    '*****************************************************************    
        
        DEFINE LCD_DREG PORTD               ' I/O port where LCD is connected
        DEFINE LCD_DBIT 4
        DEFINE LCD_RSREG PORTD
        DEFINE LCD_RSBIT 2                  ' Register select pin
        DEFINE LCD_EREG PORTD
        DEFINE LCD_EBIT 3                   ' Enable pin
        DEFINE LCD_BITS 4                   ' 4-bit data bus
        DEFINE LCD_LINES 2                  ' LCD has 2 character lines
    
    	STATE 	var Byte
    	I 	var Byte
    	 	 
    	PORTA = 0
    	PORTB = 0
    '************************************************* ****************
    '* Interrupt Initialzing *
    '************************************************* **************** 
    
        INTCON     = %10001000 ' GIE and RBIE are set
        OPTION_REG = %10000000
    
    '************************************************* ****************
    '* Initialzation *
    '************************************************* ****************
    
        PORTB = 0
        TRISB = %00010000
    
        ON INTERRUPT GOTO DIRECTION
    
    '************************************************* ****************
    '* Main Program *
    '************************************************* ****************
    
    MAIN:
    
        lcdout $fe,1,"Main Routine"
    
        FOR I = 1 to 50 : PAUSE 10 : NEXT I ' For quick response
        GOTO MAIN
        END
    
    '************************************************* ****************
    '* Interrupt Service Routine *
    '************************************************* ****************
    
        DISABLE
    
    DIRECTION:
    
        STATE = PORTB	' End of Mismatch Condition
    
        lcdout $fe,1
        lcdout "Interrupt !!!"
    
        IF State.4 THEN
    
    	   LCDOUT $FE,$C0," LOW to HIGH "
    	
        ELSE
    
    	   LCDOUT $FE,$C0, " HIGH to LOW "
    	
        ENDIF
    	
        PAUSE 100
    
        INTCON.0 = 0
    
        RESUME
    
        ENABLE
    
        END
    When I want to move LCD display command out of ISR like below, the program doesn't work correctly!

    Code:
    '************************************************* ****************
    '* Interrupt Service Routine *
    '************************************************* ****************
    
        DISABLE
    
    DIRECTION:
    
        STATE = PORTB	' End of Mismatch Condition
    
        lcdout $fe,1
        lcdout "Interrupt !!!"
    
        IF State.4 THEN
    
    	   GOSUB L2H
    	
        ELSE
    
    	   GOSUB H2L
    	
        ENDIF
    	
        PAUSE 100
    
        INTCON.0 = 0
    
        RESUME
    
        ENABLE
    
        END
    
    L2H:
        LCDOUT $FE,$C0," LOW to HIGH "
        RETURN
    H2L:
        LCDOUT $FE,$C0," HIGH to LOW "
        RETURN

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


    Did you find this post helpful? Yes | No

    Default

    Just like with the ISR itself, ... any subroutines jumped to from the ISR must be DISABLED from further interrupts, or they will attempt to interrupt themselves.

    Moving the ENABLE line to after the H2L: subroutine should help.
    <br>
    DT

  5. #5


    Did you find this post helpful? Yes | No

    Default

    Thanks alot
    Last edited by yasser hassani; - 2nd May 2008 at 12:26.

  6. #6


    Did you find this post helpful? Yes | No

    Default My problem is ...

    Thanks Dear Taylor
    If you see the first program you'll find out infact your suggestion (Moving the ENABLE line to after the H2L: subroutine should help) is used at it. My problem is about second program.
    Suppose that I want to implement this:
    When H2L occures, the program should start displaying contents of EEPROM (We call Address). Address increments one by one till interrupt L2H occures. Now program should start displaying Address again but in this subroutine Address decrements one by one. How can I do that?
    Please help me.
    Thanks alot.

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


    Did you find this post helpful? Yes | No

    Wink Expressing the "problem" is half way to solve it ...

    Hi, Yasser

    From reading your posts, I understand you want to scan your EEPROM, increasing address way, on a PORTB.4 H to L transition and decreasing addresses on a L to H transition ...

    Ok ...

    just use a FOR - NEXT EEPROM reading loop in the main program , if a "H2L" flag is set and a FOR-NEXT-STEP-1 EEPROM loop if a "L2H" flag is set.

    Note I use 2 flags to let the initial "no transition" condition usable for something Else...

    The ONLY questions will be : do you want to toggle reading order if EEPROM reading is not complete ???
    What will you do when EEPROM reading is complete ??? ( seems you wait for further transition ... )

    This has a strange smell of "K2000 scanner" or scrolling device ... really don't know why ... LOL !

    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


    Did you find this post helpful? Yes | No

    Wink Exactly I want ...

    Thanks dear Acetronics. OK. I should explain more about my problem. Suppose that I want to read EEPROM from 0000h-05DCh. Variable Add refers to address of place that should be read and displayed on LCD. When L2H interrupt occures, program starts displaying Add on LCD. Add increments one by one. If H2L interrupt doesn't occure Add rolles over and initialize with 0000. When H2L interrupt occures program should start displaing Add and decrement it one by one. For example if Add=100 and H2L occures, program starts displaying from 100 and decrement it. Suppose that Add reaches to 0000 and L2H interrupt doesn't occure. In this case program should initialize Add with 05DCh and decrement it one by one.
    Thanks again for your attention. I wait for your suggestions.
    ----
    Regards

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by yasser hassani View Post
    If you see the first program you'll find out infact your suggestion (Moving the ENABLE line to after the H2L: subroutine should help) is used at it. My problem is about second program.
    The second program is the one I was talking about.
    The subroutines are not DISABLE'd.
    <br>
    DT

  10. #10
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,651


    Did you find this post helpful? Yes | No

    Question

    Hi, Yasser

    Ok, I begin to see ...

    How much time do the addresses contents have to be displayed on your LCD before displayin the next adress content ??? ( pause between EEPROM address increments )

    I begin to doubt seriously you need any kind of interrupt ( for the part we know ... of course)

    By the way ... which processor and memory do you use ???

    Alain

    PS: I had a moment and Threw that on the screen ...
    - Compiles Ok
    - But not tested ... the idea is here

    NO INTERRUPT !!!

    Re PS: Compiled AND Tested ...

    Code:
    ' Processor 16F877a @ 4Mhz
    
    'Yasser's light or text show
    
    '*****************************************************************************
    '*****************************************************************************
    ' 						IMPORTANT NOTE
    '*****************************************************************************
    '*****************************************************************************
    '	
    '			The 16F877a shows only 256 EEPROM Bytes ...
    '
    '       				  DO NOT ASK IT 1500 !!!
    
    '*****************************************************************************
    '*****************************************************************************
    
    '*****************************************************************************
    '*                  LCD Defines for EasyPic5                                 *
    '*****************************************************************************
      
    '    DEFINE LCD_DREG PORTB               ' I/O port where LCD is connected
    '    DEFINE LCD_DBIT 0
    '    DEFINE LCD_RSREG PORTB
    '    DEFINE LCD_RSBIT 4                  ' Register select pin
    '    DEFINE LCD_EREG PORTB
    '    DEFINE LCD_EBIT 5                   ' Enable pin
    '    DEFINE LCD_BITS 4                   ' 4-bit data bus
    '    DEFINE LCD_LINES 2                  ' LCD has 2 character lines
     
    '    DEFINE OSC 8
     '*****************************************************************************
    '*                        LCD Defines                                         *
    '******************************************************************************
      
        DEFINE LCD_DREG PORTD               ' I/O port where LCD is connected
        DEFINE LCD_DBIT 4
        DEFINE LCD_RSREG PORTD
        DEFINE LCD_RSBIT 2                  ' Register select pin
        DEFINE LCD_EREG PORTD
        DEFINE LCD_EBIT 3                   ' Enable pin
        DEFINE LCD_BITS 4                   ' 4-bit data bus
        DEFINE LCD_LINES 2                  ' LCD has 2 character lines   
    '*****************************************************************************
    'Chip initialization
    
    	ADCON0 	= 0
    	ADCON1 	= 7
    	CMCON	= 7
    	CVRCON	= 0
    	 
    '*****************************************************************************
    'Variables & aliases
    
    '	Scroll			var PORTA.0					' Start and Scroll up/dn button
    	Scroll			var PORTB.4					' Start and Scroll up/dn button
    
    
    	Index 			var Word
    	I				var Word
    	
    	Delay 			var Byte
    	Value			var Byte
    	
    	Cold			var Bit
    	
    'Variables initialization
    
    CLEAR
    
    	Cold	= 1
    
    '*****************************************************************************
    'Constants
    
    	Endaddress 		CON $FF' 05DC			'Memory last address to read
    	ScrollPause		CON 400					'ReadPause duration in ms
    	
    '*****************************************************************************
    'PORTS Initialization
    	 	 
    	PORTA = 0
    	PORTB = 0
    	PORTC = 0
    	PORTD = 0
    	PORTE = 0
    	TRISA = 0
    	TRISB = %00010000
    	TRISC = 0
    	TRISD = 0
    	
    '*****************************************************************************
    'LCD Initialization
    
    LCDOUT $FE,1								'Clearscreen
    PAUSE 700
    	
    '*****************************************************************************
    '*****************************************************************************
    Coldstart:
    
    Delay = 0
    BUTTON Scroll,1,255,0,delay,1,Released
    		
    IF cold THEN 
    
    	LCDOUT $FE,$80," Hello Yasser  " 	' Waiting Message
    	LCDOUT $FE,$C0,"Waiting for you"
    	cold = 0
    	
    ENDIF
    
    goto ColdStart
    
    Released:
    
    Delay = 0
    BUTTON Scroll,1,255,0,delay,1, Released	' Wait for button release
    
    LCDOUT $FE,1						'Clear Screen
    
    
    Increase:
    
    	Index = I
    	
    	FOR I = Index to (Endaddress - 1) Step 2
    
        	READ I,Value
    		LCDOUT $FE,$80, BIN8 Value,"  ",DEC3 I			'BIN8 for Binary, may be decimal or character
    		READ I+1,Value						
    		LCDOUT $FE,$C0, BIN8 Value,"  ",DEC3 I+1
    		PAUSE ScrollPause
            	
    		Delay = 0
    		BUTTON Scroll,1,255,0,delay,1,Decrease		'Reverse Scrolling requested ?
    				
    	NEXT I
    	
    	I = 0							'No toggle ... let's rewind	Index = 0
    	Goto Increase
    	
    	
    Decrease:
    
    	Index = I
    	FOR I = Index to 1 Step - 2
    
       	    READ I,Value
    		LCDOUT $FE,$80, BIN8 Value,"  ",DEC3 I			'BIN8 for Binary, may be decimal or character
    		READ I+1,Value						             
    		LCDOUT $FE,$C0, BIN8 Value,"  ",DEC3 I+1
    		PAUSE ScrollPause
    			
    		Delay = 0
    		BUTTON Scroll,1,255,0,delay,0,Increase		'Continue Reverse scrolling ?
    			
    	NEXT I
    	
    	I = EndAddress -1 							'No toggle ...let's rewind	Index = Endaddress		
    	Goto Decrease
    	
    
    	END
    Last edited by Acetronics2; - 4th May 2008 at 18:36. Reason: a little mismatch between I and Index ... LOL !!!
    ************************************************** ***********************
    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 " !!!
    *****************************************

  11. #11


    Did you find this post helpful? Yes | No

    Default Reading from serial eeprom

    Hi dear Acentronics.
    Thank you very much for your helpful program. Sorry for my delay!! I found out I can write program without interrupt. I simulated your program with proteus. It worked correct.
    I want to use PIC16F877.
    I know that micro's eeprom hasn't 1500b memory.
    You know, I want to use serial eeprom for example 24c04 (4K bit)
    Can you help me about changes on your written program for using serial eeprom ?
    I think that I should use i2cread command like below:

    i2cread sda , scl , ctw , I , Value

    ==================
    Again more and more thanks.
    Regards

  12. #12
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,651


    Did you find this post helpful? Yes | No

    Smile

    Quote Originally Posted by yasser hassani View Post

    I simulated your program with proteus. It worked correct.
    I want to use PIC16F877.
    Hi, Yasser

    It's up to you to choose which pic you want to use ( they call it "democracy" . LOL ) ... just note LCD + ext EEPROM + 1 Pushbutton can be driven by a 18 Pins Pic... not to say a 16C84 ...

    [Humour]

    Simulation, simulation, ... that do not exist in the real World ... Last time I tried to simulate a 555 on that thing ( démo example GIVEN !!! ) ... just returned me "ERROR" !!!
    This soft is sold ... 15000 US $ !!!

    The 555 on its bredboard was working fine ...

    [/Humour]

    I know that micro's eeprom hasn't 1500b memory.
    You know, I want to use serial eeprom for example 24c04 (4K bit)
    Also note 1500 BYTES need a 24LC16 to fit into ( 1500 *8 = 12000 ...)

    Can you help me about changes on your written program for using serial eeprom ?
    I think that I should use i2cread command like below:

    i2cread sda , scl , ctw , I , Value
    Something like that ... yes !

    I'm not so used to external EEPROMs ... so, I'll need some little hours to "update" my knowledge ... but I've seen that subjects have been fully covered on this Forum ...

    I will encourage you to carefully read the 5.34 and 5.35 $ of the new and "Web" manuals, ( 5.29 and 5.30 Oooooold one ) as there is interreaction between the control Word and addresses for those EEPROMS ...

    I keep on the line ...

    read you soon

    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 " !!!
    *****************************************

  13. #13
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by yasser hassani View Post
    I want to use PIC16F877.
    I know that micro's eeprom hasn't 1500b memory.
    You know, I want to use serial eeprom for example 24c04 (4K bit)
    Might not have 1500 bytes of eeprom, but I'd be willing to bet that you'd have an extra 1500 bytes of program memory left to use.

    Can you help me about changes on your written program for using serial eeprom ?
    I think that I should use i2cread command like below:
    i2cread sda , scl , ctw , I , Value
    I'd also be willing to bet that there's something about the I2CREAD command in the manual...

  14. #14


    Did you find this post helpful? Yes | No

    Smile Thanks

    Special thanks from dear friends that help me in this thread.
    I use I2CREAD and it works excellent.
    ========
    Regards

  15. #15
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,651


    Did you find this post helpful? Yes | No

    Smile

    Hi, Yasser

    It's a pleasure for us too ... to know you're happy with your project !

    Regards

    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 " !!!
    *****************************************

  16. #16
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    For 15K$ you can't buy a head... but a least you'll be well equipped

    Proteus and ALL simulators in general = b u l l s h i t

    Nothing beat a head and real parts on a board... that gives REAL results + possible layout behaviour... the real thing.

    Add some test equipment, and you're in business.

    Sim are for lazy people.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. DT-Ints latency and other interrupt conciderations
    By HenrikOlsson in forum mel PIC BASIC Pro
    Replies: 58
    Last Post: - 12th March 2010, 18:27
  2. ELSEIF Block Would be Good.
    By T.Jackson in forum PBP Wish List
    Replies: 30
    Last Post: - 14th May 2007, 03:36
  3. jump out from a for/next loop
    By Pedro Santos in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 9th March 2007, 15:50
  4. Jump into eeprom address
    By Lotondo in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 22nd April 2006, 18:29
  5. NEWBIE: Some basic questions using interrupts
    By JackPollack in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 8th March 2006, 02:59

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