• AVR Freaks

AnsweredHot!External interrupt for panic button

Page: 12 > Showing page 1 of 2
Author
Djsarkar
Senior Member
  • Total Posts : 150
  • Reward points : 0
  • Joined: 2020/07/27 01:14:06
  • Location: 0
  • Status: online
2020/09/28 09:42:19 (permalink)
0

External interrupt for panic button

I have PIC18F45K80. I am using MPLABX 5.40 and XC8 2.30. I want to generate hardware interrupt for panic button 
 
I have written code but I am getting error 
 

 

#define _XTAL_FREQ 8000000
#include <xc.h>
// PIC18F45K80 Configuration Bit Settings
// 'C' source line config statements
// CONFIG1L
#pragma config RETEN = OFF      // VREG Sleep Enable bit (Ultra low-power regulator is Disabled (Controlled by REGSLP bit))
#pragma config INTOSCSEL = HIGH // LF-INTOSC Low-power Enable bit (LF-INTOSC in High-power mode during Sleep)
#pragma config SOSCSEL = HIGH   // SOSC Power Selection and mode Configuration bits (High Power SOSC circuit selected)
#pragma config XINST = OFF       // Extended Instruction Set (Enabled)
// CONFIG1H
#pragma config FOSC = INTIO2    // Oscillator (Internal RC oscillator)
#pragma config PLLCFG = OFF     // PLL x4 Enable bit (Disabled)
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor (Disabled)
#pragma config IESO = OFF       // Internal External Oscillator Switch Over Mode (Disabled)
// CONFIG2L
#pragma config PWRTEN = OFF     // Power Up Timer (Disabled)
#pragma config BOREN = SBORDIS  // Brown Out Detect (Enabled in hardware, SBOREN disabled)
#pragma config BORV = 3         // Brown-out Reset Voltage bits (1.8V)
#pragma config BORPWR = ZPBORMV // BORMV Power level (ZPBORMV instead of BORMV is selected)
// CONFIG2H
#pragma config WDTEN = OFF      // Watchdog Timer (WDT disabled in hardware; SWDTEN bit disabled)
#pragma config WDTPS = 1048576  // Watchdog Postscaler (1:1048576)
// CONFIG3H
#pragma config CANMX = PORTB    // ECAN Mux bit (ECAN TX and RX pins are located on RB2 and RB3, respectively)
#pragma config MSSPMSK = MSK7   // MSSP address masking (7 Bit address masking mode)
#pragma config MCLRE = ON       // Master Clear Enable (MCLR Enabled, RE3 Disabled)
// CONFIG4L
#pragma config STVREN = ON      // Stack Overflow Reset (Enabled)
#pragma config BBSIZ = BB2K     // Boot Block Size (2K word Boot Block size)
// CONFIG5L
#pragma config CP0 = OFF        // Code Protect 00800-01FFF (Disabled)
#pragma config CP1 = OFF        // Code Protect 02000-03FFF (Disabled)
#pragma config CP2 = OFF        // Code Protect 04000-05FFF (Disabled)
#pragma config CP3 = OFF        // Code Protect 06000-07FFF (Disabled)
// CONFIG5H
#pragma config CPB = OFF        // Code Protect Boot (Disabled)
#pragma config CPD = OFF        // Data EE Read Protect (Disabled)
// CONFIG6L
#pragma config WRT0 = OFF       // Table Write Protect 00800-01FFF (Disabled)
#pragma config WRT1 = OFF       // Table Write Protect 02000-03FFF (Disabled)
#pragma config WRT2 = OFF       // Table Write Protect 04000-05FFF (Disabled)
#pragma config WRT3 = OFF       // Table Write Protect 06000-07FFF (Disabled)
// CONFIG6H
#pragma config WRTC = OFF       // Config. Write Protect (Disabled)
#pragma config WRTB = OFF       // Table Write Protect Boot (Disabled)
#pragma config WRTD = OFF       // Data EE Write Protect (Disabled)
// CONFIG7L
#pragma config EBTR0 = OFF      // Table Read Protect 00800-01FFF (Disabled)
#pragma config EBTR1 = OFF      // Table Read Protect 02000-03FFF (Disabled)
#pragma config EBTR2 = OFF      // Table Read Protect 04000-05FFF (Disabled)
#pragma config EBTR3 = OFF      // Table Read Protect 06000-07FFF (Disabled)
// CONFIG7H
#pragma config EBTRB = OFF      // Table Read Protect Boot (Disabled)

