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.

Unable to get external interrupts in pic18f452

Status
Not open for further replies.

Naumanpak

Member level 2
Joined
Nov 19, 2009
Messages
51
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Location
Pakistan
Activity points
1,635
Experts,

I am not getting interrupts working.

From the data sheet, I have set out the values for bits but doesnt work. I can use it a a simple input port but not with interrupts. kindly help me out.

here is a simple test code I wrote,


Code:
 int count=0;

void interrupt()	// Interrupt function definition
    {
       INTCON.INT0IF=0;
        count++;
       }

void main()
     {


      TRISB = 0;
      INTCON.INT0IF=0;
      INTCON.INT0IE=1;
      PORTB = 0;

      Lcd_Init(&PORTB);         // Initialize LCD connected to PORTB
      Lcd_Cmd(Lcd_CLEAR);       // Clear display
      Lcd_Cmd(Lcd_CURSOR_OFF);  // Turn cursor off

     Lcd_Out(1, 1, "Waiting..");
      while(count==0);
      
       Lcd_Out(1, 1, "interrupt!!1");
      
 }

thanks
 

Naumanpak,you seem to be thinking of interrupts as simple function calls, its not the way to go my friend ... I am assuming this is C18 compiler ? ... If thats true, read the user guide (2.9.2.3 Interrupt vectors) ... also fix the comon mistake of I/O digital config (If you havent already), and I do not see any input assignment in your code, you have to configure your pin INT0 to digital input ...
 

    Naumanpak

    Points: 2
    Helpful Answer Positive Rating
Hi,
I'm assuming this is mikroC compiler.
In that case, first, you need to set the INT0 pin as digital input:

Assuming this is 16F877A, you need to set RB0 as input as :


Code:
 int count=0;

void interrupt()   // Interrupt function definition
    {
       INTCON.INT0IF=0;
        count++;
       }

void main()
     {


      TRISB = 1;
      INTCON.INT0IF=0;
      INTCON.INT0IE=1;
      PORTB = 0;

      Lcd_Init(&PORTB);         // Initialize LCD connected to PORTB
      Lcd_Cmd(Lcd_CLEAR);       // Clear display
      Lcd_Cmd(Lcd_CURSOR_OFF);  // Turn cursor off

     Lcd_Out(1, 1, "Waiting..");
      while(count==0);
     
       Lcd_Out(1, 1, "interrupt!!1");
       while (1);
     
 }

Hope this helps.
Tahmid.
 

    Naumanpak

    Points: 2
    Helpful Answer Positive Rating
Hi, thanks Tahmid.

RBO is now declared as digital input, as it should be. But still no results....

If I just use condition 'if(RB0==1)' in this code, it works..

Perhaps I am unable to initialize interrupts, even if i set the flag bit high manually, i dont get interrupts.

I am using mikroc and pic18f452.
Kindly kindly do suggest.

thanks

Added after 1 minutes:

thanks korena, I am using mikroc compiler.

Can you suggest, please.


thanks

Added after 30 minutes:

Hey thanks ALL!!!

Actually I didnt enable global interrupts.


thanks
 

pull down rb0 with 10k resistor solved my problem with above code
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top