View Full Version : Jump from ISR
yasser hassani
- 19th April 2008, 19:54
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.
mister_e
- 19th April 2008, 20:20
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.
yasser hassani
- 2nd May 2008, 10:43
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:
'************************************************* ****************
'* 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!
'************************************************* ****************
'* 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
Darrel Taylor
- 2nd May 2008, 11:02
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>
yasser hassani
- 2nd May 2008, 12:02
Thanks alot
yasser hassani
- 2nd May 2008, 12:22
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.
Acetronics2
- 2nd May 2008, 13:39
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
yasser hassani
- 3rd May 2008, 20:33
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
Darrel Taylor
- 3rd May 2008, 20:43
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>
Acetronics2
- 4th May 2008, 08:53
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 ...
' 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
yasser hassani
- 11th May 2008, 08:18
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
Acetronics2
- 11th May 2008, 09:56
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 ...
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 ...
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
skimask
- 11th May 2008, 09:57
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...
yasser hassani
- 15th May 2008, 15:27
Special thanks from dear friends that help me in this thread.
I use I2CREAD and it works excellent.
========
Regards
Acetronics2
- 15th May 2008, 15:56
Hi, Yasser
It's a pleasure for us too ... to know you're happy with your project !
Regards
Alain
mister_e
- 15th May 2008, 20:54
For 15K$ you can't buy a head... but a least you'll be well equipped :D
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.
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.