void __interrupt() tcInt(void){
     if (RB0 == 0)   // check switch if pressed
           {
             __delay_ms(40); // wait
          
             if (RB0 == 0)   // check switch if pressed
             {
               LATA0 = 1;   // LED ON
               __delay_ms(40); // wait
               LATA0 = 0;   // LED ON
               __delay_ms(40); // wait
             }
           }
    }

void main(void)
{
 
    LATA =  0;
    LATB =  0;
    LATC =  0;
    LATD =  0;
    LATE =  0;
 
    TRISA = 0b0000000;// LED connected at RA0
    TRISB = 0b0000001;// Panic button connected to External interrupt pin as an input.
    TRISC = 0b0000000;// All are output, Unused
    TRISD = 0b0000000;// All are output, RD7 LED connected
    TRISE = 0b0000000;// All are output, Unused
   
    ANCON0 = 0; // digital port
    ANCON1 = 0; // digital port
 
    CM1CON = 0; // Comparator off
    CM2CON = 0; // Comparator off
 
    ADCON0 = 0; // A/D conversion Disabled
       
    INTCON = 0b10010000; //INTERRUPT CONTROL REGISTER
    //Global interrupt enable bit = 1
    //Disables all peripheral interrupts = 0
    //Disables the TMR0 overflow interrupt = 0
    //Enables the INT0 external interrupt = 1
    //Disables the RB port change interrupt = 0
    //TMR0 register has not overflowed = 0
    //clear The INT0 external interrupt Flag = 0,
    // None of the RB<7:4> pins have changed state = 0
   
    INTCON2=0b00000000;  /* Set Interrupt detection on falling Edge*/
  
    while (1)
    {
    }
       
}
 

 
 error: use of undeclared identifier 'RB0'
     if (RB0 == 0)   // check switch if pressed
         ^
 if I change LATB to PORTB still getting same error 
post edited by Djsarkar - 2020/09/28 09:44:58
#1
KTrenholm
Super Member
  • Total Posts : 796
  • Reward points : 0
  • Joined: 2012/08/08 14:04:23
  • Location: Connecticut, USA
  • Status: offline
Re: External interrupt for panic button 2020/09/28 09:58:26 (permalink)
+5 (5)
I haven't used XC8 very much, but if it's like XC16 in how ports/pins are accessed, your check of RB0 should be:
if (PORTBbits.RB0 == 0)
 
P.S. Delays inside of interrupts are generally considered inadvisable:
https://www.microchip.com/forums/m650655.aspx
https://www.microchip.com/forums/m835242.aspx
you may want to rethink how to handle debouncing.  Perhaps inside the external interrupt ISR start a 40ms timer, then check the pin state again once the timer elapses.
 
 
post edited by KTrenholm - 2020/09/28 10:23:51
#2
ric
Super Member
  • Total Posts : 28660
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: External interrupt for panic button 2020/09/28 13:21:37 (permalink)
0
As mentioned, the real name of that bit is PORTBbits.RB0
Some pins have shortcuts defined, e.g. you can use RB2 to access PORTBbits.RB2.
On that device, there are no shortcuts for RB0 or RB1, probably because there are bits in other registers that use those names. (B0DLC to B5DLC)
 
 
 

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!
#3
dan1138
Super Member
  • Total Posts : 3917
  • Reward points : 0
  • Joined: 2007/02/21 23:04:16
  • Location: 0
  • Status: offline
Re: External interrupt for panic button 2020/09/28 15:11:15 (permalink)
+2 (2)
ric,
 
The Original Poster(OP) is likely using the simulator. For the PIC18F45K80 there are a lot of things that are just bad in the craptastic MPLABX v5.40 simulation tool.
 
Now the OP's posted code is broken as well.
 
