PICkit™ 3 Starter Kit User’s Guide
DS41628B-page 66 2012 Microchip Technology Inc.
The debounce routine is more in-depth in this lesson because we need to keep in mind
of the scenario of the switch being held down for long periods of time. If SW1 is held
down, the LEDs would change direction rapidly, making the display look like it is out of
control. The above flowchart will only change direction on the first indication of a solid
press and then ignore the switch until it is released and pushed again. The switch must
be pressed for at least the time it takes for the program to check the switch in its loop.
Since the PIC MCU is running at 500 kHz, this will seem instantaneous.
3.8.4 New Registers
None.
3.8.5 New Instructions
3.8.5.1 PIC18
3.8.5.1.1 rlncf
This rotates bits to the left without using the carry bit. The LSb simply becomes the
previous MSb. This is usually referred to as a circular shift.
FIGURE 3-7: ROTATE LEFT WITHOUT CARRY
3.8.6 Assembly
3.8.6.1 ENHANCED MID-RANGE
EXAMPLE 3-30:
Instead of using the carry bit to check if the LEDs are out of display range, the latch is
shifted to the left and LATC4 is checked. LATC4 is not connected to anything and if this
is ever set, it means that DS4 was just lit and now DS1 needs to be lit to repeat the
pattern. The PIC18 version is similar, but instead uses rlncf instead of lslf.
3.8.6.2 PIC18
The PIC18 always has to make sure that the carry bit is cleared once it is checked,
otherwise more than one LED may become lit.
TABLE 3-27:
Instruction English Purpose
RLNCF Rotate left with no carry Shift bits to the left
76543210
00010111
00101110
MSb
LSb
RotateRight:
lslf LATC, f ;logical shift left
btfsc LATC, 4 ;did it rotate out of the LED display?
bsf LATC, 0 ;yes, put in bit 0
bra MainLoop