User manual

Table Of Contents
General Purpose Input/Output Labs
© 2009 Microchip Technology Inc. DS41369A-page 35
The Decide() first checks the current value in LED_Output for two specific condi-
tions:
Is the Most Significant bit ‘1’? This means that on the next shift, the contents will
be all ‘0’s.
Is the value currently a ‘0’?
If either condition exists, the function re-initializes LED_Output to set the Least Signif-
icant bit. Otherwise, there will be a period when none of the LEDs are lit.
The shift is implemented in code as follows:
LED_Output <<= 1;
This translates to: LED_Output is equal to the current contents of LED_Output
shifted to the left by 1 bit position”
Conversely, to shift the bit to the right the code would be as follows:
LED_Output >>= 1;
The Do_Outputs() will then assign the contents of the LED_Output variable to the
PORTC register and whichever bit is high will light the connected LED. (See
Figure 3-17.)
FIGURE 3-17: RESULTS OF DO_OUTPUT()
The Initialize() now configures the PIC16F690 peripherals as follows:
•PORTC
- Initialize PORTC so that the 7 Most Significant bits are ‘0’ and the Least
Significant bit is ‘1
- Make all PORTC pins digital output
•Timer0
- Use the internal instruction clock (F
OSC/4) as the TMR0 register clock source
- Increment TMR0 register on low-to-high transition of F
OSC/4
- Assign the prescaler to Timer0 and configure to increment on every 256th
transition of F
OSC/4
Initialize the LED_Output variable to ‘0
Do_Outputs()
assigns
LED_Output to
PORTC
LED_Output variable
10000000
10000000
PORTC
Do_Outputs()
assigns
LED_Output to
PORTC
01000000
01000000
LED_Output variable
PORTC
Decide() shifts contents of
LED_Output Left by 1 bit position
Corresponding LED lights
Corresponding LED lights
First time through main():
Next time through main():
Initialize() determines initial
contents of LED_Output