[SOLVED] pic18f4520 PORT RB0 external interrupt not working

Status
Not open for further replies.

burrow

Full Member level 2
Joined
Dec 15, 2014
Messages
147
Helped
3
Reputation
6
Reaction score
3
Trophy points
18
Visit site
Activity points
1,148
Hai,
I cant make the external RB0 interrupt to work in PIC18F4520.
I just tried out a small code to test the interrupt alone and i found that interrupt on change is working but RB0 interrupt doesnt work. I tried all combination of INTCON registers.

Here is my test code



Code dot - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
sbit LCD_RS at RC2_bit;
sbit LCD_EN at RA0_bit;
sbit LCD_D4 at RD0_bit;
sbit LCD_D5 at RC5_bit;
sbit LCD_D6 at RC0_bit;
sbit LCD_D7 at Rc1_bit;
sbit LCD_RS_Direction at TRISC2_bit;
sbit LCD_EN_Direction at TRISA0_bit;
sbit LCD_D4_Direction at TRISD0_bit;
sbit LCD_D5_Direction at TRISC5_bit;
sbit LCD_D6_Direction at TRISC0_bit;
sbit LCD_D7_Direction at TRISC1_bit;
 
  char ab;
 
 void interrupt(void)
{
    if(INTCON.RBIF==1)
        {
         ab=PORTB;
         Lcd_Out(1,3,"Change interrupt");
         Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
         Delay_ms(100);
         Delay_ms(100);
         Lcd_Cmd(_LCD_CLEAR); // Clear display
         Delay_ms(100);
         INTCON.RBIF = 0;
         }
 
    if(INTCON.INT0IF==1)
      {
          Lcd_Out(1,3,"PORT B INTERRUPT");
          Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
          Delay_ms(100);
          Delay_ms(100);
          Lcd_Cmd(_LCD_CLEAR); // Clear display
          Delay_ms(100);
          INTCON.INT0IF==0;
       
      }
}
 
void main() {
   
   TRISB=0b11111111;
   INTCON.RBIE = 1;
   INTCON.GIE = 1;
   INTCON.INT0IE= 1;
   INTCON.PEIE = 1;
   INTCON.GIEL=1;
   INTCON.GIEH=1;
   INTCON.IPEN = 1;
 
    INTCON2.INTEDG0 = 1;
    INTCON2.RBIP = 1;
    Lcd_Init();
  while(1)
  {
    ;
  }
  
  }

 
Last edited by a moderator:

Don't use lengthy code and delays inside ISR. In your ISR LCD data is displayed and within 200 ms it is cleared and so you don't see anything on the display.
 

when we deal with interrupts, some settings needed as follows


#pragma code high_vector = 0x08
void interrupt_at_high_vector(void)
{
_asm
GOTO chk_isr
_endasm
}
#pragma code //return to the default code section


#pragma interrupt chk_isr



here chk_isr is the isr function name..............
 

@Surender Reddy

OP is using mikroC PRO PIC Compiler. No additional code is needed.
 

Yea i know its not a good idea to use lengthy code and delays in interrupt. I dont use them in my program. i used here to test if the interrrupt is working. And found that its not entering the interrupt function.

Some thing else is wrong here itseems



Don't use lengthy code and delays inside ISR. In your ISR LCD data is displayed and within 200 ms it is cleared and so you don't see anything on the display.

- - - Updated - - -

Hey i got it working, the problem was the lines
CMCON = 0x07;
ADCON1 = 0x06;
i removed those lines and the interrupt started working
 

If pin used for interrupt has ADC or any other multiplexed functions then they have to be disabled by configuring the respective registers.
 
Reactions: burrow

    burrow

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…