The use of the pin RB0/Int to execute an interrupt routine caused by an external pulse is a really interesting function available almost in any picmicro. This is a really easy matter to be managed particularly using high-level languages like MikroBasic/MikroC.
The use of the RB0/Int to manage interrupt externally generated requires the setting of a couple of registers of the picmicro: INTCON and OPTION_REG:
![]() |
It should be clear that the use of RB0/Int function of a picmicro requires the setting of the: GIE(7): set to 1 to enable global interrupts INTE(4): set to 1 to enable interrupts on pin RB0 PEIE(6): to disable other periferal interrupts and the set of the INTEDG bit(6) of the OPTION_REG register simply to select the rising or falling edge, of the signal. ) |
MIKROC A simple portD blinking on interrupt void interrupt(void) void main(void) |
|
Here follows a simple program, for a 16F877 or similar picmicro to generate the phases of a stepper motor upon a pulse on the interrupt pin. The four phases are given by portd.F0...portd.F3:
// PORTC.F7 = Direction
int stepH [] = {1,3,2,6,4,12,8,9}; // Half step 0001 0011 0010 0110 0100 1100 1000 1001
int number,direction;
void interrupt(void){ // generation of the phases
if (direction)
{ number++;}
else {number--;}
if (number>7) number=0;
if (number<0) number=7;
PORTD = stepH[number];
delay_us(5); // small delay to set the phase correctly
INTCON.INTF = 0; // clear the interrupt flag
}
void main(void){
number = 0;
direction =1;
TRISB = 0x01;
TRISD = 0x00;
PORTD = 0x00;
INTCON.GIE = 1; //Enable Global Interrupt
INTCON.INTE = 1; //Enable RB0/INT external Interrupt
INTCON.PEIE = 0; //Disable all unmasked peripheral interrupt
OPTION_REG.INTEDG = 1; //Interrupt on rising edge
do {
direction=0;
if (PORTC.F7) direction = 1 ;
PORTD = 0; // disable stepper if no-steps - to save power supply
} while(1);
}