This is what I could get the simulator to run correctly:
/*
 * File:   main.c
 * Author: dan1138
 *
 * Created on September 28, 2020, 2:07 PM
 */

// PIC18F45K80 Configuration Bit Settings

// 'C' source line config statements

// CONFIG1L
#pragma config RETEN = OFF      // VREG Sleep Enable bit (Ultra low-power regulator is Disabled (Controlled by REGSLP bit))
#pragma config INTOSCSEL = HIGH // LF-INTOSC Low-power Enable bit (LF-INTOSC in High-power mode during Sleep)
#pragma config SOSCSEL = HIGH   // SOSC Power Selection and mode Configuration bits (High Power SOSC circuit selected)
#pragma config XINST = OFF      // Extended Instruction Set (Disabled)

// CONFIG1H
#pragma config FOSC = INTIO2    // Oscillator (Internal RC oscillator)
#pragma config PLLCFG = OFF     // PLL x4 Enable bit (Disabled)
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor (Disabled)
#pragma config IESO = OFF       // Internal External Oscillator Switch Over Mode (Disabled)

// CONFIG2L
#pragma config PWRTEN = OFF     // Power Up Timer (Disabled)
#pragma config BOREN = OFF      // Brown Out Detect (Disabled in hardware, SBOREN disabled)
#pragma config BORV = 3         // Brown-out Reset Voltage bits (1.8V)
#pragma config BORPWR = ZPBORMV // BORMV Power level (ZPBORMV instead of BORMV is selected)

// CONFIG2H
#pragma config WDTEN = OFF      // Watchdog Timer (WDT disabled in hardware; SWDTEN bit disabled)
#pragma config WDTPS = 1048576  // Watchdog Postscaler (1:1048576)

// CONFIG3H
#pragma config CANMX = PORTB    // ECAN Mux bit (ECAN TX and RX pins are located on RB2 and RB3, respectively)
#pragma config MSSPMSK = MSK7   // MSSP address masking (7 Bit address masking mode)
#pragma config MCLRE = ON       // Master Clear Enable (MCLR Enabled, RE3 Disabled)

// CONFIG4L
#pragma config STVREN = ON      // Stack Overflow Reset (Enabled)
#pragma config BBSIZ = BB2K     // Boot Block Size (2K word Boot Block size)

// CONFIG5L
#pragma config CP0 = OFF        // Code Protect 00800-01FFF (Disabled)
#pragma config CP1 = OFF        // Code Protect 02000-03FFF (Disabled)
#pragma config CP2 = OFF        // Code Protect 04000-05FFF (Disabled)
#pragma config CP3 = OFF        // Code Protect 06000-07FFF (Disabled)

// CONFIG5H
#pragma config CPB = OFF        // Code Protect Boot (Disabled)
#pragma config CPD = OFF        // Data EE Read Protect (Disabled)

// CONFIG6L
#pragma config WRT0 = OFF       // Table Write Protect 00800-01FFF (Disabled)
#pragma config WRT1 = OFF       // Table Write Protect 02000-03FFF (Disabled)
#pragma config WRT2 = OFF       // Table Write Protect 04000-05FFF (Disabled)
#pragma config WRT3 = OFF       // Table Write Protect 06000-07FFF (Disabled)

// CONFIG6H
#pragma config WRTC = OFF       // Config. Write Protect (Disabled)
#pragma config WRTB = OFF       // Table Write Protect Boot (Disabled)
#pragma config WRTD = OFF       // Data EE Write Protect (Disabled)

// CONFIG7L
#pragma config EBTR0 = OFF      // Table Read Protect 00800-01FFF (Disabled)
#pragma config EBTR1 = OFF      // Table Read Protect 02000-03FFF (Disabled)
#pragma config EBTR2 = OFF      // Table Read Protect 04000-05FFF (Disabled)
#pragma config EBTR3 = OFF      // Table Read Protect 06000-07FFF (Disabled)

// CONFIG7H
#pragma config EBTRB = OFF      // Table Read Protect Boot (Disabled)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#include <xc.h>

#define _XTAL_FREQ 8000000
/*
 *
 */
