0
\$\begingroup\$

I did many research but couldn't find out what the problem it is. Actually my code as below. I am trying to implement a code in C with XC8 compiler.

To enable a sentence on the LCD of the board while RB6 button is pressed. I enable INCTONbits.GIE = 1 and INTCONbits.RBIE = 1 and INTCONbits.RBIF = 0.

Inside of interrupt, the displaySentence() function is entered to infinity loop to see result. I checked all answers related with interrupt in here but didn't help my problem. What can be problem for RB7-4 interrupt, I am working on PIC18f8722.

void displaySentence();

void initialize();


void interrupt  RBINT_ISR(void){

    INTCONbits.GIE = 0;

 __delay_ms(10);

    while(1){
        displaySentence();
    }
    INTCONbits.RBIF = 0;
    INTCONbits.RBIE = 1;
    INTCONbits.GIE = 1;
}


void main(void)
{
    __delay_ms(15);
    __delay_ms(15);
    __delay_ms(15);
    __delay_ms(15);

    InitLCD();          // Initialize LCD in 4bit mode
    ClearLCDScreen();  // Clear LCD screen

    initialize();

    while(1);
}



void initialize(){

    TRISB = 0x40;
    PORTB = 0x00;

    // | GIE/GIEH | PEIE/GIEL | TMR0IE  | INT0IE | RBIE | TMR0IF | INT0IF | RBIF
    // |   1      |    0      |  0      |  0     |   1  |   0    |    0   |  0
    INTCONbits.RBIF = 0;
    INTCONbits.RBIE = 1;
    INTCONbits.GIE = 1;
}

void displaySentence(){

    WriteCommandToLCD(0x80);
    WriteStringToLCD("Interrupt");
    WriteCommandToLCD(0xC0);
    WriteStringToLCD("is working");
}
\$\endgroup\$
  • \$\begingroup\$ Does the LCD work to display strings from main()? How are you triggering the PortB interrupt? How are your PortB pins connected? \$\endgroup\$ – brhans May 1 '15 at 13:49
  • \$\begingroup\$ Yes LCD works correctly inside the main,I need to control RB6 button with PORTB change interrupt. I need to enable pull-up. \$\endgroup\$ – Alihuseyn May 1 '15 at 14:05
  • 1
    \$\begingroup\$ Have you enabled PortB pullups somewhere or do you have external pullup resistors? I don't see anything like a "INTCON2bits.RBPU = 0;" anywhere in your code to enable the internal pullups. \$\endgroup\$ – brhans May 1 '15 at 14:15
  • \$\begingroup\$ I didn't use "INTCON2bits.RBPU = 0;" but while using it directly goes to interrupt.It may be due to external pull up resistors. \$\endgroup\$ – Alihuseyn May 1 '15 at 15:03
1
\$\begingroup\$

Thanks @brhans for your answer I did as you said. I disabled INTCON2bits.RBPU = 0 and it worked for me.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.