+ Post New Thread
Results 1 to 11 of 11
  1. #1
    Junior Member level 3
    Points: 322, Level: 3

    Join Date
    Jul 2018
    Posts
    27
    Helped
    0 / 0
    Points
    322
    Level
    3

    hardware issues in simple interrupt code p16f887 using mikroc

    dear seniors,

    I want to write a program on IR sensor using NEC protocol, for that i just started to understand basic codes of interrupt. Just blink an led port when interrupt is occurred. Wrote a coding n executed in proteus too. But when try to implemented in hardware mode the interrupt part is not working. I was tried my best to solve the issue, but failed all times. Here i am attaching my source code and simulator file and photos of my hardware. Kindly suggest what went wrong exactly.

    Micro controller - pic16f887
    platform - mikro c.

    Code C - [expand]
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    
    void interrupt()
    {
         if(INTF_bit)
            {
            PORTA=0X00;
            delay_ms(3000);
            INTF_bit=0;
            }
    }
     
     
    void main()
    {
            ansel = 0x00;
            anselh = 0x00;
            TRISB0_bit=1;
            TRISA=0X00;
            OPTION_REG=0X40;
            INTCON =0X90;
            RBIF_bit = 0;
            OSCCON = 0X70;
            IOCB0_bit = 1;
            while(1) {
                    PORTA=0xFF;
            }
    }

    •   AltAdvertisement

        
       

  2. #2
    Super Moderator
    Points: 79,067, Level: 68
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    16,051
    Helped
    3635 / 3635
    Points
    79,067
    Level
    68

    Re: hardware issues in simple interrupt code p16f887 using mikroc

    Hi,

    the interrupt part is not working
    As said many times: "the interrupt part is not working" is no error description.

    * Say how your test setup looks like
    * Say what you expect
    * Say what you see instead
    * say what you did so far to debug the problem

    Klaus
    Please dont contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



  3. #3
    Junior Member level 3
    Points: 322, Level: 3

    Join Date
    Jul 2018
    Posts
    27
    Helped
    0 / 0
    Points
    322
    Level
    3

    Re: hardware issues in simple interrupt code p16f887 using mikroc

    klaus,

    1. I already attached my development board.

    2. I want to decode IR remote of NEC protocol. For that I got a code from web. While testing the code i found that interrupt part is not working. Then i decided to test the interrupt with a simple LED blinking code. It works well in simulator but the while doing the same in harware found that same interrupt part is not working.

    3. when you apply voltage to MC PORT A LED goes high as written in code, but when i applied interrupt at B0, it doesn't blinking.

    4. I tried to add/modify register of INTCON, OPTION_REG, and even OSCCON for setting internal oscillator. Nothing works so far.....
    also added 10k resister to B0 to ground.



    •   AltAdvertisement

        
       

  4. #4
    Advanced Member level 2
    Points: 3,283, Level: 13
    baileychic's Avatar
    Join Date
    Aug 2017
    Posts
    651
    Helped
    50 / 50
    Points
    3,283
    Level
    13

    Re: hardware issues in simple interrupt code p16f887 using mikroc

    Don't use IOCB0_bit, instead use INTE_bit and INTF_bit.

    Enable INTE_bit, PEIE_bit, and GIE_bit before the main loop.
    In ISR test for INTF_bit.

    RB0 pin has to be used.



    •   AltAdvertisement

        
       

  5. #5
    Junior Member level 3
    Points: 322, Level: 3

    Join Date
    Jul 2018
    Posts
    27
    Helped
    0 / 0
    Points
    322
    Level
    3

    Re: hardware issues in simple interrupt code p16f887 using mikroc

    baily,

    Couldn't able to enable INTCON register before main loop, its showing error as "identifier refined".
    I already tested INTF_ bit in ISR and I used RB0 pin sir..

    Kindly suggest how to enable them before main loop..



  6. #6
    Advanced Member level 2
    Points: 3,283, Level: 13
    baileychic's Avatar
    Join Date
    Aug 2017
    Posts
    651
    Helped
    50 / 50
    Points
    3,283
    Level
    13

    Re: hardware issues in simple interrupt code p16f887 using mikroc

    Try this code.

    Code C - [expand]
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    
    void interrupt() {
        if((INTE_bit) && (INTF_bit)) {
            PORTA = ~PORTA;
            INTF_bit=0;
        }
    }
     
     
    void main() {
        OPTION_REG = 0x8F;
        
        ANSEL = 0x00;
        ANSELH = 0x00;
        
        TRISA = 0x00;
        TRISB = 0x01;
        
        INTF_bit = 0;
        INTE_bit = 1;
        
        INTCON = 0xC0;
        
        while(1) {
            asm clrwdt
        }
    }



  7. #7
    Junior Member level 3
    Points: 322, Level: 3

    Join Date
    Jul 2018
    Posts
    27
    Helped
    0 / 0
    Points
    322
    Level
    3

    Re: hardware issues in simple interrupt code p16f887 using mikroc

    Tried your code, But its not working in simulator itself.
    i have attached the project with this, kindly check and reply.

    - - - Updated - - -

    Quote Originally Posted by venthan View Post
    Tried your code, But its not working in simulator itself.
    i have attached the project with this, kindly check and reply.

    1. Your code is now working,

    2. Made two changes, 1. INTCON register value is 0x90.
    2. Added delay in ISR.

    Now its working in simulator, I will try to implement in hardware and update you.



  8. #8
    Advanced Member level 2
    Points: 3,283, Level: 13
    baileychic's Avatar
    Join Date
    Aug 2017
    Posts
    651
    Helped
    50 / 50
    Points
    3,283
    Level
    13

    Re: hardware issues in simple interrupt code p16f887 using mikroc

    INTEDG_bit was also missing in the code. I added it.

    Code C - [expand]
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    
    void interrupt() {
        if((INTF_bit)&&(INTE_bit)) {
            PORTD = ~PORTD;
            INTF_bit=0;
        }
    }
     
     
    void main() {
        OPTION_REG = 0x8F;
     
        ANSEL = 0x00;
        ANSELH = 0x00;
     
        TRISD = 0x00;
        TRISB = 0x01;
        
        PORTD = 0x00;
     
        INTF_bit = 0;
        INTEDG_bit = 0;
        INTE_bit = 1;
     
        INTCON |= 0xC0;
     
        while(1) {
            asm clrwdt
        }
    }



  9. #9
    Junior Member level 3
    Points: 322, Level: 3

    Join Date
    Jul 2018
    Posts
    27
    Helped
    0 / 0
    Points
    322
    Level
    3

    Re: hardware issues in simple interrupt code p16f887 using mikroc

    yes sir, i already made OPTION_REG = 0xCF;
    In hardware mode -----> should i enable WDT in configuration?



  10. #10
    Advanced Member level 2
    Points: 3,283, Level: 13
    baileychic's Avatar
    Join Date
    Aug 2017
    Posts
    651
    Helped
    50 / 50
    Points
    3,283
    Level
    13

    Re: hardware issues in simple interrupt code p16f887 using mikroc

    If you need WDT to be enabled then enable it else just disable it in project settings.



    •   AltAdvertisement

        
       

  11. #11
    Junior Member level 3
    Points: 322, Level: 3

    Join Date
    Jul 2018
    Posts
    27
    Helped
    0 / 0
    Points
    322
    Level
    3

    Re: hardware issues in simple interrupt code p16f887 using mikroc

    Quote Originally Posted by baileychic View Post
    If you need WDT to be enabled then enable it else just disable it in project settings.
    Yes Sir, Implemented in Hardware and its working fine now. Thanks for your guidance.



--[[ ]]--