• AVR Freaks

Hot!PIC18F452 External INT0 problems

Author
geshka
New Member
  • Total Posts : 15
  • Reward points : 0
  • Joined: 2020/12/10 14:12:20
  • Location: 0
  • Status: offline
2021/01/19 12:39:05 (permalink)
0

PIC18F452 External INT0 problems

Hello there.
I know that this topic was discussed many times , but unfortunately I cannot make it work whatever I am doing, so calling for common wisdom...
I have test setup with PIC18F452 on Picdem2plus board (if it matters), using C18 compiler/MPLAB IDE 8.92 .  Trying to implement external  interrupt on RB0 - pulling my hear for third day in a row - not working.  Just not getting into interrupt routine. 
 
 
Here is the code

#define _XTAL_FREQ 4000000UL

#include <p18f452.h>
// Configuration Bits
#pragma config OSC = XT
#pragma config LVP = OFF
#pragma config PWRT=OFF, BOR=OFF, BORV=45 //reset if below 4.5 volt
#pragma config DEBUG=ON,STVR=OFF

void HIGH_ISR(void) ;
void LOW_ISR(void) ;

// High Priority Interrupt Vector
#pragma code high_vector=0x08
void high_interrupt(void) {
 _asm GOTO HIGH_ISR _endasm
}
#pragma code

// Low Priority Interrupt Vector
#pragma code low_vector=0x18
void low_interrupt(void) {
 _asm GOTO LOW_ISR _endasm
}
#pragma code

// LOW PRIORITY INTERRUPT SERVICE ROUTINE
#pragma interruptlow LOW_ISR
void LOW_ISR(void) {

  }

}

// HIGH PRIORITY INTERRUPT SERVICE ROUTINE
#pragma interrupt HIGH_ISR
void HIGH_ISR(void) {
    if( INTCONbits.INT0IF == 1 ) { // On Change...

            LATBbits.LATB3 = ~LATBbits.LATB3;
            INTCONbits.INT0IF = 0;
  }

}

 
 
 void main(void)
 {
    TRISBbits.TRISB3 = 0; // test blinking LED on PB1
    
 INTCON2bits.RBPU = 0; // enable PORTB internal pullups
 TRISBbits.TRISB0 = 1; // PORTB bit 0 (connected to switch) is input (1)

 // Set up switch interrupt on INT0
 INTCON2bits.INTEDG0 = 0; // interrupt on falling edge of INT0 (switch pressed)
 INTCONbits.INT0IF = 0; // ensure flag is cleared
 INTCONbits.INT0IE = 1; // enable INT0 interrupt // NOTE: INT0 is ALWAYS a high priority interrupt
 // Set up global interrupts
 RCONbits.IPEN = 1; // Enable priority levels on interrupts
 INTCONbits.GIEL = 1; // Low priority interrupts allowed
 INTCONbits.GIEH = 1; // Interrupting enable

 INTCONbits.GIE = 1; //Global Interrupt Enable
    
     while(1)
     {
      
     }
 }
 
#1

3 Replies Related Threads

    ric
    Super Member
    • Total Posts : 29861
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: PIC18F452 External INT0 problems 2021/01/19 12:47:19 (permalink)
    0
    Any particular reason you are using the long obsolete C18 compiler rather than XC8?
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    geshka
    New Member
    • Total Posts : 15
    • Reward points : 0
    • Joined: 2020/12/10 14:12:20
    • Location: 0
    • Status: offline
    Re: PIC18F452 External INT0 problems 2021/01/19 13:04:19 (permalink)
    +1 (1)
    Yes, it just a bit of long story...
    I am working on original project based on PIC18F14K50 /C18 - DC motor controller with constant speed ( optical sensor feed with PID ) . Project is developed by some person and not being continued or supported anymore. It is very well developed  project (SW and HW), though there are few issues with code there - few bugs that I was trying to fix. Unfortunately debugging of 14K50 is complicated/expensive and I decided to port code to PIC18F254 with minimal changes, debug it, and than backport it.  I have already ported and made majority of the critical code, including Timer0 interrupt, ADC piece and PWM generation.  I just stuck with External interrupt routine that receiving optical pulses from encoder. 
    Any help will be appreciated.  
    #3
    geshka
    New Member
    • Total Posts : 15
    • Reward points : 0
    • Joined: 2020/12/10 14:12:20
    • Location: 0
    • Status: offline
    [SOLVED]Re: PIC18F452 External INT0 problems 2021/01/19 18:05:38 (permalink)
    +1 (1)
    Issue resolved.  Appears that PICdem 2 board has dividing resistor and LED that applying 2.4 volt to the RB0 pin.  That is not enough ( should be 0.8 X Vdd  = 4V )  to create interrupt rising edge.
     
    Thanks. 
    #4
    Jump to:
    © 2021 APG vNext Commercial Version 4.5