Interrupt on RB port change with PIC18F23K20


Closed Thread
Results 1 to 7 of 7

Hybrid View

  1. #1
    Join Date
    Aug 2005
    Posts
    20

    Default Interrupt on RB port change with PIC18F23K20

    Hello all, I'm trying to make a low power app that use interrupts on RB4-5-6-7 port change.
    The problem is that it's always awake so LD1 blink continuously. Portb internal pull-up are enabled so I want interrupt when RB4-5-6-7 goes low.
    This is my test code:
    Code:
    OSCCON = %01001110  '1MHz int osc
    ANSEL = 0
    ANSELH = 0
    ADCON0.0 = 0
    CCP1CON = 0
    CCP2CON = 0
    REGISTER
    CM1CON0.7 = 0
    CM2CON0.7 = 0
    CVRCON.7 = 0
    CVRCON2.7 = 0
    HLVDCON.4 = 0
    INTCON.3 = 1
    INTCON.4 = 0
    INTCON2.7 = 0
    SSPCON1 = 0
    TRISB=%11111111
    IOCB.7=1
    IOCB.6=1
    IOCB.5=1
    IOCB.4=1
    
    SW1 VAR PORTB.4
    SW2 VAR PORTB.5
    SW3 VAR PORTB.6
    SW4 VAR PORTB.7
    
    LD1 VAR PORTA.0
    
    HIGH LD1
    INTCON.0=0
    
    ciclo:
    TOGGLE LD1
    
    IF (SW1 == 0) THEN 
      HIGH LD2
    ENDIF
    
    ASM
      sleep
    ENDASM
    
    
    INTCON.0=0
    LOW LD2
    pause 100
    
    goto ciclo
    can someone help me to understand where is the problem (probably I miss something) and how to make it works?
    very thanks!

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


    Did you find this post helpful? Yes | No

    Default

    You are close, you have many of the elements required.

    Go to your manual and take a look at ON INTERRUPT. You should be able to see what is missing.

    When you say "low power", are you wanting the chip to sleep until a button is pressed?
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    no need for any ON INTERRUPT here. One thing you MUST look at first is if RB_INT can wake up the PIC. Also double check your configuration fuses AND all INT related registers. INTCON and the likes.
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    Yup, but the OP did ask about interrupts, so I figured he may as well start with the basics...
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    I know Dave but looking at the original code
    Code:
    ASM
      sleep
    ENDASM
    should have give you some pointer? OK OK OK I'm being a smart a55 as usual
    </pre>
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    PORTB change interrupt interrupts twice when :
    first > the pin goes low
    Second > the pin goes high.

    Thus, pin toggle happens twice and ends up at the same state.
    You should use a flag, or bounce until the second interrupt occurs.

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

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