User manual

Table Of Contents
General Purpose Input/Output Labs
© 2009 Microchip Technology Inc. DS41369A-page 37
Changes from the previous lab include PORTC initialization so that all bits are0
except for the Least Significant bit (LSb) and the initialization of the LED_Output
variable.
3. Copy/paste the code in Example 3-13 into the Decide() section labeled:
//ADD DECISION CODE HERE
EXAMPLE 3-13: DECIDE()CODE FOR LAB 4
4. Copy/paste the code in Example 3-14 over the Do_Outputs() code from the
previous lab.
EXAMPLE 3-14: DO_OUTPUTS() CODE FOR LAB 4
This code simply assigns the contents of the LED_Output variable to the PORTC
register.
5. Copy/paste the code in Example 3-15 over the main() code from the previous
lab to incorporate the Decide().
EXAMPLE 3-15: MAIN() CODE FOR LAB 4
Compile the project. There should be no errors.
//First check if LED_Output variable has most significant bit
//set to 1 or if LED_Output variable is all 0's.
//If so, re initialize the LED_Output variable so that the
//least significant bit is set to 1 and all other bits are
//cleared to 0
if((LED_Output == 0b10000000) || (LED_Output == 0b00000000))
LED_Output = 0b00000001;
//If neither of these conditions are true, simply shift
//the LED_Output variable's contents to the Left by 1 bit
//position
else LED_Output <<=1;
//Assign the manipulated contents of the
//LED_Output variable to the PORTC register
PORTC = LED_Output;
Initialize(); //Initialize the relevant registers
while(1)
{
Decide(); //Make any decisions
Do_Outputs(); //Perform any outputs
Timing();//Sets execution rate of the
//Software Control Loop
}