User manual

Table Of Contents
General Purpose Input/Output Labs
© 2009 Microchip Technology Inc. DS41369A-page 27
The Do_Outputs() changes somewhat from the previous lab by implementing the
XOR operator to toggle the value in each PORTC bit location each time through the
software loop. The XOR operator is implemented in code as follows:
RCx ^= 1;
This translates to: “Make RCx equal to the current value in RCx XOR’d with 1”
When a value is XOR’d with itself, the result is 0’ (i.e., 1 XOR’d with 1 = 0, 0 XOR’d
with 0 = 0). When a value is XOR’d with a value different than itself, the result is ‘1’ (i.e.,
1 XOR’d with 0 = 1). Therefore, each time through the loop PORTC bits will toggle from
1-to-0 or 0-to-1 depending on its current value.
3.3.5.2 PROCEDURE
Using the code developed in the previous lab, make the following changes:
1. Copy/paste the code in Example 3-4 over the Initialize() code from the
previous lab.
EXAMPLE 3-4: INITIALIZE() CODE FOR LAB 2
The only change from the previous lab is that the PORTC bits are all set high to 1.
2. Copy/paste the code in Example 3-5 over the Do_Outputs() code from the
previous lab to accommodate the XOR bit toggle.
Note: The reader may wish to create a new project as per the previous lab called
GPIO_Lab2.mcp
//Set all PORTC bits HIGH (to a known state)
PORTC = 0b11111111;
//Configure PORTC's ANALOG/DIGITAL pins as all Digital
ANS4 = 0;//Associated with RC0
ANS5 = 0;//Associated with RC1
ANS6 = 0;//Associated with RC2
ANS7 = 0;//Associated with RC3
ANS8 = 0;//Associated with RC6
ANS9 = 0;//Associated with RC7
//Configure PORTC pins as all output
//i.e. 1 = Input, 0 = Output
TRISC0 = 0;//Make RC0 (pin 16) output
TRISC1 = 0;//Make RC1 (pin 15) output
TRISC2 = 0;//Make RC2 (pin 14) output
TRISC3 = 0;//Make RC3 (pin 7) output
TRISC4 = 0;//Make RC4 (pin 6) output
TRISC5 = 0;//Make RC5 (pin 5) output
TRISC6 = 0;//Make RC6 (pin 8) output
TRISC7 = 0;//Make RC7 (pin 9) output