void __interrupt() tcInt(void)
{
    if((INTCONbits.INT0IE) && (INTCONbits.INT0IF))
    {
        INTCONbits.INT0IF = 0;
        INTCONbits.INT0IE = 0;
        /*
         * Handle a panic event
         */
    }
}
/*
 *
 */
void main(void)
{
    INTCON = 0;
    
    LATA =  0;
    LATB =  0;
    LATC =  0;
    LATD =  0;
    LATE =  0;
 
    TRISA = 0b0000000;// LED connected at RA0
    TRISB = 0b0000001;// Panic button connected to External interrupt pin as an input.
    TRISC = 0b0000000;// All are output, Unused
    TRISD = 0b0000000;// All are output, RD7 LED connected
    TRISE = 0b0000000;// All are output, Unused
    
    ADCON0 = 0; /* The simulator seems to need this */
    ADCON1 = 0; /* PORTB bits to read correctly. */
    ANCON0 = 0; /* make AN0 to AN7 digital */
    ANCON1 = 0; /* make AN8 to AN14 digital */
    CM1CON = 0; /* Turn off comparators */
    CM2CON = 0;

    INTCON2bits.INTEDG0 = 0;    /* Select High to Low edge for INT0 */
    INTCONbits.INT0IF   = 0;    /* Clear INT0 assert */
    INTCONbits.INT0IE   = 1;    /* Enable INT0 interrupt */
    INTCONbits.GIE      = 1;    /* Enable system interrupts */
    
    for(;;)
    {
        if((!INTCONbits.INT0IE) && (PORTBbits.RB0))
        {
            /*
             * When INT0IE is low and RB0 is high a panic event
             * was detected and cleared.
             *
             * The action here is to wait 100 milliseconds
             * then re-enable detection of interrupt used
             * to detect panic events.
             */
            __delay_ms(100);
            INTCONbits.INT0IF = 0;
            INTCONbits.INT0IE = 1;
        }
        
    }
}

The simulator fault is that ADCON0 and ADCON1 must be zeroed as well as ANCON0 and ANCON1 for PORTB bit RB0 to read as a one. Now here is where the simulator goes sideways. When ANCON0 and ANCON1 are not zeroed the interrupt is recognized but PORTB bit RB0 always reads as zero regardless of what the stimulus action is.
 
It seems the only purpose for the simulator is to personally annoy me.
post edited by dan1138 - 2020/09/28 15:39:52
#4
ric
Super Member
  • Total Posts : 28660
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: External interrupt for panic button 2020/09/28 15:36:27 (permalink)
0
dan1138
ric,
 
The Original Poster(OP) is likely using the simulator.

Hi Dan.
I'm curious how you come to that conclusion. From something in another thread maybe?
The question in this thread is purely about why trying to use "RB0" to read a pin on a PIC18F45K80 gives a compiler error.
Post#2 explained how to do it, and my post explained why RB0 doesn't work on this PIC.
 

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!
#5
dan1138
Super Member
  • Total Posts : 3917
  • Reward points : 0
  • Joined: 2007/02/21 23:04:16
  • Location: 0
  • Status: offline
Re: External interrupt for panic button 2020/09/28 15:56:28 (permalink)
+1 (1)
ric
I'm curious how you come to that conclusion. From something in another thread maybe?

I have been seeing Djsarkar's posts in several PIC related forums and he seems to bounce around from real parts to simulator sessions.

I posted my code here just in case the OP is trying this on the simulator.
#6
hexreader
Super Member
  • Total Posts : 1091
  • Reward points : 0
  • Joined: 2008/05/04 03:06:55
  • Location: England
  • Status: online
Re: External interrupt for panic button 2020/09/28 15:59:26 (permalink)
0
Is it the forum software that has mangled the indenting on the OPs code?
... or maybe MPLABX editor?
 
Or did the OP mangle the formatting all by himself/herself?
 
I nagged him/her about poor formatting on another forum, but it now occurs to me that I may owe an apology
post edited by hexreader - 2020/09/28 16:00:32

Experienced Hobbyist
#7
Djsarkar
Senior Member
  • Total Posts : 150
  • Reward points : 0
  • Joined: 2020/07/27 01:14:06
  • Location: 0
  • Status: online
