PORTB interrupt on change

Discussion in 'Embedded Systems and Microcontrollers' started by olvine, Apr 17, 2014.

  1. olvine

    Thread Starter Member

    Mar 10, 2014
    99
    0
    why it is not working ??

    Please Help!!

    //// PIC16F887
    //// MikroC


    Code ( (Unknown Language)):
    1.  
    2.  
    3. void interrupt()
    4. {
    5. INTCON.PEIE=0;
    6. INTCON.GIE=0;
    7.  
    8. if(INTCON.RBIF==1){
    9. PORTA.RA5=~PORTA.RA5;
    10. INTCON.RBIF=0;
    11. }
    12.  
    13. INTCON.PEIE=1;
    14. }
    15.  
    16.  
    17. void main(){
    18.  
    19. PORTB=0;
    20. TRISB.RB5=1;
    21. TRISA.RA5=0;
    22. PORTA.RA5=0;
    23.  
    24. IOCB=1;
    25. WPUB=1;
    26.  
    27. INTCON.RBIF=0;
    28. INTCON.PEIE=1;
    29. INTCON.GIE=1;
    30. INTCON.RBIE=1;
    31.  
    32.  
    33.  
    34. while(1){
    35. }
    36. }
    37.  
    38. [\code]
     
    Last edited: Apr 17, 2014
  2. GopherT

    AAC Fanatic!

    Nov 23, 2012
    6,015
    3,789
    Define "working" and tell is what is happening instead of "working".
     
  3. MrChips

    Moderator

    Oct 2, 2009
    12,437
    3,360
    When posting code please use code tags:

    [code=rich]
    Your code goes here
    [/code]
     
  4. olvine

    Thread Starter Member

    Mar 10, 2014
    99
    0
    Ra5 is not changing its value and compiler is not going into interrupt routine..
    input is a square wave of 1khz
     
  5. MrChips

    Moderator

    Oct 2, 2009
    12,437
    3,360
    Did you set ANSEL = 0
     
    olvine likes this.
  6. olvine

    Thread Starter Member

    Mar 10, 2014
    99
    0
    Now i have done that...now its working with ANSELH=0 ansel=0
     
  7. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    void interrupt()
    {
    INTCON.PEIE=0;
    INTCON.GIE=0;

    After the first interrupt, GIE is turned off and you have no way to turn it back on. GIE kills all interrupts after that point.

    You should remove that line from your interrupt code. You are already switching PEIE off and back on so messing with GIE is probably not needed.
     
    olvine likes this.
Loading...