Can I have interupts on any pin ?


Closed Thread
Results 1 to 22 of 22

Hybrid View

  1. #1
    Join Date
    Dec 2004
    Location
    Scarborough UK
    Posts
    77

    Talking Can I have interupts on any pin ?

    Hi All

    1. Can I have interupts work on any pin ? (so that i can detect when a pin changes state)

    2. Can i have multiple interupts ? (one for each pin so that i can trigger diffrent iterupt handlers depending on which pin changes state)

    Anyone know how to do this (on 18f4550)

    Thx
    Reading the datasheet & understanding it are two different things.

  2. #2
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    699


    Did you find this post helpful? Yes | No

    Default

    Bonxy,

    Yes, you can have multiple interrupts. Can you have an interrupt work on any pin on a PIC18F4550? I don't know about that. But can you create a routine where you check the status of the pins that you want and then if a change is made goto to a sub-routine? Something like

    Code:
    IF PORTX.0 = 1 THEN GOTO SUBROUTINE0
    IF PORTX.1 = 1 THEN GOTO SUBROUTINE1
    .......
    Robert
    Last edited by rsocor01; - 10th March 2010 at 14:29.

  3. #3
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Use RB.0 for interrupt pin and connect as many normal pin as you want to this pin via a diode.

    RB0 will interrupt with any of the pins; you will check the status of the pins in interrupt routine.

    Thus, if you connect 10pins with RB0, then you will have 10 interrupt pins.

    ____________________________________
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Wink

    Hi, Bonxy

    You always can use the old method : use an " OR " gate to trigger one interrupt pin of the device.
    after, read ports and just check your inputs as rsocor01 tells, hoping they didn't change state in between ... ( possible issue ... but ...)

    note a couple of MCP 23016 or 23S17 ( Port expanders ) could help a lot here ...

    the question is here : really need it ???

    Alain
    ************************************************** ***********************
    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 " !!!
    *****************************************

  5. #5
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    Or - if you can tolerate a little latency -

    You can use a fast timer interrupt (say 1mSec) and check the status of any pin in that interrupt.
    Charles Linquist

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


    Did you find this post helpful? Yes | No

    Default

    Can I have interupts on any pin ?
    No. You can't have interrupts on any pin. Only pins that have some type of associated interrupt will cause a hardware interrupt.

    Testing inputs pins for high or low logic states is not a hardware interrupt.
    Last edited by Bruce; - 11th March 2010 at 00:50.
    Regards,

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

  7. #7
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    This is an example of what I mentioned earlier.

    I'll call it FAKE INTERRUPT

    It does have a latency of a little over a millisecond, but often it is plenty good enough to do what you need done. You can make the interrupt faster if you wish - but remember each time you enter/leave an interrupt, you are stealing quite a few processor cycles.


    This code will check the status of any pin once per millisecond. It was written for an 18Fxxxx at 40Mhz. This example is checking the status of PORTC.0.


    Code:
        Changed VAR BYTE
         OldPort VAR BYTE
          
         T0CON = %10001000 ; turn it on, 16 bits, no prescaler (osc/4)
            
         CLEAR 
    
    
    '-----------------  DT_INTS section ----------------------------        
           
            INCLUDE "DT_INTS-18.bas"        
            INCLUDE "ReEnterPBP-18.bas"     
    ASM
         INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
                  INT_Handler    TMR0_INT,   _FakeInt,   PBP,  yes 
              endm
        INT_CREATE           
    ENDASM
    
    
    Goto OverInt
    
    '------------------ Timer 0 interrupt handler-----------------------------------
    
    
    FakeInt:
            
             TMR0H = $D8  ; Preload depends on clk speed
             TMR0L = $F7  ; One millesecond timeout at 40Mhz. 
                          ; Always load HIGHBYTE FIRST
                                  
             Changed = PortC ^ OldPort 
             IF Changed.0 = 1 THEN     ; Pick your pin
                 OldPort = PortC
                 ;;;;  Whatever you want to do when Port bit changes
             ENDIF     
             
    @ INT_RETURN         
    
    
    Overint:
      
      OldPort = PortC    ; Init the var
    
    @ INT_ENABLE TMR0_INT
    
    
    NormalProgramLoop:
    
       
    
        Goto NormalProgramLoop
       
      END
    Charles Linquist

Similar Threads

  1. Is this a K Type sensor?
    By jessey in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 21st November 2009, 13:55
  2. DS1820 with 16f688
    By jessey in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 23rd May 2009, 05:07
  3. Advice-scrutiny for my serial controller
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th December 2008, 17:11
  4. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  5. Another RTC, DS1287
    By DavidK in forum Code Examples
    Replies: 0
    Last Post: - 12th December 2006, 17: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