Need help with Interrupts PIC-16F648A

General discussion on mikroC.
Post Reply
Author
Message
X-Team
Posts: 4
Joined: 26 Aug 2010 21:16
Location: Niš, Srbija

Need help with Interrupts PIC-16F648A

#1 Post by X-Team » 26 Aug 2010 21:35

Hi,
I need help with interrupts, I know that they pause the executing of main program and execute the code under the interrupt function. I was trying to flash a led on PORTB = 0x80 the RB7 bit. And it didn't work here's the code:

Code: Select all

void main()
{
  INTCON.GIE = 1;            //Ukljuci sve Interrupte
  INTCON.INTE = 1;           //Ukljuci RB0/INT interrupt
  OPTION_REG.INTEDG = 1;     //interrupt on rising edge of RB0/INT pin.
  
  TRISA = 0xFF;
  PORTA = 0x00;
  PORTB = 0x00;
  TRISB = 0b00000001;       //Binarno znaci da samo RB0 bude ulazni port
  while(1)
  {
    PORTB = 0x02;   //Ukljuci diodu na RB1
  }

}
void interrupt()
{

   INTCON.GIE = 0;           //Iskljuci sve prekide (interrupte)
   PORTB = 0x80;           //Ukljuci led diodu na RB7
   Delay_ms(2000);
   INTCON.INTF = 0;          //Ocisti RB0 Interupt flag
   INTCON.GIE = 1;           //Ukljuci sve prekide (interrupte)
     
}
Now I tried to simulate it in proteus and when I press the button for interrupt nothing happens the LED does not flash?
I'm 100% sure that the scheme works. I think I don't know how to use the interrupts. So please correct my error here!

Thanks in advance!

braus
Posts: 167
Joined: 25 Jul 2007 22:55
Location: Mexico, city.

Re: Need help with Interrupts PIC-16F648A

#2 Post by braus » 26 Aug 2010 23:54

Hello X team, certainly you have to be sure the button you are using is going to feed 5V to RB0 bit when you press it, normally it should deliver 0V.
After that let's check the logical part of your project...

Code: Select all

void main()
{
  INTCON.GIE = 1;            //Ukljuci sve Interrupte
  INTCON.INTE = 1;           //Ukljuci RB0/INT interrupt
  OPTION_REG.INTEDG = 1;     //interrupt on rising edge of RB0/INT pin.
  
  TRISA = 0xFF;
  PORTA = 0x00;
  PORTB = 0x00;
  TRISB = 0b00000001;       //Binarno znaci da samo RB0 bude ulazni port
  while(1)
  {
    PORTB = 0x02;   //Ukljuci diodu na RB1
  }

}
void interrupt()
{

   INTCON.GIE = 0;   //it is not neccesary to clear this bit, PIC MCU does it when it enters in the
                            //interrupt.
   PORTB = 0x80;           //try PORTB.B7=1
   Delay_ms(2000);
   INTCON.INTF = 0;          //Ocisti RB0 Interupt flag
   INTCON.GIE = 1;           //Ukljuci sve prekide (interrupte)
     
}
it should work.
Best Regards
Omar Galicia
Mexico City

X-Team
Posts: 4
Joined: 26 Aug 2010 21:16
Location: Niš, Srbija

Re: Need help with Interrupts PIC-16F648A

#3 Post by X-Team » 27 Aug 2010 02:54

I didn't quite understood you. I have the schematic like this, maybe I made there a mistake:
Image
Please correct me.

Thanks in advance!

X-Team
Posts: 4
Joined: 26 Aug 2010 21:16
Location: Niš, Srbija

Re: Need help with Interrupts PIC-16F648A

#4 Post by X-Team » 27 Aug 2010 03:33

I also tried with this simple schematic:
Image
And this code:

Code: Select all

void main()
{
  INTCON.GIE = 1;            //Ukljuci sve Interrupte
  INTCON.INTE = 1;           //Ukljuci RB0/INT interrupt
  OPTION_REG.INTEDG = 1;     //interrupt on rising edge of RB0/INT pin.

  TRISA = 0xFF;
  PORTA = 0x00;
  PORTB = 0x00;
  TRISB = 0b00000001;       //Binarno znaci da samo RB0 bude ulazni port
  while(1)
  {
    PORTB = 0x02;   //Ukljuci diodu na RB1
  }

}
void interrupt()
{

   INTCON.GIE = 0;   //it is not neccesary to clear this bit, PIC MCU does it when it enters in the
                            //interrupt.
   PORTB.B7 = 1;           //tried with PORTB = 0x80
   Delay_ms(2000);
   INTCON.INTF = 0;          //Ocisti RB0 Interupt flag
   INTCON.GIE = 1;           //Ukljuci sve prekide (interrupte)

}
When I press the switch only led on RB1 is ON the Led or RB7 won't blink or turn on!

Post Reply

Return to “mikroC General”