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.

[SOLVED] External Interrupt on PIC 18f4550

Status
Not open for further replies.

arnab913

Junior Member level 3
Junior Member level 3
Joined
Jul 27, 2012
Messages
30
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Chittagong, Bangladesh
Visit site
Activity points
1,515
Hi,
facing problem to do an external interrupt on 18f4550 uc. Got a lot pain...Trying various way,but nothing happens...
Code:
void Interrupt() 
{
  // This is external INT0 interrupt (for sync start)
  //   - once we get falling edge on RB0 we are disabling INT0 interrupt

  if (INT0IF_bit && INT0IE_bit) {

     INT0IF_bit = 0;
     INT0IE_bit = 0;
     PORTC = 0xFF;
     //Delay_1sec;
   }
}
void main() 
{
TRISB=0xFF;
PORTB=0;
TRISC=0;
PORTC=0;
INTCON=0b10010000;
INTEDG0_bit = 0;         // Interrupt on falling edge on RB0
 while(1)
  {
   if (PORTB.f0==1)
    {
    INT0IF_bit=1;
    INT0IE_bit=1;
    }
  }

}
Please help... :(
 

What you try to do arnab.

I see some unnecessary things here.
1. After making TRISB = 0xFF why you are doing PORTB = 0
2. If INT0IE = 1 only interrupt can occur then why you testing for its true case "if (INT0IF_bit && INT0IE_bit)"
3. INT01F is a bit which will be set to 1 on an interrupt, why you are setting in the while loop.
if (PORTB.f0==1)
{
INT0IF_bit=1;
INT0IE_bit=1;
}

- - - Updated - - -
 
What you try to do arnab.

I see some unnecessary things here.
1. After making TRISB = 0xFF why you are doing PORTB = 0
2. If INT0IE = 1 only interrupt can occur then why you testing for its true case "if (INT0IF_bit && INT0IE_bit)"
3. INT01F is a bit which will be set to 1 on an interrupt, why you are setting in the while loop.
if (PORTB.f0==1)
{
INT0IF_bit=1;
INT0IE_bit=1;
}

- - - Updated - - -
Thanks for reply :)
Sir,isn't it necessary to select the initial state of PORTB ?
I just want to make state "HIGH" of PORTC by external interrupt on RB0. My logic was,when PORTB=1,interrupt will occur confirming INT0IE && INT0IF=1.
I'm little confused when I press PORTB.f0,does it automatically go to interrupt function without calling it on main loop??
I've found a lots of code googling,but cann't understand it....

- - - Updated - - -

Intcon = 0b11010000
Is it necessary to active peripheral interrupt bit?? I just want external interrupt sir....
 

Once u initially initialize Interrupt no need to enable bit till it clear . but before enable cleaf flag is no problem. Under main above action not require. Is Peripheral bit require to set
 

Thanks for reply :)
Sir,isn't it necessary to select the initial state of PORTB ?
If you are making a port as output then you need to initialise the port. But here you are initialising the port as input hence you cant make it to have a defined state through software. Even PORTb = 0 will not do anything once it has been declared as input. The only way is you need to either pull up or pull down that pin depends on requirement.

I just want to make state "HIGH" of PORTC by external interrupt on RB0. My logic was,when PORTB=1,interrupt will occur confirming INT0IE && INT0IF=1.
On first interrupt on RB0 you are making PORTC = 0xFF, when you will clear it. Also if second interrupt occurs what you want to do? How you are generating interrupt here either pulse wave or button press???
I'm little confused when I press PORTB.f0,does it automatically go to interrupt function without calling it on main loop??
I've found a lots of code googling,but cann't understand it....
Hey whenever interrupt occurs the program automatically jumps to the interrupt vector routine and after completing IVR it goes back to its normal main function execution or from the place where it has jumped. If we manually call the interrupt there is no purpose of using the interrupts.

- - - Updated - - -


Is it necessary to active peripheral interrupt bit?? I just want external interrupt sir....[/QUOTE]
 
This is my modified code.But still there is no output..... :(
Code:
void main()
{
    TRISD=0;                      // Configure PortD as output port
    portd=0;
  //  INTCON=0x10;                  // Enable INT0
    INTCON=0b10010000;
   // INTCON2=0;                    // Set Falling Edge Trigger for INT0
    trisb=255;


    

    INTCON.GIE=1;    // Enable The Global Interrupt
    while(1)
    {
        LATD=0x55;       //Set some value at PortD
        //Delay_1sec;
        //LATD=0;
    }
}

void interrupt()              // Interrupt ISR
{
    INTCON.INT0IF=0;          // Clear the interrupt 0 flag
    LATD=~LATD;               // Invert (Toggle) the value at PortD
    Delay_ms(1000);           // Delay for 1 sec
}
Added proteus image.... proteus.png
 

Try this one..
void main()
{
TRISB=0xFF;
TRISD=0xFF; // Configure PortD as output port

portd=0;
// INTCON=0x10; // Enable INT0
INTCON=0b11010000;
INTCON2=0b11000000; // Set Falling Edge Trigger for INT0





INTCON.GIE=1; // Enable The Global Interrupt

LATD=0x55; //Set some value at PortD
while(1)
{


}
}

void interrupt() // Interrupt ISR
{
INTCON.INT0IF=0; // Clear the interrupt 0 flag
LATD=~LATD; // Invert (Toggle) the value at PortD
Delay_ms(2); // Delay for 1 sec
}

Which compiler are you using?
 

TRISD=0xFF; // Configure PortD as output port
For output it should be TRISD=0;
I'm tried using Mikro C 4.15 and 6.00
But still no output.... :(

- - - Updated - - -

TRISD=0xFF; // Configure PortD as output port
For output it should be TRISD=0;
I'm tried using Mikro C 4.15 and 6.00
But still no output.... :(

- - - Updated - - -

TRISD=0xFF; // Configure PortD as output port
For output it should be TRISD=0;
I'm tried using Mikro C 4.15 and 6.00
But still no output.... :(
 

Try this code. Proteus file included.


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
void interrupt()
{
      if(INT0IF_bit){
           INT0IF_bit = 0;
           PORTC.F0 = 1;
      }    INTCON.INT0IE = 0;
}
 
void main()
{
    TRISB = 0xFF;
    PORTB = 0x00;
    TRISC = 0x00;
    PORTC = 0x00;
    ADCON1 = 0b00001111;
    INTCON = 0b10011000;
    INTCON2 = 0b10000001;
 
    while(1)
    {
       ;
    }
}

 

Attachments

  • INT0.rar
    54.8 KB · Views: 143
Last edited:
I've just solved the problem. :)

Problem was,I had't made the analog B port digital.
Thank you vary much sir :)

- - - Updated - - -

I've just solved the problem. :)

Problem was,I had't made the analog B port digital.
Thank you vary much sir :)

- - - Updated - - -

I've just solved the problem. :)

Problem was,I had't made the analog B port digital.
Thank you vary much sir :)
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top