PICkit™ 3 Starter Kit User’s Guide
DS41628B-page 54 2012 Microchip Technology Inc.
The PIC18 can rotate through carry or not. If not, the LSb would simply be loaded into
the MSb. The program needs to use the carry bit to test if it rotated the LED out of the
displayable range, much like in the PIC16. The only difference is now the carry bit
MUST be cleared when it rotates out of the display. If it is not cleared, the program will
light up DS3 as intended, but soon all LEDs will be lit since LATCbits. LATC7 will be
set, and then subsequent rotations will move it down onto the visible range of
<RC3:RC0>.
3.4.7 C Language
3.4.7.1 BOTH
The ‘C’ version is much simpler and easier to understand. The program delays for 500
ms, shifts the LATC register to the right, and then checks if the carry bit in LATC is set.
If so, the program will set RC3 in anticipation of the next rotate.
EXAMPLE 3-17:
It is important to note that the above shift is a logical shift since it is an unsigned register.
The STATUS register is still updated after the shift. The shift in Example 3-17 incorpo-
rates one of the many short-hand notations of ‘C’, as described in Example 3-18.
EXAMPLE 3-18:
__delay_ms(500); //delay 500ms
LATC >> = 1; //shift to the right by 1
if(STATUSbits.C) //when the last LED is lit, restart the pattern
LATCbits.LATC3 = 1;
LATC >> = 1;
This is equivalent as:
LATC = LATC >> 1;
Or rather:
lsrf LATC,F ;shift the LEDs and turn on the next LED to the right