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 on pic18f

Status
Not open for further replies.

hamidkavianathar

Member level 5
Joined
Mar 6, 2016
Messages
89
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
804
Hello guys
I am new to pic micro controllers. I have a problem with it. I have written a very simple code to test the external its interrupts. I don't know why it doesn't work. could you please tell me, what I should do?
this is block design of interrupt scheme of the micro controller:
qweee.JPG

and this my code:

Code:
#include <p18f4550.h>

#pragma config FOSC = INTOSCIO_EC   //internal ocsillator
#pragma config WDT = OFF            //turn off WDT
#pragma config LVP = OFF            //turn off LVP
#pragma config BOR = ON             //enable brownout reset


//----------------------------------------------------------------------------

void main (void);
void InterruptHandlerHigh (void);
void delay (void)
{
    volatile int i;
    for (i=0;i<10000;i++);
}

//----------------------------------------------------------------------------
// Main routine
char flag = 0;
void
main ()
{
    
INTCONbits.INT0IF = 0;
INTCONbits.INT0IE = 1;
INTCON2bits.INTEDG0 = 0;
ADCON0 = 0xFF;
INTCON2bits.RBPU = 1;

RCONbits.IPEN = 1;
INTCONbits.PEIE = 1;

INTCONbits.GIE = 1;

TRISAbits.TRISA0 = 0;


TRISBbits.TRISB0 = 1;

  while (1)
    {
      if (flag == 1)
      {
        LATAbits.LATA0 = 1;
        delay();
        LATAbits.LATA0 = 0;
        delay();
      }
      else
          LATAbits.LATA0 = 1;
    }
     

}


#pragma code InterruptVectorHigh = 0x08
void
InterruptVectorHigh (void)
{
    
  _asm
    goto InterruptHandlerHigh //jump to interrupt routine
  _endasm
}

//----------------------------------------------------------------------------
// High priority interrupt routine

#pragma code
#pragma interrupt InterruptHandlerHigh

void
InterruptHandlerHigh ()
{
  if (INTCONbits.INT0F)
    {       
      INTCONbits.INT0F = 0;
      flag = 1;
    }
}

thank you.
 

It is not too usual the use of goto instructions in C programming, even worse, in an assembly call. There should have other issues, but at least the flag variable is not being cleared anywhere.
 

It is not too usual the use of goto instructions in C programming, even worse, in an assembly call. There should have other issues, but at least the flag variable is not being cleared anywhere.

thanks for the comment.
yeah you're right. I usually don't use "goto" in my codes. but it is an example from microchip. and "flag" varible is not being cleared because it is a very simple project and I want to test the external interrupt.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top