How to know what pin triggered an interrupt?


Closed Thread
Results 1 to 20 of 20

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    I may be wrong, but I can not think of a PIC that has a porta interrupt.

    What PIC are you using?
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    I would read the port as fast as possible (immediately on interrupt) by saving it in an 8-bit
    variable, and then testing for the port bit in question stored in my variable.

    MyPort VAR BYTE. MyPort=PORTA. Now test bits in MyPort for the change.

    Edit:
    The only interrupt flags available are those shown in the data sheet.
    Last edited by Bruce; - 7th October 2008 at 18:57. Reason: Flags
    Regards,

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

  3. #3
    xnihilo's Avatar
    xnihilo Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bruce View Post
    I would read the port as fast as possible (immediately on interrupt) by saving it in an 8-bit
    variable, and then testing for the port bit in question stored in my variable.

    MyPort VAR BYTE. MyPort=PORTA. Now test bits in MyPort for the change.

    Edit:
    The only interrupt flags available are those shown in the data sheet.
    That's exactly what I'm doing (see my code below) but I have the feeling it makes me waste some time doing all the stuff only to know which pin triggered the int

    Code:
    DISABLE 				'disable individual interrupts while executing the interrupt routine (do not put check interrupts calls after each instruction)
    
    
    in_sig: 
    
    
    'MEMO: first read the port THEN clear the flag otherwise mismatch still exists
    'Contribution from: Darrel Taylor (www.picbasic.co.uk/forum/)
    a = porta               'read port to clear mismatch
    
    'TEST block
    HIGH portc.2
    
    'check what pin triggered the int
    'we have the time of the header pulse to manage that work
    if (a.0(0) == 0) THEN
        pin = 0
        GOTO got_pin        'bypass 
    ENDIF
    if (a.0(1) == 0) THEN
        pin = 1
        GOTO got_pin        'bypass 
    ENDIF
    if (a.0(2) == 0) THEN
        pin = 2
        GOTO got_pin        'bypass 
    ENDIF
    if (a.0(3) == 0) THEN
        pin = 3
        GOTO got_pin        'bypass 
    ENDIF
    if (a.0(4) == 0) THEN
        pin = 4
        GOTO got_pin        'bypass 
    ENDIF
    
    got_pin:
    This works, then I have to use porta.0(pin).

  4. #4
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    I may be wrong, but I can not think of a PIC that has a porta interrupt...
    Unless he is using a PIC24 - which can have interrupts on every port.

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


    Did you find this post helpful? Yes | No

    Default

    If PBP supported the 24 series it would be nice..;o}
    Regards,

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

  6. #6
    xnihilo's Avatar
    xnihilo Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by rmteo View Post
    Unless he is using a PIC24 - which can have interrupts on every port.
    PORTA and PORTB have it. You can choose which pin change can trigger an int but then you only have an INT flag that tells you some port pin triggered an int, it's up to us to check which one did it.

  7. #7
    xnihilo's Avatar
    xnihilo Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    I may be wrong, but I can not think of a PIC that has a porta interrupt.

    What PIC are you using?
    Yes, it is called portA on change interrupt, there are also portB on change interrupts.
    It exists on the models I'm using: 16F684, 16F690, 18F452. Very useful by the way.

Similar Threads

  1. 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
  2. Help with Analog Interrupt
    By brid0030 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th February 2008, 18:14
  3. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  4. Another RTC, DS1287
    By DavidK in forum Code Examples
    Replies: 0
    Last Post: - 12th December 2006, 17:07
  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 : 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