Re: External interrupt for panic button 2020/09/28 16:45:33 (permalink)
0
KTrenholm
I haven't used XC8 very much, but if it's like XC16 in how ports/pins are accessed, your check of RB0 should be:
if (PORTBbits.RB0 == 0)
 
Perhaps inside the external interrupt ISR start a 40ms timer, then check the pin state again once the timer elapses.

KTrenholm  Thanks Now the code is compile with no errors 
 
Yes I am aware that ISR should be short and there should be know delay in ISR but I am just testing code 
#8
PStechPaul
Super Member
  • Total Posts : 2950
  • Reward points : 0
  • Joined: 2006/06/27 16:11:32
  • Location: Cockeysville, MD, USA
  • Status: offline
Re: External interrupt for panic button 2020/09/28 16:52:54 (permalink)
-1 (1)
There are known errors in the simulator for 5.40. We were "promised" a fix with 5.45 due end of August, but that ship has sailed (or sunk). Maybe August 2021?

 
#9
Djsarkar
Senior Member
  • Total Posts : 150
  • Reward points : 0
  • Joined: 2020/07/27 01:14:06
  • Location: 0
  • Status: online
Re: External interrupt for panic button 2020/09/28 17:00:41 (permalink)
0
Hi Dan
 
I was learning how to use simulator tools to test code but this question about external interrupt and error related to code. I have actual development board  
 
Hi ric 
Thanks for mention the exact reason of RB0 why its not working. Now the code is compiling with no error
But When I press LED is not turning on  
 
Hi hexreder
 
I have experienced problem with forum software
#10
hexreader
Super Member
  • Total Posts : 1091
  • Reward points : 0
  • Joined: 2008/05/04 03:06:55
  • Location: England
  • Status: online
Re: External interrupt for panic button 2020/09/28 17:08:18 (permalink)
+2 (2)
Quote "I have experienced problem with forum software"
 
I had a feeling that the forum may have issues.
 
