41369B
41369B
41369B
DS41369B
PICDEM Lab
Development Board
Users Guide
DS41369B-page 2 2011 Microchip Technology Inc.
Information contained in this publication regarding device
applications and the like is provided only for your convenience
and may be superseded by updates. It is your responsibility to
ensure that your application meets with your specifications.
MICROCHIP MAKES NO REPRESENTATIONS OR
WARRANTIES OF ANY KIND WHETHER EXPRESS OR
IMPLIED, WRITTEN OR ORAL, STATUTORY OR
OTHERWISE, RELATED TO THE INFORMATION,
INCLUDING BUT NOT LIMITED TO ITS CONDITION,
QUALITY, PERFORMANCE, MERCHANTABILITY OR
FITNESS FOR PURPOSE. Microchip disclaims all liability
arising from this information and its use. Use of Microchip
devices in life support and/or safety applications is entirely at
the buyers risk, and the buyer agrees to defend, indemnify and
hold harmless Microchip from any and all damages, claims,
suits, or expenses resulting from such use. No licenses are
conveyed, implicitly or otherwise, under any Microchip
intellectual property rights.
Trademarks
The Microchip name and logo, the Microchip logo, dsPIC,
KEELOQ, KEELOQ logo, MPLAB, PIC, PICmicro, PICSTART,
PIC
32
logo, rfPIC and UNI/O are registered trademarks of
Microchip Technology Incorporated in the U.S.A. and other
countries.
FilterLab, Hampshire, HI-TECH C, Linear Active Thermistor,
MXDEV, MXLAB, SEEVAL and The Embedded Control
Solutions Company are registered trademarks of Microchip
Technology Incorporated in the U.S.A.
Analog-for-the-Digital Age, Application Maestro, CodeGuard,
dsPICDEM, dsPICDEM.net, dsPICworks, dsSPEAK, ECAN,
ECONOMONITOR, FanSense, HI-TIDE, In-Circuit Serial
Programming, ICSP, Mindi, MiWi, MPASM, MPLAB Certified
logo, MPLIB, MPLINK, mTouch, Omniscient Code
Generation, PICC, PICC-18, PICDEM, PICDEM.net, PICkit,
PICtail, REAL ICE, rfLAB, Select Mode, Total Endurance,
TSHARC, UniWinDriver, WiperLock and ZENA are
trademarks of Microchip Technology Incorporated in the
U.S.A. and other countries.
SQTP is a service mark of Microchip Technology Incorporated
in the U.S.A.
All other trademarks mentioned herein are property of their
respective companies.
2011, Microchip Technology Incorporated, Printed in the
U.S.A., All Rights Reserved.
Printed on recycled paper.
ISBN: 978-1-60932-844-3
Note the following details of the code protection feature on Microchip devices:
Microchip products meet the specification contained in their particular Microchip Data Sheet.
Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the
intended manner and under normal conditions.
There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our
knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchips Data
Sheets. Most likely, the person doing so is engaged in theft of intellectual property.
Microchip is willing to work with the customer who is concerned about the integrity of their code.
Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as unbreakable.
Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our
products. Attempts to break Microchips code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts
allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.
Microchip received ISO/TS-16949:2002 certification for its worldwide
headquarters, design and wafer fabrication facilities in Chandler and
Tempe, Arizona; Gresham, Oregon and design centers in California
and India. The Companys quality system processes and procedures
are for its PIC
MCUs and dsPIC
DSCs, KEELOQ
code hopping
devices, Serial EEPROMs, microperipherals, nonvolatile memory and
analog products. In addition, Microchips quality system for the design
and manufacture of development systems is ISO 9001:2000 certified.
PICDEM
LAB DEVELOPMENT
BOARD USERS GUIDE
2011 Microchip Technology Inc. DS41369B-page 3
Table of Contents
Chapter 1. Overview
1.1 Introduction ..................................................................................................... 9
1.2 Highlights ........................................................................................................ 9
1.3 PICDEM Lab Development Kit Contents .................................................... 9
1.4 PICDEM Lab Development Board Construction and Layout .................... 10
1.5 Target Power ................................................................................................ 11
1.6 Connecting the PICkit 3 Programmer/Debugger ...................................... 12
1.7 Solderless Prototyping Area Strip Configuration .......................................... 13
Chapter 2. Getting Started
2.1 Introduction ................................................................................................... 15
2.2 Prerequisites ................................................................................................ 15
2.3 The Software Control Loop .......................................................................... 15
2.4 MPLAB
microcontroller socket U5
b) J12 dedicated to PIC
microcontroller socket U3
c) J6 dedicated to PIC
microcontroller socket U2
2. PICkit Serial Analyzer Connection Header (J11) and Receptacle (J15)
To use the PICkit Serial Analyzer, connect to appropriate PIC MCU expansion
header using jumper wires from receptacle.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Overview
2011 Microchip Technology Inc. DS41369B-page 11
3. 32 kHz Crystal Oscillator (Y1) and Connection Header (J7)
4. VDD Connect/Disconnect Jumpers (J3, J4, J5)
a) J3 jumper connects/disconnects VDD1 supply to PIC16F690 MCU in socket
U2
b) J4 jumper connects/disconnects VDD2 supply to PIC16F819 MCU in socket
U3
c) J5 jumper connects/disconnects VDD3 supply to PIC10F206 MCU in socket
U5
5. Battery Clip Connection (BT1) for 9V Battery and Jumpers (J14)
J14 jumpers connect/disconnect battery terminals for use in future lab on battery
chargers.
6. 9 VDC Supply Connector (J1) and Connect/Disconnect Jumper (J2)
7. Power ON Switch (SW1)
8. 8-Pin PDIP PIC10F MCU Socket (U5) and Bilateral Dual-Row Expansion
Headers (J10 and J18)
Dual-row expansion headers provide connectivity to each pin on the PIC10F206
MCU populating socket U5.
9. 5V Brushed DC Motor
10. 18-Pin PDIP PIC MCU Socket (U3) and Bilateral Dual-Row Expansion Head-
ers (J17 and J16)
Dual-row expansion headers provide connectivity to each pin on the PIC16F819
MCU populating socket U3.
11. 8, 14, 20-Pin PDIP PIC MCU Socket (U2) and Bilateral Dual-Row Expansion
Headers (J8 and J9)
Dual-row expansion headers provide connectivity to each pin on the PIC16F690
MCU populating socket U2.
12. Solderless Prototyping Area
13. Bilateral Dual-Row Supply Headers (J22 and J23)
Provide both VDD and VSS connectivity bilaterally to the solderless prototyping
area.
14. 0.2 Watt, 8-Ohm Speaker (LS1) with Connection Header (J19)
J19 connector used to connect speaker LS1 to user application using jumper
wires.
15. Battery Positive (CP+) and Negative (CP-) Connection Header (J26)
Provides connectivity of positive and negative battery terminals to the user appli-
cation using jumper wires.
16. Variable VDD Potentiometer (R1)
Potentiometer used to vary PIC MCU supply voltage from approximately 1.3V to
approximately 5V.
1.5 TARGET POWER
The PICDEM Lab Development Board can be powered in one of three ways:
1. Using a 9-12 VDC power supply connected to connector J1
(Microchip part #AC162039 recommended)
Ensure that connect/disconnect jumper J2 is in place.
PICDEM
TM
Lab Development Board Users Guide
DS41369B-page 12 2011 Microchip Technology Inc.
2. Using a 9V battery connected to connector BT1
Ensure that connect/disconnect jumpers J14 are in place.
3. A PICkit 3 Programmer/Debugger connected to any one of the three PICkit
Programmer/Debugger connectors J13, J12 and J6 (recommended for
low-power applications only).
When using methods 1 or 2, each PIC
microcon-
troller sockets:
1. VDD1 (J3) connects/disconnects supply voltage to the PIC
microcontroller
populating U2.
2. VDD2 (J4) connects/disconnects supply voltage to the PIC
microcontroller
populating U3.
3. VDD3 (J5) connects/disconnects supply voltage to the PIC
microcontroller
populating U5.
Using methods 1 or 2 enables the use of the variable VDD potentiometer (R1) to control
supply voltages from approximately 1.3 to 5V. Rotating the potentiometer clockwise will
raise the supply voltage while rotating the potentiometer counterclockwise will
decrease the supply voltage.
1.6 CONNECTING THE PICKIT 3 PROGRAMMER/DEBUGGER
The three PIC
micro-
controller sockets:
1. ICSP1 (J6) connects to the PIC
IDE down-
load page at the following url:
www.microchip.com/mplab
This page outlines the MPLAB IDE and also features downloadable plug-ins, Users
Guides and other useful information.
2. Scroll down to the Downloads section of the page and select the latest full
release zip file for MPLAB IDE vx.xx. (See Figure 2-2.)
FIGURE 2-2: MPLAB ZIP FILE
3. When prompted, open the .zip file and extract all contents to a new folder named
something meaningful such as MPLAB created in a directory such as Desktop
or another location easily accessible.
4. Once all files are extracted, navigate to the folder created and double click on the
Install_MPLAB_vxxx.exe file to start the installation process.
5. The MPLAB
Pro for
the PIC10/12/16 MCU Family Compiler to install (additional components are not
required to complete the labs in this users guide) and click Next to continue.
(See Figure 2-5.)
Getting Started
2011 Microchip Technology Inc. DS41369B-page 19
FIGURE 2-5: HI TECH COMPONENTS
14. In the next window, choose the language of preference, select the Add to
environment path radio button and click Next to continue. (See Figure 2-6.)
FIGURE 2-6: HI TECH LANGUAGE PREFERENCES
The installation process will now begin.
15. Once the installation is complete, a confirmation window will open. Select or
de-select the View the compiler release notes radio button and click Finish to
proceed. (See Figure 2-7.)
PICDEM
TM
Lab Development Board Users Guide
DS41369B-page 20 2011 Microchip Technology Inc.
FIGURE 2-7: HI TECH INSTALL CONFIRMATION
16. The MPLAB
IDE. A
more in-depth tutorial is provided in the document Introduction to MPLAB
IDE and
HI-TECH C
PRO for the PIC10/12/16 MCU Family Lite Mode Compiler Tutorial
(DS41322) included on the accompanying CD-ROM.
1. Open MPLAB IDE by selecting Start>Microchip>MPLAB IDE vX.XX>MPLAB
IDE.
2. In the MPLAB IDE toolbar, select Project>Project Wizard....
3. The Welcome dialog box should now be open. Select Next> to proceed.
4. In the Step One: window, select the PIC16F690 from the Device: drop-down
menu and select Next> to continue. (See Figure 3-3.)
FIGURE 3-3: STEP ONE
5. In the Step Two: window, select the HI TECH Universal ToolSuite from the Active
Toolsuite drop down menu. The window should now resemble Figure 3-4.
Note: The PORT register should always be initialized to a known value before
configuring the associated TRIS bit. This avoids unexpected voltage levels
on the associated pins since at start-up port bit values are unknown.
General Purpose Input/Output Labs
2011 Microchip Technology Inc. DS41369B-page 25
FIGURE 3-4: STEP TWO
6. In the Step Three: window, use the Browse button and navigate to a new folder
on the C:\ drive to store this project. Alternately, the reader may wish to use the
C:\PICDEM_Lab\GPIO_Labs\GPIO_Lab1 folder created earlier. (See
Figure 3-5.)
FIGURE 3-5: STEP THREE
7. In the Step Four: files are added to the project. A Lab_Template.c file has
been provided in the C:\PICDEM_Lab\Lab_Template.c directory that can be
used as the basis for all labs in this manual. To use the Lab_Template.c file,
select it from the right menu and click the Add>> button. Click on the large letter
A that appears next to the added file in the right window until it becomes a C.
This indicates that a copy of the Lab_Template.c will be included in the project
directory. Otherwise, changes made to the file during the course of the lab will
alter the original file.
PICDEM
TM
Lab Development Board Users Guide
DS41369B-page 26 2011 Microchip Technology Inc.
Finally, rename the Lab_Template.c file in the right window to GPIO_Lab1.c by
clicking on it three times to enable editing the name. The Step Four: window should
now resemble Figure 3-6. Click Next to continue.
FIGURE 3-6: STEP FOUR
8. Finally, the Summary window should appear showing the selected device, the
tool suite and the new project file name. Click Finish to exit the Project Wizard.
FIGURE 3-7: SUMMARY
9. The MPLAB
Compiler.
PICDEM
TM
Lab Development Board Users Guide
DS41369B-page 56 2011 Microchip Technology Inc.
EXAMPLE 3-24: INITIALIZE() CODE FOR GPIO LAB 6
It should be noted that the Global Interrupt Enable bit (GIE) is set last in the
Example 3-24. This ensures that interrupts will not occur during the Initialize(),
having adverse consequences on code operation.
//Clear PORTC to a known state
//Set the least significant bit to 1 so that it can be
//shifted through
PORTC = 0b00000001;
//Clear the PORTA register to a known state
PORTA = 0b00000000;
//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;//Associated with RC0
TRISC1 = 0;//Associated with RC1
TRISC2 = 0;//Associated with RC2
TRISC3 = 0;//Associated with RC3
TRISC4 = 0;//Associated with RC4
TRISC5 = 0;//Associated with RC5
TRISC6 = 0;//Associated with RC6
TRISC7 = 0;//Associated with RC7
//Configure PORTA bit RA0 as Digital input
ANS2 = 0;
TRISA2 = 1;
//Configure Timer0 to overflow every 5mS
T0CS = 0; //Select FOSC/4 as Timer0 clock source
T0SE = 0; //Increment TMR0 on rising clock edge
PSA = 0; //Assign prescaler to Timer0
//Select a 1:32 prescaler
PS0 = 0;
PS1 = 0;
PS2 = 1;
//Initialize the direction flag to shift bits from
//right-to-left
//(i.e. 0 = Shift PORTC bits from right-to-left
// 1 = Shift PORTC bits from left-to-right
direction = 0;
//Initialize LED_Output to all zeros
LED_Output = 0b00000000;
//Configure for external interrupts on RA2
INTEDG = 0; //Interrupt to occur on High-to-LOW
//transition of RA2 voltage
INTE = 1; //Enable the external interrupt
INTF = 0; //Clear the external interrupt flag
GIE = 1;//Enable interrupt capability on the
//PIC16F690 ***ALWAYS DONE LAST*****
General Purpose Input/Output Labs
2011 Microchip Technology Inc. DS41369B-page 57
3. Copy/paste the code in Example 3-25 into the main() over the code from the
previous lab to remove the Get_Inputs().
EXAMPLE 3-25: MAIN() CODE FOR GPIO LAB 6
4. The remaining code remains unchanged from the previous lab. Compile the
project. There should be no errors.
3.4.5.4 TESTING THE APPLICATION
Program the PIC16F690. The application should behave as it did in the previous lab.
Only this time, the change in LED flashing direction should now be more responsive to
push button presses due to the interrupt added.
The solution for this project is located in the
C:\PICDEM_Lab\GPIO_Labs\GPIO_Lab6\solution directory.
3.4.6 Lab 7: Push Button Interrupt-on-Change
3.4.6.1 NEW REGISTERS USED IN THIS LAB
To configure the peripherals used in this lab, the following registers are used:
1. Interrupt-on-Change PORTA Register: IOCA (Register 4-6 in Section 4 of the
PIC16F690 Data Sheet).
- Configures PORTA associated pins that will generate an interrupt when a
change in voltage level is detected.
2. Interrupt Control Register: INTCON (Register 2-3 in Section 2 of the PIC16F690
Data Sheet)
- Enable interrupt functionality on the PIC16F690.
- Enables PORTA/PORTB change interrupts.
- Contains a flag that indicates that a PORTA or PORTB change interrupt has
occurred.
3.4.6.2 OVERVIEW
This lab adds a different kind of interrupt associated with the General Purpose
Input/Output peripheral called interrupt-on-change. Rather than simply interrupting the
CPU on a single edge transition on the RA2 pin, an interrupt will now occur on any edge
transition. Therefore, when the push button is pressed and/or released, an interrupt will
occur. This lab will use these concepts to shift the flashing LEDs from left-to-right while
the push button is pressed and from right-to-left when the push button is released.
Each PORTA and PORTB pin is individually configurable as an interrupt-on-change
pin. Control bits in the Interrupt-on-Change PORTA register (IOCA) enable or disable
the interrupt function for each pin.
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
}
PICDEM
TM
Lab Development Board Users Guide
DS41369B-page 58 2011 Microchip Technology Inc.
The INTCON register is needed as well to implement the interrupt-on-change feature.
Again the GIE bit needs to be set to enable any interrupts used on the microcontroller.
To configure for an interrupt-on-change, the PORTA/PORTB Change Interrupt Enable
bit (RABIE) must be set along with the individual enable bits in the IOCA register. On
an interrupt-on-change for configured pins, the PORTA/PORTB Change Interrupt Flag
bit (RABIF) will be set. To detect a logic change on a port pin, the firmware needs to
know what has changed. Therefore, PORTA must be read before an
interrupt-on-change can occur. Reading PORTA retains, or latches, the current value
on the RA2 pin for later reference. In the event that the signal on the RA2 pin changes
and a mismatch with the reference value occurs, an interrupt will result.
The main() software flowchart for this lab remains the same as that in Figure 3-24 of
the previous lab. The Interrupt Service Routine changes since it now must determine
whether the interrupt occurred due to a high-to-low or low-to-high transition on pin RA2.
The ISR flowchart is shown in Figure 3-25.
FIGURE 3-25: PB_PRESSISR FLOWCHART FOR LAB 7
pb_pressISR()
RABIE and RABIF
bits set
?
RETURN
Clear RABIF flag
YES
RA2 pin = 0
?
direction = 1
Delay for 5mS
NO
RA2 pin = 0
?
RA2 pin = 1
?
Delay for 5mS
RA2 pin = 1
?
direction = 1
Read PORTA
YES
YES
NO
NO
NO
General Purpose Input/Output Labs
2011 Microchip Technology Inc. DS41369B-page 59
The PB_PressISR() now checks to see if the voltage level on RA2 has changed
state from a 1-to-0 or from 0-to-1. Each condition will change the direction that the
LEDs flash sequentially. Note that the direction bit toggle used in previous labs has
been replaced by assigning either a 1 for the left-to-right direction or 0 for the
right-to-left direction. As discussed earlier, the PORTA register must be read before the
first interrupt can occur and at the end of each subsequent ISR execution to ensure that
the microcontroller has an up-to-date reference to measure the current state of the RA2
pin.
The Initialize() for this lab configures the peripherals and interrupts as follows:
PORTC
- Clears PORTC
- Configures all pins as digital output
PORTA
- Clears PORTA
- Configures RA2 as a digital input
Timer0
- Uses the FOSC/4 as clock source
- Increment TMR0 on rising FOSC/4 clock edge
- Use Prescaler at 1:32
Global Variables
- Initialize direction to 0
- Initialize LED_Output to 0
Interrupt
- Enable RA2 Interrupt-on-Change
- Enable change interrupts in INTCON by setting the RABIE bit
- Clear the RABIF change interrupt flag in INTCON
- Enable Global Interrupts by setting GIE
- Read PORTA to latch current value on RA2 for reference
3.4.6.3 PROCEDURE
Using the firmware developed in the previous lab, make the following changes:
1. Copy/paste the code in Example 3-26 into the PB_PressISR() over the code
from the previous lab.
PICDEM
TM
Lab Development Board Users Guide
DS41369B-page 60 2011 Microchip Technology Inc.
EXAMPLE 3-26: PB_PRESSISR() CODE FOR GPIO LAB 7
2. Copy/paste the code in Example 3-27 into the Initialize() over the code
from the previous lab.
//First, check if the interrupt occurred as a result of an
//RA2 change interrupt. If so, clear the RABIF flag so
//that subsequent interrupts can occur
if(RABIE && RABIF) RABIF = 0;
//Check the push button connected to RA0 pin. If 0, then a
//push button press is indicated
if(RA2 == 0)
{
//Delay for 5mS to filter switch bounce
Delay_5mS();
//if RA2 is still 0 then change the direction flag
if (RA2 == 0) direction = 1;
}
//Check the push button connected to RA0 pin. If 1, then a
//push button release is indicated
if(RA2 == 1)
{
//Delay for 5mS to filter switch bounce
Delay_5mS();
//if RA2 is still 1 then change the direction flag
if (RA2 == 1) direction = 0;
}
//Otherwise, keep the direction bit the same as it was
else direction = direction;
//Read PORTA to latch RA2 value for the next interrupt
PORTA = PORTA;
General Purpose Input/Output Labs
2011 Microchip Technology Inc. DS41369B-page 61
EXAMPLE 3-27: INITIALIZE() CODE FOR GPIO LAB 7
//Clear PORTC to a known state
//Set the least significant bit to 1 so that it can be
//shifted through
PORTC = 0b00000001;
//Clear the PORTA register to a known state
PORTA = 0b00000000;
//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;//Associated with RC0
TRISC1 = 0;//Associated with RC1
TRISC2 = 0;//Associated with RC2
TRISC3 = 0;//Associated with RC3
TRISC4 = 0;//Associated with RC4
TRISC5 = 0;//Associated with RC5
TRISC6 = 0;//Associated with RC6
TRISC7 = 0;//Associated with RC7
//Configure PORTA bit RA0 as Digital input
ANS2 = 0;
TRISA2 = 1;
//Configure Timer0 to overflow every 5mS
T0CS = 0; //Select FOSC/4 as Timer0 clock source
T0SE = 0; //Increment TMR0 on rising clock edge
PSA = 0; //Assign prescaler to Timer0
//Select a 1:32 prescaler
PS0 = 0;
PS1 = 0;
PS2 = 1;
//Initialize the direction flag to shift bits from right-to-left
//(i.e. 0 = Shift PORTC bits from right-to-left
// 1 = Shift PORTC bits from left-to-right
direction = 0;
//Initialize LED_Output to all zeros
LED_Output = 0b00000000;
//Configure for RA2 Interrupt-On-Change
IOCA2 = 1; //Enable RA2 interrupt-on-change
RABIE = 1; //Enable change interrupts
RABIF = 0; //Clear the change interrupt flag
GIE = 1;//Enable interrupt capability on the
//PIC16F690 ***ALWAYS DONE LAST*****
//Read PORTA to latch the current RA2 voltage level
PORTA = PORTA;
PICDEM
TM
Lab Development Board Users Guide
DS41369B-page 62 2011 Microchip Technology Inc.
3. All remaining code from the previous lab is unchanged. Compile the project.
There should be no errors.
3.4.6.4 TESTING THE APPLICATION
Program the PIC16F690. The LEDs connected to PORTC should now flash sequen-
tially from left-to-right when the push button is released and flash from right-to-left when
the push button is pressed.
The solution for this project is located in the
C:\PICDEM_Lab\GPIO_Labs\GPIO_Lab7\solution directory.
3.4.7 Lab 8: Using Weak Pull-Ups
3.4.7.1 NEW REGISTERS USED IN THIS LAB
To configure the peripherals used in this lab, the following registers are used:
1. OPTION Register: OPTION (Register 2-2 in Section 2 of the PIC16F690 Data
Sheet)
- Enables PORTA/PORTB weak pull-ups to be used on the PIC16F690.
2. PORTA Weak Pull-Up Register: WPUA (Register 4-5 in Section 4 of the
PIC16F690 Data Sheet)
- Selects which PORTA pins will have weak pull-ups enabled.
3.4.7.2 OVERVIEW
This lab expands on the previous lab by adding weak pull-ups to remove the 10 K
used previously to tie RA2 pin to VDD. Each of the PORTA pins (except RA3) and
PORTB pins, has an individually configurable internal weak pull-up. Essentially, these
weak pull-ups perform the same task as the resistor connected to the RA2 pin and push
button as shown in Figure 3-12 only internal to the microcontroller. This feature can be
used to decrease component counts in the circuit.
Clearing the PORTA/PORTB Pull-up Enable bit, RABPU, in the OPTION register will
enable weak pull-ups on any PORTA pin selected using the Weak Pull-Up PORTA
register (WPUA).
The only change needed to the PICDEM Lab Development Board Schematic shown in
Figure 3-18 is to remove the 10 K resistor connected to both the push button and pin
RA2.
The Initialize() is all that needs to be changed in firmware by adding the following
configurations:
Select RA2 to have a weak pull-up by setting the Weak Pull-Up Register bit
WPUA2 in the WPUA: PORTA Register.
Enable the PORTA/PORTB Pull-up Enable bit (RABPU) in the OPTION register
by clearing it.
3.4.7.3 PROCEDURE
Using the firmware developed in the previous lab, make the following changes:
1. Copy/paste the code in Example 3-28 into the Initialize() over the code
from the previous lab.
General Purpose Input/Output Labs
2011 Microchip Technology Inc. DS41369B-page 63
EXAMPLE 3-28: INITIALIZE() CODE FOR GPIO LAB 8
//Clear PORTC to a known state
//Set the least significant bit to 1 so that it can be
//shifted through
PORTC = 0b00000001;
//Clear the PORTA register to a known state
PORTA = 0b00000000;
//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;//Associated with RC0
TRISC1 = 0;//Associated with RC1
TRISC2 = 0;//Associated with RC2
TRISC3 = 0;//Associated with RC3
TRISC4 = 0;//Associated with RC4
TRISC5 = 0;//Associated with RC5
TRISC6 = 0;//Associated with RC6
TRISC7 = 0;//Associated with RC7
//Configure PORTA bit RA0 as Digital input
ANS2 = 0;
TRISA2 = 1;
//Enable Weak Pull-ups on RA2
WPUA2 = 1;
RABPU = 0; //Enable PORTA/PORTB Pull-ups
//Configure Timer0 to overflow every 5mS
T0CS = 0; //Select FOSC/4 as Timer0 clock source
T0SE = 0; //Increment TMR0 on rising clock edge
PSA = 0; //Assign prescaler to Timer0
//Select a 1:32 prescaler
PS0 = 0;
PS1 = 0;
PS2 = 1;
//Initialize the direction flag to shift bits from right-to-left
//(i.e. 0 = Shift PORTC bits from right-to-left
// 1 = Shift PORTC bits from left-to-right
direction = 0;
//Initialize LED_Output to all zeros
LED_Output = 0b00000000;
//Configure for RA2 Interrupt-On-Change
IOCA2 = 1; //Enable RA2 interrupt-on-change
RABIE = 1; //Enable change interrupts
RABIF = 0; //Clear the change interrupt flag
GIE = 1;//Enable interrupt capability on the
//PIC16F690 ***ALWAYS DONE LAST*****
//Read PORTA to latch the current RA2 voltage level
PORTA = PORTA;
PICDEM
TM
Lab Development Board Users Guide
DS41369B-page 64 2011 Microchip Technology Inc.
3.4.7.4 TESTING THE APPLICATION
Program the PIC16F690. The application should operate exactly as it did in the previ-
ous lab. Only this time with the absence of the 10 K pull-up resistor.
The solution for this project is located in the
C:\PICDEM_Lab\GPIO_Labs\GPIO_Lab8\solution directory.
PICDEM
TM
LAB DEVELOPMENT
BOARD USERS GUIDE
2011 Microchip Technology Inc. DS41369B-page 65
Chapter 4. Comparator Peripheral Labs
4.1 INTRODUCTION
The following labs cover some of the fundamental features of the Comparator 1
peripheral found on the PIC16F690 including some unique applications. These
peripherals are very useful mixed signal building blocks as they provide analog
functionality independent of program execution. The labs in this section will
demonstrate this functionality, then introduce intelligence to implement a relatively high
resolution temperature sensor measurement application.
4.2 COMPARATOR LABS
4.2.1 Reference Documentation
All documentation is available on the PICDEM Lab Development Kit accompanying
CD-ROM:
PIC16F690 Data Sheet (DS41262)
- Section 4.0: I/O Ports
- Section 5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41369B-page 96 2011 Microchip Technology Inc.
AMERICAS
Corporate Office
2355 West Chandler Blvd.
Chandler, AZ 85224-6199
Tel: 480-792-7200
Fax: 480-792-7277
Technical Support:
http://support.microchip.com
Web Address:
www.microchip.com
Atlanta
Duluth, GA
Tel: 678-957-9614
Fax: 678-957-1455
Boston
Westborough, MA
Tel: 774-760-0087
Fax: 774-760-0088
Chicago
Itasca, IL
Tel: 630-285-0071
Fax: 630-285-0075
Cleveland
Independence, OH
Tel: 216-447-0464
Fax: 216-447-0643
Dallas
Addison, TX
Tel: 972-818-7423
Fax: 972-818-2924
Detroit
Farmington Hills, MI
Tel: 248-538-2250
Fax: 248-538-2260
Kokomo
Kokomo, IN
Tel: 765-864-8360
Fax: 765-864-8387
Los Angeles
Mission Viejo, CA
Tel: 949-462-9523
Fax: 949-462-9608
Santa Clara
Santa Clara, CA
Tel: 408-961-6444
Fax: 408-961-6445
Toronto
Mississauga, Ontario,
Canada
Tel: 905-673-0699
Fax: 905-673-6509
ASIA/PACIFIC
Asia Pacific Office
Suites 3707-14, 37th Floor
Tower 6, The Gateway
Harbour City, Kowloon
Hong Kong
Tel: 852-2401-1200
Fax: 852-2401-3431
Australia - Sydney
Tel: 61-2-9868-6733
Fax: 61-2-9868-6755
China - Beijing
Tel: 86-10-8528-2100
Fax: 86-10-8528-2104
China - Chengdu
Tel: 86-28-8665-5511
Fax: 86-28-8665-7889
China - Chongqing
Tel: 86-23-8980-9588
Fax: 86-23-8980-9500
China - Hong Kong SAR
Tel: 852-2401-1200
Fax: 852-2401-3431
China - Nanjing
Tel: 86-25-8473-2460
Fax: 86-25-8473-2470
China - Qingdao
Tel: 86-532-8502-7355
Fax: 86-532-8502-7205
China - Shanghai
Tel: 86-21-5407-5533
Fax: 86-21-5407-5066
China - Shenyang
Tel: 86-24-2334-2829
Fax: 86-24-2334-2393
China - Shenzhen
Tel: 86-755-8203-2660
Fax: 86-755-8203-1760
China - Wuhan
Tel: 86-27-5980-5300
Fax: 86-27-5980-5118
China - Xian
Tel: 86-29-8833-7252
Fax: 86-29-8833-7256
China - Xiamen
Tel: 86-592-2388138
Fax: 86-592-2388130
China - Zhuhai
Tel: 86-756-3210040
Fax: 86-756-3210049
ASIA/PACIFIC
India - Bangalore
Tel: 91-80-3090-4444
Fax: 91-80-3090-4123
India - New Delhi
Tel: 91-11-4160-8631
Fax: 91-11-4160-8632
India - Pune
Tel: 91-20-2566-1512
Fax: 91-20-2566-1513
Japan - Yokohama
Tel: 81-45-471- 6166
Fax: 81-45-471-6122
Korea - Daegu
Tel: 82-53-744-4301
Fax: 82-53-744-4302
Korea - Seoul
Tel: 82-2-554-7200
Fax: 82-2-558-5932 or
82-2-558-5934
Malaysia - Kuala Lumpur
Tel: 60-3-6201-9857
Fax: 60-3-6201-9859
Malaysia - Penang
Tel: 60-4-227-8870
Fax: 60-4-227-4068
Philippines - Manila
Tel: 63-2-634-9065
Fax: 63-2-634-9069
Singapore
Tel: 65-6334-8870
Fax: 65-6334-8850
Taiwan - Hsin Chu
Tel: 886-3-6578-300
Fax: 886-3-6578-370
Taiwan - Kaohsiung
Tel: 886-7-213-7830
Fax: 886-7-330-9305
Taiwan - Taipei
Tel: 886-2-2500-6610
Fax: 886-2-2508-0102
Thailand - Bangkok
Tel: 66-2-694-1351
Fax: 66-2-694-1350
EUROPE
Austria - Wels
Tel: 43-7242-2244-39
Fax: 43-7242-2244-393
Denmark - Copenhagen
Tel: 45-4450-2828
Fax: 45-4485-2829
France - Paris
Tel: 33-1-69-53-63-20
Fax: 33-1-69-30-90-79
Germany - Munich
Tel: 49-89-627-144-0
Fax: 49-89-627-144-44
Italy - Milan
Tel: 39-0331-742611
Fax: 39-0331-466781
Netherlands - Drunen
Tel: 31-416-690399
Fax: 31-416-690340
Spain - Madrid
Tel: 34-91-708-08-90
Fax: 34-91-708-08-91
UK - Wokingham
Tel: 44-118-921-5869
Fax: 44-118-921-5820
Worldwide Sales and Service
08/04/10