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.

[PIC] Problem with Interrupt - 12F683 MikroC code

Status
Not open for further replies.

mm_pk1

Newbie level 6
Joined
Jan 9, 2009
Messages
12
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,372
Dear all,

I am new on PIC12x. Code continuously toggles the GP0 of 12F683 and whenever interrupt (INT) is invoked, GP1 toggles. The problem is that interrupt is invoked only once, and it seems that after executing the ISR, control does not return back to the main function. When interrupt is invoked first time, GP1 toggles but after that LED blinking on GP0 stops. Following is the code and Proteus schematic is also attached for reference please:

Code:
unsigned char a=0;

void interrupt ()
{
   GPIO.F1 = ~a;     //Toggle GP1 at each interrupt occurrence 
   INTCON.F0 = 0;   //Clear INT flag
}

void main()
{
     ANSEL = 0;
     CMCON0 = 7;
     TRISIO.F0 = 0;     //Continuous blinking LED on this port
     TRISIO.F1 = 0;     //This port toggles whenever interrupt occurs
     TRISIO.F2 = 1;     //Making GP2 as input for interrupt

     while(1)
     {
        INTCON = 0xD0;   //Enable Global interrupt and INT
        {
           GPIO.F0 = 0;    
           Delay_ms(100);
           GPIO.F1 = 1;
           Delay_ms(100);
       }
     }
}

Proteus_Sim.jpg
 

from looking at your code - it look like you don't blink each one of the leds....
 

Code:
     while(1)
     {
        INTCON = 0xD0;   //Enable Global interrupt and INT
        {
           GPIO.F0 = 0;    
           Delay_ms(100);
           GPIO.F1 = 1;  [COLOR="#FF0000"]<<<<<<<< Did you mean GPIO.F0 = 1; ??????[/COLOR]
           Delay_ms(100);
       }
     }

In any case, it's best to set the value of INTCON outside the loop and enable the INTE interrupt bit before GIE (do it in two lines of code).

Brian.
 

Your code shows that External Interrupt is enabled by INTCON = 0xD0, whereas in ISR, you are clearing the INTCON.F0 i.e. port change interrupt flag bit. The INTCON.F1 bit (External interrupt flag bit) should be cleared instead INTCON.F0 bit. The reason that control does not return from ISR is - the concerned interrupt flag bit is not cleared, thus forcing the control to remain in ISR indefinitely.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top