Tricky Interrupt

General discussion on mikroC.
Post Reply
Author
Message
davidm
Posts: 1
Joined: 19 Jul 2005 00:18

Tricky Interrupt

#1 Post by davidm » 19 Jul 2005 00:37

Here is an extract from a trial application using 'change of state' interrupts on PORTB. I am trying to ascertain which input (RB7 or RB6) invoked the interrupt.

An oscilloscope check on PORTC.F0 confirms the interrupt is being generated however, there is no activity on F5 nor F4.

OPTION_REG.RBPU is cleared so that weak pullups are enabled.

//////////////////////////////////////////////////////////////
//
// Device: PIC16F876
// Fosc: 14.7456MHz
//
// Pulse width: 0.66uSec
//
// PORTB bits 6 and 7 are pulsed inputs.
// PORTC bits 0, 5 and 4 are debug outputs.
//

unsigned char ucLastPortB; // ucLastPortB set to PORTB in main().
unsigned char ucIndexer;

void interrupt()
{
if ( INTCON & ( 1 << RBIF ) )
{
PORTC.F0 = 1;

ucLastPortB ^= PORTB; // Extract the change(s)

if ( ucLastPortB.F7 )
{
PORTC.F5 = 1;
ucIndexer = 0; // Reset
PORTC.F5 = 0;
}

if ( ucLastPortB.F6 )
{
PORTC.F4 = 1;
++ucIndexer; // Incr
PORTC.F4 = 0;

}

ucLastPortB = PORTB;

INTCON &= ~( 1 << RBIF ); // Clear flag
PORTC.F0 = 0;
}
}

//////////////////////////////////////////////////////////////

Comments are sought.

Regards - davidm

pizon
mikroElektronika team
Posts: 823
Joined: 11 Oct 2004 08:53

Re: Tricky Interrupt

#2 Post by pizon » 19 Jul 2005 09:57

1. You must disable weak pull-ups, otherwise you won't be able to detect any change:

Code: Select all

OPTION_REG.f7 = 1; // RBPU off
2. Insert a small delay (~5ms) between PORTC.F4/F5 state change, to be able to detect it;
pizon

Post Reply

Return to “mikroC General”