bigdogguru
Administrator
- Joined
- Mar 12, 2010
- Messages
- 9,821
- Helped
- 2,350
- Reputation
- 4,694
- Reaction score
- 2,272
- Trophy points
- 1,413
- Location
- Southwest, USA
- Activity points
- 62,393
Actually, RB6/PGC and RB7/PGD can be used as both ICSP for device programming and Digital I/O during runtime, however you cannot use the debugging feature if RB6/PGC and RB7/PGD are used as Digital I/O and it must be disabled by properly configuring the Configuration Register bits.
One of the more straight forward methods of implementing buttons is to use either the External Interrupt of RB0 or Interrupt On Change feature of RB4:RB7. Using this technique allows a button closure to trigger an interrupt service routine (ISR) which can handle the appropriate action depending on which button was pressed/closed.
Reference: PIC16F87XA Datasheet , Section: 4.2 PORTB and the TRISB Register, Page: 44
BigDog
One of the more straight forward methods of implementing buttons is to use either the External Interrupt of RB0 or Interrupt On Change feature of RB4:RB7. Using this technique allows a button closure to trigger an interrupt service routine (ISR) which can handle the appropriate action depending on which button was pressed/closed.
Reference: PIC16F87XA Datasheet , Section: 4.2 PORTB and the TRISB Register, Page: 44
Four of the PORTB pins, RB7:RB4, have an interrupton-
change feature. Only pins configured as inputs can
cause this interrupt to occur (i.e., any RB7:RB4 pin
configured as an output is excluded from the interrupton-
change 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 RB port change
interrupt with flag bit RBIF (INTCON<0>).
This interrupt can wake the device from Sleep. The
user, in the Interrupt Service Routine, can clear the
interrupt in the following manner:
a) Any read or write of PORTB. This will end the
mismatch condition.
b) Clear flag bit RBIF.
A mismatch condition will continue to set flag bit RBIF.
Reading PORTB will end the mismatch condition and
allow flag bit RBIF to be cleared.
The interrupt-on-change feature is recommended for
wake-up on key depression operation and operations
where PORTB is only used for the interrupt-on-change
feature. Polling of PORTB is not recommended while
using the interrupt-on-change feature.
This interrupt-on-mismatch feature, together with software
configurable pull-ups on these four pins, allow
easy interface to a keypad and make it possible for
wake-up on key depression. Refer to the application
note, AN552, “Implementing Wake-up on Key Stroke”
(DS00552).
RB0/INT is an external interrupt input pin and is
configured using the INTEDG bit (OPTION_REG<6>).
RB0/INT is discussed in detail in Section 14.11.1 “INT
Interrupt”.
BigDog