© 2000 Scenix Semiconductor, Inc. All rights reserved. 137 SX User’s Manual Rev. 3.1 www.scenix.com Chapter 4 Clocking, Power Down, and Reset Here is an example of a program segment that configures the RB0, RB1, and RB2 pins to operate as
Multi-Input Wakeup/Interrupt pins, sensitive to falling edges:
mov M,#$0F ;prepare to write port data direction registers mov W,#$07 ;load W with the value 07h mov !RB,W ;configure RB0-RB2 to be inputs mov M,#$0A ;prepare to write WKED_B (edge) register
;W contains the value 07h
mov !RB,W ;configure RB0-RB2 to sense falling edges mov W,#$09 ;value of 09h to be written to MODE register mov M,W ;prepare to access WKPND_B (pending) register mov W,#$00 ;clear W mov !RB,W ;clear all wakeup pending flags mov M,#$0B ;prepare to write WKEN_B (enable) register mov W,#$F8h ;load W with the value F8h mov !RB,W ;enable RB0-RB2 to operate as wakeup inputs To prevent false interrupts, the enabling step (clearing bits in WKEN_B) should be done as the last
step in a sequence of Port B configuration steps.
After this program segment is executed, the device can receive interrupts on the RB0, RB1, and RB2
pins. If the device is put into the power down mode (by executing a “SLEEP” instruction), the device
can then receive wakeup signals on those same pins.
4.4.2 Reading and Writing the Wakeup Pending Bits The interrupt service routine or initialization code can determine which pin received the wakeup signal
by reading the WKPND_B register, as in the following example:
mov M,#$09 ;set MODE register to access WKPND_B mov W,#$00 ;clear W mov !RB,W ;exchange contents of W and WKPND_B When the MODE register is set to provide access to WKPND_B or CMP_B, the instruction “mov
!RB,W” performs an exchange between the contents of W and the port control register, rather than a
simple move. In the example above, the “mov !RB,W” instruction simultaneously loads W with the
current WKPND_B pending flags and clears the WKPND_B register. The program can test the bits in
W to determine  which Port  B pin  caused the wakeup or interrupt event. Clearing the WKPND_B
register is necessary to enable detection of any subsequent wakeup or interrupt events on the Port B
pins.