Multiple interrupt (RBIE, INT0, INT1)

General discussion on mikroPascal.
Post Reply
Author
Message
MattH
Posts: 173
Joined: 09 Jan 2005 03:55
Location: Allentown,PA

Multiple interrupt (RBIE, INT0, INT1)

#1 Post by MattH » 28 Jan 2005 04:33

Hi,
I'm trying to get 3 int's working but 'm having trouble.
Hardware: EasyPic2 8MHz
Using 4 buttons on PORTB<7:4> under interrupt
2 Buttons (PORTB.0 & 1) to simulate interrupt on INT0, INT1
GLCD to monitor some states.
I can't publish the whole source because it is approx. 30kB
Following are the most important parts:

<initial setup>

Code: Select all

{===================================================================}
  {INTCON2 : %01100001 >> $61
           : 0 = RBIP RB PORT CHANGE
           : 1 = -
           : 2 = TMR0IP TMR0 OVERFLOW
           : 3 = -
           : 4 = INTEDGE2 1=RISING/0=FALLING EDGE
           : 5 = INTEDGE1 1=RISING/0=FALLING EDGE
           : 6 = INTEDGE0 1=RISING/0=FALLING EDGE
           : 7 = RBPU 1=PORTB PULLUP ENABLED, 0= DISABLED
  }
  intcon2 := $61;        //rising edge on INT0/INT1
  {INTCON3 : %01001000 >> $48
           : 0 = INT1IF 1=INT OCCURRED
           : 1 = INT2IF
           : 2 = -
           : 3 = INT1IE 1=INT1 ENABLED
           : 4 = INT2IE 1=INT2 ENABLED
           : 5 = -
           : 6 = INT1IP 1=HIGH PRIORITY
           : 7 = INT2IP
  }
  intcon3 := $48;         //enable INT1  high prio
  //delay_ms(5000);
    {INTCON : %11011000 >> $D8
           : 0 = RBIF PORTB<7:4> STATE CHANGE
           : 1 = INT0IF INT OCCURRED
           : 2 = TMR0IF TMR0 OVERFLOW OCCURRED
           : 3 = RBIE 1=PORTB CHANGE ENABLED
           : 4 = INT0IE 1=INT0 ENABLED
           : 5 = TMR0IE 1=TMR0 OVERFLOW INT ENABLED
           : 6 = PEIE/GIEL 1=HIGH PRIORITY
           : 7 = GIE/GIEH 1=GLOBAL INT'S ENABLED
  }
  intcon := $D8;         //enable RBIE & INT0
{======================================================================}
< ISR >

Code: Select all

procedure interrupt;
begin
 // intcon := $0F;
  if TestBit(INTCON,RBIF) <> 0 then    // test if RBIF is set
    begin
      delay_us(1000);                  // wait 5 mS
      new_portb:=portb and $F0;
      intcon:=$D8;                     // enable global int &int0,rbie
    end
  else
       if TestBit(INTCON,INT0IF) <> 0 then    // test if INT0IE is set
        begin
        clearbit(intcon,7);                   // disable  global int
        TMR1H := $00;
        TMR1L := $00;
        int0_t:=true;
        clearbit(intcon,INT0IF);            // clear INT0IF
        setbit(INTCON,INT0IE);
        setbit(T1CON,1);                    //START timer1
        setbit(portc,5);
        setbit(intcon,7);                  // enable global int
        end
  else
       if TestBit(INTCON3,INT1IF) <> 0 then   // test if INT1IE is set
        begin
        clearbit(intcon,7);                   // disable  global int
        clearbit(portc,5);
        clearbit(T1CON,0);                   // stop timer1
        clearbit(intcon3,INT1IF);            // clear INT1IF
        setbit(INTCON3,INT1IE);
        setbit(intcon,7);                   // enable global int
        end;
end;
After restart the program reacts differently. Sometimes it goes straight in to ISR<INT0> w/out doing anything. Sometimes the buttons PORTB<7:4>
working, sometimes they don't.

I switched PIC's w/out any results.

I'm done (for now).....
Last edited by MattH on 28 Jan 2005 13:30, edited 4 times in total.
Don't code after midnight...

Storic
Posts: 393
Joined: 01 Oct 2004 00:20
Location: Australia (S.A.)

#2 Post by Storic » 28 Jan 2005 06:27

Hi,
I have found that with interrupts, I dont use the If then Else....

IF interupt_0 THEN ... do somthing

followed by the next

IF interupt_1 THEN ... do somthing.

I also try to enable the interupts outside the interupt and reset the interupt at the end of the interupt;

I dont know if this we help, It works for me.

Andrew

Post Reply

Return to “mikroPascal General”