User manual

Table Of Contents
PICDEM
TM
Lab Development Board User’s Guide
DS41369A-page 46 © 2009 Microchip Technology Inc.
3. Copy/paste the code in Example 3-19 into the Get_Inputs() at the section
labeled:
//ADD GET_INPUTS CODE HERE
EXAMPLE 3-19: GET_INPUTS() CODE FOR GPIO LAB 5
4. Copy/paste the code in Example 3-20 into the Decide() over the code from the
previous lab.
EXAMPLE 3-20: DECIDE() CODE FOR GPIO LAB 5
//Check for a push button press (i.e. RA2 = 0)
if (RA2 == 0)
{
Delay_5mS(); //Delay to debounce
//Check if push button is still pressed
if(RA2 == 0) direction ^= 1; //If so, toggle the
//direction bit
}
//Otherwise keep direction the same as it was
else direction = direction;
if(direction == 0)
{
//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 most significant bit is set to 1 and all other
//bits are 0
if((LED_Output == 0b00000001) || (LED_Output ==
0b00000000)) LED_Output = 0b10000000;
//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;
}
else
{
//First check if LED_Output variable has the least
//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 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 Right by 1
//bit position
else LED_Output <<=1;
}