Problem with Interrupt on PIC18F4620 PORTB


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2007
    Posts
    4

    Default Problem with Interrupt on PIC18F4620 PORTB

    Hi,
    i have this problem on my program. I tried calling the interrupt routine but it just won't be called. For this case, i need to press the SW3(button) and there will be an interrupt but the interrupt just wont be activated and hence the routine won't be called. Can anyone help me with this? Any help will be appreciated.My source code is as below:


    #include<p18f4620.h> //for special function register declarations
    #include<portb.h> //for the RB0/INT0 interrupt
    //#include<adc.h>
    //#include<stdlib.h>
    //#include<delays.h>


    void Record (void);
    #pragma code InterruptVectorHigh = 0x08
    void InterruptVectorHigh(void)
    {
    _asm
    goto Record
    _endasm
    }
    #pragma code //allow the linker to locate the remaining code

    #pragma interrupt Record
    void Record(void)
    {
    PORTDbits.RD6=0;
    PORTDbits.RD7=0;
    PORTCbits.RC2=0;
    INTCONbits.INT0IF=0; //clear flag to avoid another interrupt
    }

    void EnableHighInterrupts(void)
    {
    RCONbits.IPEN =1; //enable interrupt priority levels
    INTCONbits.GIEH=1; //enable all high priority interrupts
    }

    void WaitForRecord(void)
    {
    //INTCONbits.RBIF=0;
    while(1); //wait for the SW3 button to be pressed
    }

    void main(void)
    {
    /*Port, TRIS and LAT initialisation*/
    //TRISA = 0x8F; //RA<3:0> as inputs, this value will change after
    //checking PORT A
    //PORTAbits.RA4=1;
    //PORTAbits.RA5=1; //it showed HIGH on hardware but not at the
    //watch view
    ADCON1 = 0x0F;
    TRISB = 0x07; //RB<2:0> as inputs
    //RB<5:3> as outputs
    //RB<7:6> as inputs
    LATB = 0x00;
    //PORTB=0x00;
    //PORTBbits.RB3=1;
    //PORTBbits.RB4=1;
    //PORTBbits.RB5=1;

    //TRISC = 0x20; //RC5 as inputs
    //RC<7:6>, RC<4:0> as outputs
    //PORTCbits.RC0=1;
    //PORTCbits.RC1=1;
    //PORTCbits.RC2=1;
    //PORTCbits.RC3=1;
    //PORTCbits.RC4=1;

    //TRISD = 0x00; //RD<7:0> as outputs

    //PORTDbits.RD6=1;
    //PORTDbits.RD7=1;

    //TRISE = 0xB0; //RE<2:0> as outputs, this value will change after
    //checking PORT E
    //ADCON1 = 0x0A;//Configure A/D for digital inputs for PORT E
    //PORTEbits.RE0=1;
    //PORTEbits.RE1=1;
    //PORTEbits.RE2=1;


    EnableHighInterrupts();

    OpenRB0INT(PORTB_CHANGE_INT_ON & //enable the RB0/INT0 interrupt
    PORTB_PULLUPS_ON & //configure the RB0 pin for input
    FALLING_EDGE_INT); //trigger interrupt upon SW3 button
    //depression
    WaitForRecord();
    }

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by rookie View Post
    #include<p18f4620.h> //for special function register declarations
    #include<portb.h> //for the RB0/INT0 interrupt
    //#include<adc.h>
    //#include<stdlib.h>
    //#include<delays.h>
    void Record (void);
    #pragma code InterruptVectorHigh = 0x08
    void InterruptVectorHigh(void)
    {
    _asm
    goto Record
    _endasm
    }
    #pragma code //allow the linker to locate the remaining code
    #pragma interrupt Record
    void Record(void)
    {
    PORTDbits.RD6=0;
    PORTDbits.RD7=0;
    PORTCbits.RC2=0;
    INTCONbits.INT0IF=0; //clear flag to avoid another interrupt
    }
    void EnableHighInterrupts(void)
    {
    RCONbits.IPEN =1; //enable interrupt priority levels
    INTCONbits.GIEH=1; //enable all high priority interrupts
    }
    void WaitForRecord(void)
    {
    //INTCONbits.RBIF=0;
    while(1); //wait for the SW3 button to be pressed
    }
    void main(void)
    {
    /*Port, TRIS and LAT initialisation*/
    //TRISA = 0x8F; //RA<3:0> as inputs, this value will change after
    //checking PORT A
    //PORTAbits.RA4=1;
    //PORTAbits.RA5=1; //it showed HIGH on hardware but not at the
    //watch view
    ADCON1 = 0x0F;
    TRISB = 0x07; //RB<2:0> as inputs
    //RB<5:3> as outputs
    //RB<7:6> as inputs
    LATB = 0x00;
    //PORTB=0x00;
    //PORTBbits.RB3=1;
    //PORTBbits.RB4=1;
    //PORTBbits.RB5=1;
    //TRISC = 0x20; //RC5 as inputs
    //RC<7:6>, RC<4:0> as outputs
    //PORTCbits.RC0=1;
    //PORTCbits.RC1=1;
    //PORTCbits.RC2=1;
    //PORTCbits.RC3=1;
    //PORTCbits.RC4=1;
    //TRISD = 0x00; //RD<7:0> as outputs
    //PORTDbits.RD6=1;
    //PORTDbits.RD7=1;
    //TRISE = 0xB0; //RE<2:0> as outputs, this value will change after
    //checking PORT E
    //ADCON1 = 0x0A;//Configure A/D for digital inputs for PORT E
    //PORTEbits.RE0=1;
    //PORTEbits.RE1=1;
    //PORTEbits.RE2=1;
    EnableHighInterrupts();
    OpenRB0INT(PORTB_CHANGE_INT_ON & //enable the RB0/INT0 interrupt
    PORTB_PULLUPS_ON & //configure the RB0 pin for input
    FALLING_EDGE_INT); //trigger interrupt upon SW3 button
    //depression
    WaitForRecord();
    }
    Try a C forum, not a PicBasic forum.

Similar Threads

  1. PICs can do more if use others than delays instructions
    By hardcore in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 24th February 2010, 19:52
  2. 16f886 interrupt on portB problem
    By antonjan in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 8th October 2008, 20:06
  3. shifting problem
    By helmut in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 31st August 2007, 06:11
  4. Interrupt Problem
    By Kamikaze47 in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 16th November 2005, 20:58
  5. Output PIC module
    By freelancebee in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th September 2005, 20:10

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts