PDA

View Full Version : Int Interrupt question



lerameur
- 25th November 2010, 18:00
I am using P16f88, I read in Dogim Ibrahim book on picbasic that I can use the int interrupt, or external interrupt. I would like to see example of such interrupts. I keep finding ASM, timer interrupt, but no external interrupts in picbasic pro :(

ScaleRobotics
- 25th November 2010, 18:10
Here is what I think are the best interrupts to use with PicBasic. They are called instant interrupts, or DT Interrupts. Here is a link and a few examples that should work with your chip, with possibly some minor adjustments.

http://darreltaylor.com/DT_INTS-14/intro.html

lerameur
- 25th November 2010, 18:11
Ok ok I found lots of stuff, RB0 seems to be the pin of choice for most Pic's. Just that in most example they are showing ONE mainloop, and say after the interrupt sequence is finish, the program return to the mainloop. Does it go to the mainloop, or does it go back where it left like a sub routine.. ???

K
PS I was making a while loop to go to a special menu. The while loop was looking for a external pin being activated. implementing that while loop everywhere made it nasty. I think as far as I can read, this is the best choice, external interrupt ! as soon the user pushes the button it goes to a menu. My only concern is, can I do anything in an interrupt ?, meaning I2C reading, looping, pausing, observing other pin values. Meaning can I use interrupt routine like I would a subroutine ???

mackrackit
- 25th November 2010, 18:13
The

@ INT_RETURN
at the end of the interrupt routine sends the code back to what it was doing when the interrupt was triggered.

mackrackit
- 25th November 2010, 18:22
My only concern is, can I do anything in an interrupt ?
Yes and no...
It is normally best to get in and out of an interrupt as quick as possible.
Set a flag or increment a variable that will then be acted upon in the main program after the interrupt is finished.

lerameur
- 25th November 2010, 18:31
eee ook, you mean something like:
/
RBO = 1 ' call interrupt

myInterrupt:
Gosub Display_menu
@int interrupt

Display_menu:
'display result on LCD....
return
/

WIll the return go back to the interrupt or back to where interrupt has left the main program ??

K

lerameur
- 25th November 2010, 18:40
Here is exactly what I need.. I think :)
The programs records a multitude of time from an external timer.
When the user push Pushes Button-A (RB0), it will go to a menu where the user can see all the times. The user can push Again button-A, to see the next time, Pushes again for the following time until it reaches the end. If the Button-A is not press for 10 seconds, the menu exit and return to where it left off. Is this Clear ?? sometime it is clear to me but not to others

K

Archangel
- 25th November 2010, 23:49
eee ook, you mean something like:
/
RBO = 1 ' call interrupt


K
Hi Ken,
not exactly, when RB0 does = 1 it sets a flag bit and that bit stays set even if RB0 goes back to zero, your program does something of your choosing as a result and then it clears that flag bit before it resumes, assuming you write the code properly.


WIll the return go back to the interrupt or back to where interrupt has left the main program ??
It returns to the next line normally.

lerameur
- 25th November 2010, 23:56
not sure I am following you on this one !
anyone has a written example of an external interrupt program ??

K

Archangel
- 26th November 2010, 00:10
REGISTER 2-3: INTCON: INTERRUPT CONTROL REGISTER (ADDRESS 0Bh, 8Bh, 10Bh, 18Bh)
Note: Interrupt flag bits get set when an interrupt
condition occurs, regardless of the state of
its corresponding enable bit or the global
enable bit, GIE (INTCON<7>). User
software should ensure the appropriate
interrupt flag bits are clear prior to
enabling an interrupt.
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-x
GIE PEIE TMR0IE INT0IE RBIE TMR0IF INT0IF RBIF
bit 7 bit 0
bit 7 GIE: Global Interrupt Enable bit
1 = Enables all unmasked interrupts
0 = Disables all interrupts
bit 6 PEIE: Peripheral Interrupt Enable bit
1 = Enables all unmasked peripheral interrupts
0 = Disables all peripheral interrupts
bit 5 TMR0IE: TMR0 Overflow Interrupt Enable bit
1 = Enables the TMR0 interrupt
0 = Disables the TMR0 interrupt
bit 4 INT0IE: RB0/INT External Interrupt Enable bit
1 = Enables the RB0/INT external interrupt
0 = Disables the RB0/INT external interrupt
bit 3 RBIE: RB Port Change Interrupt Enable bit
1 = Enables the RB port change interrupt
0 = Disables the RB port change interrupt
bit 2 TMR0IF: TMR0 Overflow Interrupt Flag bit
1 = TMR0 register has overflowed (must be cleared in software)
0 = TMR0 register did not overflow
bit 1 INT0IF: RB0/INT External Interrupt Flag bit
1 = The RB0/INT external interrupt occurred (must be cleared in software)
0 = The RB0/INT external interrupt did not occur
bit 0 RBIF: RB Port Change Interrupt Flag bit
A mismatch condition will continue to set flag bit RBIF. Reading PORTB will end the mismatch
condition and allow flag bit RBIF to be cleared.
1 = At least one of the RB7:RB4 pins changed state (must be cleared in software)
0 = None of the RB7:RB4 pins have changed state
Bit 1 of the intcon register is what your interrupt routine will be looking for, Assembly interrupts will act on it immediatly (Like Darrel's) PBP interrupts will get to it eventually.

lerameur
- 26th November 2010, 00:40
I read the definition in the manual, I meant of a small example program .BAS :)
I will give me a more hands on view thanks

mackrackit
- 26th November 2010, 02:53
Here are some snippets from a 16F873A project.
It triggers on PORTB.0 using ON INTERRUPT.


ON INTERRUPT GOTO MYINT
INTCON = %10010000

MAIN:
'DO STUFF
GOTO MAIN

DISABLE
MYINT:
IF PORTB.0 = 1 THEN
PC = PC + 1
WRITE 3,PC.BYTE0
WRITE 4,PC.BYTE1
READ 3,PCNT.BYTE0
READ 4,PCNT.BYTE1
pause 100
ELSE
PC = PC
ENDIF

INTCON.1 = 0
RESUME
ENABLE

Archangel
- 27th November 2010, 02:30
Hi Ken,
Spend an hour or more in ME Labs website, there are a Gaggle of sample programs and user submitted programs there. It is a very good resource, I promise. It may / not have the example you seek, it IS worth the time.
http://melabs.com/resources/samples-pbp-general.htm