My sincere apologies for being mean :(
 
Will make it up to you in 2 weeks when my PIC18F45K80 arrives and I can help with your projects
post edited by hexreader - 2020/09/28 17:09:43

Experienced Hobbyist
#11
dan1138
Super Member
  • Total Posts : 3917
  • Reward points : 0
  • Joined: 2007/02/21 23:04:16
  • Location: 0
  • Status: offline
Re: External interrupt for panic button 2020/09/28 17:52:32 (permalink) ☼ Best Answerby Djsarkar 2020/09/29 07:02:13
+2 (2)
Djsarkar
I was learning how to use simulator tools to test code but this question about external interrupt and error related to code. I have actual development board

With real hardware see of this code will cause the LED to change:
/*
 * File:   main.c
 * Author: dan1138
 *
 * Created on September 28, 2020, 2:07 PM
 */

// PIC18F45K80 Configuration Bit Settings

// 'C' source line config statements

// CONFIG1L
#pragma config RETEN = OFF      // VREG Sleep Enable bit (Ultra low-power regulator is Disabled (Controlled by REGSLP bit))
#pragma config INTOSCSEL = HIGH // LF-INTOSC Low-power Enable bit (LF-INTOSC in High-power mode during Sleep)
#pragma config SOSCSEL = HIGH   // SOSC Power Selection and mode Configuration bits (High Power SOSC circuit selected)
#pragma config XINST = OFF      // Extended Instruction Set (Disabled)

// CONFIG1H
#pragma config FOSC = INTIO2    // Oscillator (Internal RC oscillator)
#pragma config PLLCFG = OFF     // PLL x4 Enable bit (Disabled)
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor (Disabled)
#pragma config IESO = OFF       // Internal External Oscillator Switch Over Mode (Disabled)

// CONFIG2L
#pragma config PWRTEN = OFF     // Power Up Timer (Disabled)
#pragma config BOREN = OFF      // Brown Out Detect (Disabled in hardware, SBOREN disabled)
#pragma config BORV = 3         // Brown-out Reset Voltage bits (1.8V)
#pragma config BORPWR = ZPBORMV // BORMV Power level (ZPBORMV instead of BORMV is selected)

// CONFIG2H
#pragma config WDTEN = OFF      // Watchdog Timer (WDT disabled in hardware; SWDTEN bit disabled)
#pragma config WDTPS = 1048576  // Watchdog Postscaler (1:1048576)

// CONFIG3H
#pragma config CANMX = PORTB    // ECAN Mux bit (ECAN TX and RX pins are located on RB2 and RB3, respectively)
#pragma config MSSPMSK = MSK7   // MSSP address masking (7 Bit address masking mode)
#pragma config MCLRE = ON       // Master Clear Enable (MCLR Enabled, RE3 Disabled)

// CONFIG4L
#pragma config STVREN = ON      // Stack Overflow Reset (Enabled)
#pragma config BBSIZ = BB2K     // Boot Block Size (2K word Boot Block size)

// CONFIG5L
#pragma config CP0 = OFF        // Code Protect 00800-01FFF (Disabled)
#pragma config CP1 = OFF        // Code Protect 02000-03FFF (Disabled)
#pragma config CP2 = OFF        // Code Protect 04000-05FFF (Disabled)
#pragma config CP3 = OFF        // Code Protect 06000-07FFF (Disabled)

// CONFIG5H
#pragma config CPB = OFF        // Code Protect Boot (Disabled)
#pragma config CPD = OFF        // Data EE Read Protect (Disabled)

// CONFIG6L
#pragma config WRT0 = OFF       // Table Write Protect 00800-01FFF (Disabled)
#pragma config WRT1 = OFF       // Table Write Protect 02000-03FFF (Disabled)
#pragma config WRT2 = OFF       // Table Write Protect 04000-05FFF (Disabled)
#pragma config WRT3 = OFF       // Table Write Protect 06000-07FFF (Disabled)

// CONFIG6H
#pragma config WRTC = OFF       // Config. Write Protect (Disabled)
#pragma config WRTB = OFF       // Table Write Protect Boot (Disabled)
#pragma config WRTD = OFF       // Data EE Write Protect (Disabled)

// CONFIG7L
#pragma config EBTR0 = OFF      // Table Read Protect 00800-01FFF (Disabled)
#pragma config EBTR1 = OFF      // Table Read Protect 02000-03FFF (Disabled)
#pragma config EBTR2 = OFF      // Table Read Protect 04000-05FFF (Disabled)
#pragma config EBTR3 = OFF      // Table Read Protect 06000-07FFF (Disabled)

// CONFIG7H
#pragma config EBTRB = OFF      // Table Read Protect Boot (Disabled)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#include <xc.h>

#define _XTAL_FREQ 8000000
/*
 *
 */
void __interrupt() tcInt(void)
{
    if((INTCONbits.INT0IE) && (INTCONbits.INT0IF))
    {
        INTCONbits.INT0IF = 0;
        INTCONbits.INT0IE = 0;
        /*
         * Handle a panic event
         */
        LATAbits.LA0 ^= 1;  /* Toggle LED on RA0 */
    }
}
/*
 *
 */
void main(void)
{
    INTCON = 0;
    
    LATA =  0;
    LATB =  0;
    LATC =  0;
    LATD =  0;
    LATE =  0;
 
    TRISA = 0b0000000;// LED connected at RA0
    TRISB = 0b0000001;// Panic button connected to External interrupt pin as an input.
    TRISC = 0b0000000;// All are output, Unused
    TRISD = 0b0000000;// All are output, RD7 LED connected
    TRISE = 0b0000000;// All are output, Unused
    
    ADCON0 = 0; /* The simulator seems to need this for */
    ADCON1 = 0; /* PORTB bits to read correctly. */
    ANCON0 = 0; /* make AN0 to AN7 digital */
    ANCON1 = 0; /* make AN8 to AN14 digital */
    CM1CON = 0; /* Turn off comparators */
    CM2CON = 0;

    INTCON2bits.INTEDG0 = 0;    /* Select High to Low edge for INT0 */
    INTCONbits.INT0IF   = 0;    /* Clear INT0 assert */
    INTCONbits.INT0IE   = 1;    /* Enable INT0 interrupt */
    INTCONbits.GIE      = 1;    /* Enable system interrupts */
    
    for(;;)
    {
        if((!INTCONbits.INT0IE) && (PORTBbits.RB0))
        {
            /*
             * When INT0IE is low and RB0 is high a panic event
             * was detected and cleared.
             *
             * The action here is to wait 100 milliseconds
             * then re-enable detection of interrupt used
             * to detect panic events.
             */
            __delay_ms(500);
            INTCONbits.INT0IF = 0;
            INTCONbits.INT0IE = 1;
        }
    }
}

This works as I expect in the simulator please let me know if this work on your board.
 
#12
Djsarkar
Senior Member
  • Total Posts : 150
  • Reward points : 0
  • Joined: 2020/07/27 01:14:06
  • Location: 0
  • Status: online
Re: External interrupt for panic button 2020/09/28 18:08:53 (permalink)
0
dan1138
This works as I expect in the simulator please let me know if this work on your board.

Hi dan
I ran your code but when I press button LED doesn't toggle 
#13
ric
Super Member
  • Total Posts : 28660
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: External interrupt for panic button 2020/09/28 18:24:41 (permalink)
0
How exactly is the button wired up?
Do you have external pullup or pulldown?
Have you checked the voltage on the PIC pin with the button up, and down?
 
 

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!
#14
Djsarkar
Senior Member
  • Total Posts : 150
  • Reward points : 0
  • Joined: 2020/07/27 01:14:06
  • Location: 0
  • Status: online
Re: External interrupt for panic button 2020/09/28 18:40:36 (permalink)
0
ric
How exactly is the button wired up?
Do you have external pullup or pulldown?
Have you checked the voltage on the PIC pin with the button up, and down?

Pullup resistor, I have attached connection 
I have measured 5v DC when I press button and when no button press 0 V DC 

Attached Image(s)

#15
davea
Super Member
  • Total Posts : 384
  • Reward points : 0
  • Joined: 2016/01/28 13:12:13
  • Location: Tampa Bay FL USA
  • Status: online
Re: External interrupt for panic button 2020/09/28 18:46:30 (permalink)
+1 (1)
I have measured 5v DC when I press button and when no button press 0 V DC 
you show switch type NO but they must be NC type for this to be true....
#16
Djsarkar
Senior Member
  • Total Posts : 150
  • Reward points : 0
  • Joined: 2020/07/27 01:14:06
  • Location: 0
  • Status: online
Re: External interrupt for panic button 2020/09/28 18:53:34 (permalink)
0
davea
I have measured 5v DC when I press button and when no button press 0 V DC 
you show switch type NO but they must be NC type for this to be true....

attached picture of my actual hardware
I am using 12 DC power supply 
PIC Kit3
 
RA0 connected to L0
RB0 connected to SW1 CN10
 
post edited by Djsarkar - 2020/09/28 18:55:19

Attached Image(s)

#17
ric
Super Member
  • Total Posts : 28660
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: External interrupt for panic button 2020/09/28 20:37:56 (permalink)
0
I agree with davea.
The pin should be LOW when you are pressing the button!
 

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!
#18
dan1138
Super Member
  • Total Posts : 3917
  • Reward points : 0
  • Joined: 2007/02/21 23:04:16
  • Location: 0
  • Status: offline
Re: External interrupt for panic button 2020/09/28 20:39:42 (permalink)
0
Djsarkar
dan1138
This works as I expect in the simulator please let me know if this work on your board.

Hi dan
I ran your code but when I press button LED doesn't toggle

What else is there to say at this point.
 
The code works in the simulator so perhaps the fault lies elsewhere.
 
Perhaps if you posted the schematic that NSK Electronics claims it included on the CD that ships with the development board it may give a clue of where best for you to go next.
#19
davea
Super Member
  • Total Posts : 384
  • Reward points : 0
  • Joined: 2016/01/28 13:12:13
  • Location: Tampa Bay FL USA
  • Status: online
Re: External interrupt for panic button 2020/09/28 20:41:56 (permalink)
0
can you identify what that PIC board is...
as i not going looking for it
and what point do you "just give up"
#20
Page: 12 > Showing page 1 of 2
Jump to:
© 2020 APG vNext Commercial Version 4.5