Int Interrupt question


Closed Thread
Results 1 to 13 of 13
  1. #1
    Join Date
    Sep 2006
    Posts
    747

    Default Int Interrupt question

    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
    Last edited by lerameur; - 25th November 2010 at 18:02.

  2. #2
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    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
    http://www.scalerobotics.com

  3. #3
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    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 ???
    Last edited by lerameur; - 25th November 2010 at 18:15.

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    The
    Code:
    @ INT_RETURN
    at the end of the interrupt routine sends the code back to what it was doing when the interrupt was triggered.
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    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.
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    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

  7. #7
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    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

  8. #8
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post
    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.
    Last edited by Archangel; - 25th November 2010 at 23:52.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  9. #9
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    not sure I am following you on this one !
    anyone has a written example of an external interrupt program ??

    K

  10. #10
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Code:
    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.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  11. #11
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    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

  12. #12
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Here are some snippets from a 16F873A project.
    It triggers on PORTB.0 using ON INTERRUPT.
    Code:
    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
    Dave
    Always wear safety glasses while programming.

  13. #13
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    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
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

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