sp
Full Member level 6
- Joined
- Jan 1, 2004
- Messages
- 395
- Helped
- 23
- Reputation
- 46
- Reaction score
- 2
- Trophy points
- 1,298
- Location
- Floating Garden
- Activity points
- 4,044
picbasic pro interrupt
main page: https://www.microengineeringlabs.com/resources/pbpmanual/
the below: https://www.microengineeringlabs.com/resources/pbpmanual/5_42-5_47.htm#544
wad i wanna ask is tht after the RESUME... it will return to the main prog... so the ENABLE wont b able to run... y it is there anyway??... or it should b put b4 the RESUME so it can turn on the interrupt again...
thank you
my regards,
sp
main page: https://www.microengineeringlabs.com/resources/pbpmanual/
the below: https://www.microengineeringlabs.com/resources/pbpmanual/5_42-5_47.htm#544
Code:
ON INTERRUPT
ON INTERRUPT GOTO Label
ON INTERRUPT allows the handling of microcontroller interrupts by a PICBASIC PRO™ subroutine.
There are 2 ways to handle interrupts using the PICBASIC PRO™ Compiler. The first is to write an assembly language interrupt routine. This is the way to handle interrupts with the shortest latency and lowest overhead. This method is discussed under advanced topics in a later section.
The second method is to write a PICBASIC PRO™ interrupt handler. This looks just like a PICBASIC PRO™ subroutine but ends with a RESUME.
When an interrupt occurs, it is flagged. As soon as the current PICBASIC PRO™ statement=s execution is complete, the program jumps to the BASIC interrupt handler at Label. Once the interrupt handler is complete, a RESUME statement sends the program back to where it was when the interrupt occurred, picking up where it left off.
DISABLE and ENABLE allow different sections of a PICBASIC PRO™ program to execute without the possibility of being interrupted. The most notable place to use DISABLE is right before the actual interrupt handler. Or the interrupt handler may be placed before the ON INTERRUPT statement as the interrupt flag is not checked before the first ON INTERRUPT in a program.
Latency is the time it takes from the time of the actual interrupt to the time the interrupt handler is entered. Since PICBASIC PRO™ statements are not re-entrant (i.e. you cannot execute another PICBASIC PRO™ statement while one is being executed), there can be considerable latency before the interrupt routine is entered.
PBP will not enter the BASIC interrupt handler until it has finished executing the current statement. If the statement is a PAUSE or SERIN, it could be quite a while before the interrupt is acknowledged. The program must be designed with this latency in mind. If it is unacceptable and the interrupts must be handled more quickly, an assembly language interrupt routine must be used.
Overhead is another issue. ON INTERRUPT will add an instruction after every statement to check whether or not an interrupt has occurred. DISABLE turns off the addition of this instruction. ENABLE turns it back on again. Usually the additional instruction will not be much of a problem, but long programs in small microcontrollers could suffer.
More than one ON INTERRUPT may be used in a program.
ON INTERRUPT GOTO myint ' Interrupt handler is myint
INTCON = %10010000 ' Enable RB0 interrupt
. . .
DISABLE ' Disable interrupts in handler
myint: led = 1 ' Turn on LED when interrupted
RESUME ' Return to main program
ENABLE ' Enable interrupts after handler
To turn off interrupts permanently (or until needed again) once ON INTERRUPT has been used, set INTCON to $80:
INTCON = $80
wad i wanna ask is tht after the RESUME... it will return to the main prog... so the ENABLE wont b able to run... y it is there anyway??... or it should b put b4 the RESUME so it can turn on the interrupt again...
thank you
my regards,
sp