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.

External interrupt PIC18F4520

Status
Not open for further replies.

r_guna_sekar

Newbie level 6
Joined
Jul 5, 2010
Messages
11
Helped
2
Reputation
4
Reaction score
1
Trophy points
1,283
Location
Chennai
Activity points
1,341
hi

i'm trying to use three external interrupts...

in this code the interrupts are working fine.. (I tested it with LED)

But i Cant Read Or Update the mic_num in this code


Code:
#define LED PORTD.F0

unsigned int mic_num = 0;


void interrupt()
{

if(INTCON.F1 == 1)
      {
      mic_num = 1;
      }
else if(INTCON3.F0 == 1)
      {
      mic_num = 2;
      }
else if(INTCON3.F1 == 1)
      {
      mic_num = 3;
      }
}

void main()
{
TRISD = 0x00;                      // for Display, LED, Relay
TRISC = 0x00;
TRISB = 0xFF;
LED =1;
delay_ms(1000);
LED =0;

PORTC = 0;

INTCON = 0b10010000;
INTCON2 = 0b01110000;
INTCON3 = 0b00011000;
RCON.IPEN = 0;
while(1)
      {
      if(mic_num > 0) // this Part is not working
             {
             LED = 1;
             }
      }
}
 

You are never resetting mic_num back to 0 so once an interrupt has occurred, mic_num will always be more than 1 and the LED will always be on.
 

please somebody give me a suggestion ....

i want to use three external interrupts....

PIC18F4520
 
Last edited:

what compiler you are using? where is interupt vector in your code?
also
you need to use the pull up resistor or pull down resistor(depends whether you assign portb=1 or portb=0 ) with interupt pins. also u didnt assign any value to portb interupt pins. you should write something like this.
TRISD = 0x00; // for Display, LED, Relay
TRISC = 0x00;
TRISB = 0xFF;
PORTB=0x00;
PORTD=0x00;
LED =1;
delay_ms(1000);
LED =0;
 

i'm using MikroC compiler.....
my all three interrupts are working (i tested it with LED)......
Code:
if(INTCON.INT0IF == 1)
LED = 1;
i'm using pull down resistor and i configured rising edge interrupt...

my issue is i cant update the mic_num while interrupt occurs...
 

This is the fixed code:
Code:
#define LED PORTD.F0

unsigned int mic_num = 0;


void interrupt()
{

if(INTCON.F1 == 1)
      {
      mic_num = 1;
      INTCON.F1 = 0;
      }
else if(INTCON3.F0 == 1)
      {
      INTCON3.F0 = 0;
      mic_num = 2;
      }
else if(INTCON3.F1 == 1)
      {
      INTCON3.F1 = 0;
      mic_num = 3;
      }
}

void main()
{
TRISD = 0x00;                      // for Display, LED, Relay
TRISC = 0x00;
TRISB = 0xFF;
LED =1;
delay_ms(1000);
LED =0;

ADCON1 = 7;                          //Disable ADC
CMCON = 7;                           //Disable comparator
PORTC = 0;

INTCON = 0b10010000;
INTCON2 = 0b01110000;
INTCON3 = 0b00011000;
RCON.IPEN = 0;
while(1)
      {
      if(mic_num > 0) // this Part is not working
             {
             LED = 1;
             }
      }
}

2 problems:
1) Most importantly, the INT0, INT1 and INT2 pins are also multiplexed to ADC inputs. So, you have to first select them as digital pins by disabling the ADC and comparator.
2) You did not clear the flags. However, your problem was created due to what I've explained in point 1.

Hope this helps.
Tahmid.
 
Last edited:
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top