what's wrong with this interrupt


Closed Thread
Results 1 to 7 of 7
  1. #1
    micro's Avatar
    micro Guest

    Default what's wrong with this interrupt

    the prog. below is a simple interrupt enables RB7 to RB4 ports to work as external interrupt, i used one of them to view numbers countes from 0 to 5 and display it on serial LCD and return to a main prog. to view a message, but the problem when i enter intterupt i can not get out from it, i did the same prgo to RB0 and gave me good result, but with RB7-RB4 is not



    trisa=%00000
    trisb=%11111111

    option_reg=%10000000
    intcon = %10001000
    I var byte

    on interrupt goto int

    main:

    serout porta.0,2,[254,1]
    pause 10
    serout porta.0,2,["Hello"]
    pause 100
    goto main

    disable interrupt

    int:

    for i=0 to 5

    serout porta.0,2,[254,1]
    pause 10
    serout porta.0,2,[#i]
    pause 1000

    next i

    INTCON.0=0

    resume
    enable interrupt
    end

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


    Did you find this post helpful? Yes | No

    Default

    pic model ?
    Steve

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

  3. #3
    micro's Avatar
    micro Guest


    Did you find this post helpful? Yes | No

    Default

    pic16f84
    sorry i forgot that

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Read portB on entry into the interrupt routine to end the mismatch condition.

    SomeVar = PORTB ' read portB

    Then clear the interrupt flag before exiting your interrupt routine.

    INTCON.0 = 0 ' RB port change int flag is cleared.

    Now whenever portB is different from the last value read, INTCON.0 will be set, and you'll vector back to your interrupt routine.

    Read this app note for more details:
    http://ww1.microchip.com/downloads/e...tes/00566b.pdf
    Last edited by Bruce; - 2nd February 2006 at 16:37.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  5. #5
    micro's Avatar
    micro Guest


    Did you find this post helpful? Yes | No

    Default

    i solved the problem with another method as below


    trisa=%00000
    trisb=%11111111

    option_reg=%10000000
    intcon = %10001000
    I var byte

    on interrupt goto int

    main:
    back: if portb<>0 then intcon=%10001000 ; test bit 3
    serout porta.0,2,[254,1]
    pause 10
    serout porta.0,2,["Hello"]
    pause 100
    goto main

    disable interrupt

    int:

    for i=0 to 5

    serout porta.0,2,[254,1]
    pause 10
    serout porta.0,2,[#i]
    pause 1000

    next i

    INTCON=%10000000 ; cleared bit 3 bit
    goto back ; back to test
    resume
    enable interrupt
    end


    i will read document, thank u for that, and waiting a reply from Mister_e
    Last edited by micro; - 2nd February 2006 at 21:53.

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


    Did you find this post helpful? Yes | No

    Default

    Micro,
    Maybe your solution is working but will Behave weird one day or another.

    I've nothing else to add from the Bruce's explanation. Everything is covered in his document.

    AND it's also covered in the PORTB TRISB section 3.2 of your datasheet too.

    BTW, why using interrupt on PORTB<7:4> if you never test wich pin gives you the interupt?
    Steve

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

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


    Did you find this post helpful? Yes | No

    Talking Other method ?????????????????????

    Quote Originally Posted by micro
    i solved the problem with another method as below


    if portb<>0 then intcon=%10001000
    Just a longer way to read PORTB ... no other method here !!!

    Elegant solution would have been to display the port where the interrupt came from, in the "serout"

    Alain
    Last edited by Acetronics2; - 3rd February 2006 at 09:39.
    ************************************************** ***********************
    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 " !!!
    *****************************************

Similar Threads

  1. Won't go back to SLEEP after 1st Interrupt
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 29th June 2009, 09:00
  2. Can't ID interrupt source with this IntHandler??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd June 2009, 02:35
  3. Help with Analog Interrupt
    By brid0030 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th February 2008, 18:14
  4. NEWBIE: Some basic questions using interrupts
    By JackPollack in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 8th March 2006, 02:59
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

Members who have read this thread : 1

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