Hi!

Each of the PORTB pins has a weak internal pull-up
(≈200 µA typical). A single control bit can turn on all the
pull-ups. This is done by clearing the RBPU
(OPTION<7>) bit. The weak pull-up is automatically
turned off when the port pin is configured as an output.
The pull-ups are disabled on Power-on Reset.

OPTION_REG.7 = 0 ' Enable all PORTB pullups
OPTION_REG.7 = 1 ' Disable all PORTB pullups

* * *

To set a pin or port to an output (or input), set its TRIS register.
Setting a TRIS bit to 0 makes its corresponding port pin an output.
Setting a TRIS bit to 1 makes its corresponding port pin an input.

Examples on PORTB:

TRISB = %11111111 'sets all the PORTB pins to inputs.
TRISB = %00000000 'sets all the PORTB pins to outputs.
TRISB = %11110000 'b7,b6,b5,b4=inputs / b3,b2,b1,b0 =outputs
TRISB = %11100000 'b7,b6,b5=inputs / b4,b3,b2,b1,b0 =outputs


Try to find out what happen if you set all the PINs of PORTB
as inputs with TRISB = %11111111 then enable all PORTB pullups
with OPTION_REG.7 = 0 and then you set TRISB = %11100000.
('b7,b6,b5=inputs / b4,b3,b2,b1,b0 =outputs).
Pullups still there on b7,b6,b5? (Source +5 Volts ≈200 µA).

* * *

External interrupt on RB0/INT pin

External interrupt on RB0/INT pin is edge triggered:
either rising if INTEDG bit (OPTION<6>) is set, or
falling, if INTEDG bit is clear. When a valid edge
appears on the RB0/INT pin, the INTF bit
(INTCON<1>) is set. This interrupt can be disabled by
clearing the INTE control bit (INTCON<4>). The INTF
bit must be cleared in software in the interrupt service
routine before re-enabling this interrupt. The RB0/INT
interrupt can wake-up the processor from SLEEP, if the
INTE bit was set prior to going into SLEEP. The status
of the GIE bit decides whether or not the processor
branches to the interrupt vector following wake-up.

OPTION_REG.6 = 0 'Interrupt on falling edge of RB0/INT pin
OPTION_REG.6 = 1 'Interrupt on rising edge of RB0/INT pin
INTCON = %10010000 'Enable INTE
INTCON.1 = 0 'Clear RB0/INT External Interrupt Flag bit

* * *

RB<7:4>, have an interrupt-onchange feature.

Four of PORTB’s pins, RB<7:4>, have an interrupt-onchange
feature. Only pins configured as inputs can
cause this interrupt to occur (i.e., any RB<7:4> pin configured
as an output is excluded from the interrupt-onchange
comparison). The input pins (of RB7:RB4) are
compared with the old value latched on the last read of
PORTB. The “mismatch” outputs of RB7:RB4 are
OR’ed together to generate the RBIF interrupt (flag
latched in INTCON<0>).


INTCON = %10001000 'Enable RBIE
INTCON.0 = 0 'Clear Port Change Interrupt Flag bit

* * *

From your code:

INTCON = %10011000 ' Enable INTE interrupt
(Comment wrong, you enable INTE and also RBIE).

INTCON.1 = 0 ' Clear interrupt flag
(Clear RB0/INT External Interrupt Flag bit).


Best regards,

Luciano