Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

hardware issues in simple interrupt code p16f887 using mikroc

Status
Not open for further replies.

venthan

Junior Member level 3
Joined
Jul 23, 2018
Messages
27
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
272
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;
        }
}

 

Attachments

  • int.rar
    43.8 KB · Views: 114
  • IMG_20190603_142933.jpg
    IMG_20190603_142933.jpg
    539.6 KB · Views: 143

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
 

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.
 

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.
 

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..
 

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
    }
}

 

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

- - - Updated - - -

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.
 

Attachments

  • INTLAST.rar
    11.6 KB · Views: 106

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
    }
}

 

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

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

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. :thumbsup:
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top