Microchip Technology PICDEM™ Lab Development Board User’s Guide

PICDEM™ Lab
Development Board
User’s Guide
© 2009 Microchip Technology Inc. DS41369A
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 Microchip’s 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 Microchip’s 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.
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 buyer’s 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, Accuron, dsPIC, K
EELOQ, KEELOQ logo, MPLAB, PIC, PICmicro,
PICSTART, rfPIC, SmartShunt and UNI/O are registered trademarks of Microchip Technology Incorporated in the U.S.A. and other countries.
FilterLab, Linear Active Thermistor, MXDEV, MXLAB, SEEVAL, SmartSensor 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, In-Circuit Serial Programming, ICSP, ICEPIC, Mindi, MiWi, MPASM, MPLAB Certified logo, MPLIB, MPLINK, mTouch, PICkit, PICDEM, PICDEM.net, PICtail, PIC
32
logo, PowerCal, PowerInfo, PowerMate, PowerTool, REAL ICE, rfLAB, Select Mode, Total Endurance, 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.
© 2009, Microchip Technology Incorporated, Printed in the U.S.A., All Rights Reserved.
Printed on recycled paper.
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 Company’s quality system processes and procedures are for its PIC devices, Serial EEPROMs, microperipherals, nonvolatile memory and analog products. In addition, Microchip’s quality system for the design and manufacture of development systems is ISO 9001:2000 certified.
®
MCUs and dsPIC® DSCs, KEELOQ
®
code hopping
DS41369A-page ii © 2009 Microchip Technology Inc.
Chapter 1. Overview
1.1 Introduction ..................................................................................................... 5
1.2 Highlights ........................................................................................................ 5
1.3 PICDEM™ Lab Development Kit Contents .................................................... 5
1.4 PICDEM™ Lab Development Board Construction and Layout ...................... 6
1.5 Target Power .................................................................................................. 7
1.6 Connecting the PICkit™ 2 Programmer/Debugger ........................................ 8
1.7 Solderless Prototyping Area Strip Configuration ............................................ 9
Chapter 2. Getting Started
2.1 Introduction ................................................................................................... 11
2.2 Prerequisites ................................................................................................ 11
2.3 The Software Control Loop .......................................................................... 11
2.4 MPLAB
2.5 Installing the Included Lab Files ................................................................... 16
®
IDE Download Instructions ............................................................ 12
PICDEM™LAB DEVELOPMENT
BOARD USER’S GUIDE
Table of Contents
Chapter 3. General Purpose Input/Output Labs
3.1 Introduction ................................................................................................... 17
3.2 General Purpose Input/Output Labs ............................................................. 17
3.3 GPIO Output Labs ........................................................................................ 18
3.3.1 Reference Documentation ......................................................................... 18
3.3.2 Equipment Required for GPIO Output Labs .............................................. 18
3.3.3 PICDEM Lab Development Board Setup for GPIO Output Labs ............... 18
3.3.4 Lab 1: Light LEDs ...................................................................................... 19
3.3.5 Lab 2: Flash LEDs (Delay Loop) ............................................................... 25
3.3.6 Lab 3: Simple Delays Using Timer0 .......................................................... 29
3.3.7 Lab 4: Rotate LEDs ................................................................................... 34
3.4 GPIO Input Labs ........................................................................................... 38
3.4.1 Reference Documentation ......................................................................... 38
3.4.2 Equipment Required for GPIO Input Labs ................................................. 38
3.4.3 PICDEM Lab Development Board Setup for GPIO Input Labs ................. 38
3.4.4 Lab 5: Adding a Push Button ..................................................................... 39
3.4.5 Lab 6: Push Button Interrupt ..................................................................... 48
3.4.6 Lab 7: Push Button Interrupt-on-Change .................................................. 53
3.4.7 Lab 8: Using Weak Pull-Ups ..................................................................... 58
© 2009 Microchip Technology Inc. DS41369A-page iii
PICDEM™Lab Development Board User’s Guide
Chapter 4. Comparator Peripheral Labs
4.1 Introduction ................................................................................................... 61
4.2 Comparator Labs .......................................................................................... 61
4.2.1 Reference Documentation .........................................................................61
4.2.2 Comparator Labs .......................................................................................61
4.2.3 Equipment Required ..................................................................................61
4.2.4 Lab 1: Simple Compare .............................................................................62
4.2.5 Lab 2: Using the Comparator Voltage Reference ......................................64
4.2.6 Lab 3: Higher Resolution Sensor Readings Using a Single Comparator ...68
Chapter 5. Analog-to-Digital Converter Peripheral Labs
5.1 Introduction ................................................................................................... 75
5.2 ADC Labs ..................................................................................................... 75
5.2.1 Reference Documentation .........................................................................75
5.2.2 Equipment Required ..................................................................................75
5.2.3 Lab 1: Simple ADC ....................................................................................76
5.2.4 Lab 2: Audible Temperature Sensor ..........................................................85
Appendix A. Schematic
A.1 PICDEM Lab Development Kit Schematic ................................................... 91
DS41369A-page iv © 2009 Microchip Technology Inc.
PICDEMTM LAB DEVELOPMENT
BOARD USER’S GUIDE
Preface
NOTICE TO CUSTOMERS
All documentation becomes dated, and this manual is no exception. Microchip tools and documentation are constantly evolving to meet customer needs, so some actual dialogs and/or tool descriptions may differ from those in this document. Please refer to our web site (www.microchip.com) to obtain the latest documentation available.
Documents are identified with a “DS” number. This number is located on the bottom of each page, in front of the p age number. The numbering convention for the DS number is “DSXXXXXA”, where “XXXXX” is the document number and “A” is the revision level of the document.
For the most up-to-date information on development tools, see the MPLAB Select the Help menu, and then Topics to open a list of available on-line help files.
INTRODUCTION
®
IDE on-line help.
This chapter contains general information that will be useful to know before using the PICDEM
• Document Layout
• Conventions Used in this Guide
• Recommended Reading
• The Microchip Web Site
• Customer Support
• Document Revision History
DOCUMENT LAYOUT
This document describes how to use the PICDEM TMLab Development Board as a development tool to emulate and debug firmware on a target board. The manual layout is as follows:
Chapter 1. “Overview ”
Chapter 2. “Getti ng Started”
Chapter 3. “Gener al Purpo se Inp ut/Ou tp ut Lab s”
Chapter 4. “Comparator Periphera l Labs”
Chapter 5. “Analog- to -Di gital Converter Peri phe ral Labs”
Appendix A. “Schematic”
TM
Lab Development Board. Items discussed in this chapter include:
© 2009 Microchip Technology Inc. DS41369A-page 1
PICDEMTM Lab Development Board User’s Gu ide
CONVENTIONS USED IN THIS GUIDE
This manual uses the following documentation conventions:
DOCUMENTATION CONVENTIONS
Description Represents Examples
Arial font:
Italic characters Referenced books MPLAB
Emphasized text ...is the only compiler...
Initial caps A window the Output window
A dialog the Settings dialog A menu selection select Enable Programmer
Quotes A field name in a window or
dialog
Underlined, italic text with right angle bracket
Bold characters A dialog button Click OK
N‘Rnnnn A number in verilog format,
Text in angle brackets < > A key on the keyboard Press <Enter>, <F1>
Courier New font:
Plain Courier New Sample source code #define START
Italic Courier New A variable argument file.o, where file can be
Square brackets [ ] Optional arguments mcc18 [options] file
Curly brackets and pipe character: { | }
Ellipses... Replaces repeated text var_name [,
A menu path File>Save
A tab Click the Power tab
where N is the total number of digits, R is the radix and n is a digit.
Filenames autoexec.bat File paths c:\mcc18\h Keywords _asm, _endasm, static Command-line options -Opa+, -Opa- Bit values 0, 1 Constants 0xFF, ‘A’
Choice of mutually exclusive arguments; an OR selection
Represents code supplied by user
“Save project before build”
4‘b0010, 2‘hF1
any valid filename
[options] errorlevel {0|1}
var_name...] void main (void)
{ ... }
®
IDE User’s Guide
DS41369A-page 2 © 2009 Microchip Technology Inc.
RECOMMENDED READING
This user’s guide describes how to use the PICDEM™ Lab Development Kit. Other useful documents are listed below. The following Microchip documents are available and recommended as supplemental reference resources.
Readme Files
For the latest information on using other tools, read the tool-specific Readme files in the Readmes subdirectory of the MPLAB contain update information and known issues that may not be included in this user’s guide.
THE MICROCHIP WEB SITE
Microchip provides online support via our web site at www.microchip.com. This web site is used as a means to make files and information easily available to customers. Accessible by using your favorite Internet browser, the web site contains the following information:
Product Support – Data sheets and errata, application notes and sample
programs, design resources, user’s guides and hardware support documents, latest software releases and archived software
General Technical Support – Frequently Asked Questions (FAQs), technical
support requests, online discussion groups, Microchip consultant program member listing
Business of Microchip – Product selector and ordering guides, latest Microchip
press releases, listing of seminars and events, listings of Microchip sales offices, distributors and factory representatives
Preface
®
IDE installation directory. The Readme files
© 2009 Microchip Technology Inc. DS41369A-page 3
PICDEMTM Lab Development Board User’s Gu ide
CUSTOMER SUPPORT
Users of Microchip products can receive assistance through several channels:
• Distributor or Representative
• Local Sales Office
• Field Application Engineer (FAE)
• Technical Support
Customers should contact their distributor, representative or field application engineer (FAE) for support. Local sales offices are also available to help customers. A listing of sales offices and locations is included in the back of this document.
Technical support is available through the web site at: http://support.microchip.com
DOCUMENT REVISION HISTORY
Revision A (February 2009)
• Initial Release of this Document.
DS41369A-page 4 © 2009 Microchip Technology Inc.

1.1 INTRODUCTION

The PICDEM Lab Development Board supports Microchip’s 8, 14, 18 and 20-pin 8-bit MCUs including accommodation for PIC10F products in the 8-pin PDIP package. Dual-row expansion headers on either side of each socket provide connectivity to all pins on the connected PIC explore a relatively large number of application examples without making permanent modifications to the board. Components permanently mounted to the board are inter­faced using expansion headers to the user’s application via jumper wires. A variable supply voltage allows user’s to supply voltages between 1.2V to 5V to each of the PIC MCU connection sockets.

1.2 HIGHLIGHTS

This chapter discusses:
• PICDEM™ Lab Development Kit Contents
• PICDEM™ Lab Development Board Construction and Layout
• Target Power
• Connecting the PICkit™ 2 Programmer/Debugger
• Solderless Prototyping Area Strip Configuration
PICDEMTM LAB DEVELOPMENT
BOARD USER’S GUIDE

Chapter 1. Overview

®
MCU. A solderless prototyping area allows the user to

1.3 PICDEM™ LAB DEVELOPMENT KIT CONTENTS

The PICDEM™ Development Kit contains the following items:
1. The PICDEM™ Lab Development Board
2. Lab component kit including:
• (1) PIC16F616 DIP
• (1) PIC12F615 DIP
• (4) 10k Resistors
•(4) 1kΩ Resistors
• (8) 470 Resistors
• (4) 220 Resistors
• (4) 100 Resistors
• (1) 10k NTC Thermistor
• (4) Green LEDs
• (4) Red LEDs
• (4) 1N4148 Diodes
•(2) 0.1μF Capacitors
•(2) 1μF Capacitors
•(2) 10μF Capacitors
• (4) Push buttons
• (10) 5” Jumper Wires
• (10) 3” Jumper Wires
© 2009 Microchip Technology Inc. DS41369A-page 5
PICDEMTM Lab Development Board User’s Gu ide
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
• (10) 1” Jumper Wires
• (4) IRFD9020 P-CH MOSFETs
• (4) IRFD010 N-CH MOSFETs
• (2) 100k Potentiometers
3. PICkit™ 2 Programmer/Debugger with USB Cable
4. CD-ROM including:
- “PICDEM™ Lab Development Board User’s Guide and Labs” (DS41369)
- “PIC16F631/677/685/687/689/690 Data Sheet” (DS41262)
- “Introduction to MPLAB MCU Family Lite Mode Compiler Tutorial” (DS41322)
- Timer: Timer0 Tutorial (Part 1) (DS51682)
- Timer: Timer0 Tutorial (Part 2) (DS51702)

1.4 PICDEM™ LAB DEVELOPMENT BOARD CONSTRUCTION AND LAYOUT

The Low Pin Count USB Development Board and populated components are shown in Figure 1-1.

FIGURE 1-1: PICDEM™ LAB DEVELOPMENT BOARD

®
IDE and HI-TECH C® PRO for the PIC10/12/16
DS41369A-page 6 © 2009 Microchip Technology Inc.
1. PICkit™ 2 Programmer/Debugger Connection Headers (J13, J12 and J6)
a) J13 dedicated to PIC b) J12 dedicated to PIC c) J6 dedicated to PIC
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.
®
microcontroller socket U5
®
microcontroller socket U3
®
microcontroller socket U2
Overview
3. 32 kHz Crystal Oscillator (Y1) and Connection Header (J7)
4. V
DD Connect/Disconnect Jumpers (J3, J4, J5)
a) J3 jumper connects/disconnects V
U2
b) J4 jumper connects/disconnects V
U3
c) J5 jumper connects/disconnects V
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 V
DC 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 V
DD 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 V
DD Potentiometer (R1)
Potentiometer used to vary PIC MCU supply voltage from approximately 1.3V to approximately 5V.
DD1 supply to PIC16F690 MCU in socket
DD2 supply to PIC16F819 MCU in socket
DD3 supply to PIC10F206 MCU in socket

1.5 TARGET POWER

The PICDEM™ Lab Development Board can be powered in one of three ways:
1. Using a 9-12 V
(MIcrochip part #AC162039 recommended) Ensure that connect/disconnect jumper J2 is in place.
© 2009 Microchip Technology Inc. DS41369A-page 7
DC power supply connected to connector J1
PICDEMTM Lab Development Board User’s Gu ide
2. Using a 9V battery connected to connector BT1 Ensure that connect/disconnect jumpers J14 are in place.
3. A PICkit™ 2 Programmer/Debugger connected to any one of the three PICkit™ Programmer/Debugger connectors J13, J12 and J6 (recommended for low-power applications only).
Note: When using the PICkit™ 2 Programmer/Debugger as the power source,
the variable V
When using methods 1 or 2, each PIC connect/disconnect jumper that, when in place, enables the positive supply voltage to the respective V
DD pins. The VDD jumpers connect to the following PIC
troller sockets:
DD1 (J3) connects/disconnects supply voltage to the PIC
1. V populating U2.
2. V
DD2 (J4) connects/disconnects supply voltage to the PIC
populating U3.
3. V
DD3 (J5) connects/disconnects supply voltage to the PIC
populating U5.
Using methods 1 or 2 enables the use of the variable V 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.
DD potentiometer (R1) will not vary the supply voltage.
®
microcontroller has an associated
®
®
microcontroller
®
microcontroller
®
microcontroller
DD potentiometer (R1) to control
microcon-

1.6 CONNECTING THE PICkit™ 2 PROGRAMMER/DEBUGGER

The three PIC® microcontrollers populating sockets U5, U3 and U2 have their own PICkit™ Programmer/Debugger (ICSP™) connectors so that each can be pro­grammed or debugged individually. The ICSP™ connect to the following PIC controller sockets:
1. ICSP1 (J6) connects to the PIC
2. ICSP2 (J12) connects to the PIC
3. ICSP3 (J13) connects to the PIC
The PICkit™ Programmer/Debugger connects to the ICSP™ connector as shown in Figure 1-2.
®
microcontroller populating U2.
®
microcontroller populating U3.
®
microcontroller populating U5.
®
micro-
DS41369A-page 8 © 2009 Microchip Technology Inc.
Overview
ICSP™ CONNECTOR
P
o
we
r
T
a
r
g
e
t
B
u
s
y
PICkit™ Programmer/Debugger
Denotes Pin 1
Solderless Prototyping Area
Solderless Prototyping Area
Showing Strip Connections
FIGURE 1-2: CONNECTING THE PICkit™ PROGRAMMER/DEBUGGER TO
AN ICSP™ CONNECTOR
The PICkit™ 2 Programmer/Debugger is then connected to an available USB port on the PC using the included USB cable.

1.7 SOLDERLESS PROTOTYPING AREA STRIP CONFIGURATION

The solderless prototyping area contains a variety of strips under the perforated plastic block. These strips “short” vertical rows of holes together as shown in Figure 1-3.
FIGURE 1-3: SOLDERLESS PROTOTYPING AREA STRIP
CONFIGURATION
© 2009 Microchip Technology Inc. DS41369A-page 9
PICDEMTM Lab Development Board User’s Gu ide
NOTES:
DS41369A-page 10 © 2009 Microchip Technology Inc.
PICDEMTM LAB DEVELOPMENT
main()
Loop Forever
Timing()
Initialize()
Get_Inputs()
Decide()
Do_Outputs()

Chapter 2. Getting Started

2.1 INTRODUCTION

This chapter is intended to prepare the reader to complete the labs in the remaining chapters of this user’s guide.

2.2 PREREQUISITES

The labs contained within this lab manual assumes the user:
1. Has a basic understanding of the C programming language.
2. Understands basic circuit analysis.
3. Has completed or understands the concepts contained within the introductory
tutorial: “Introduction to MPLAB MCU Family Lite Mode Compiler Tutorial” (DS41322B) provided on the
accompanying CD-ROM.

2.3 THE SOFTWARE CONTROL LOOP

BOARD USER ’S GUIDE
®
IDE and HI-TECH C® PRO for the PIC10/12/16
The labs used in this user’s guide implement a software control loop in various configurations but always in the same sequence as shown in Example 2-1.
FIGURE 2-1: MAIN() SOFTWARE CONTROL LOOP FLOWCHART FOR
USED IN LABS
Each block of the software control loop represents a function that organizes tasks into
logical, organized groupings that are called from the main function (main()). Notice
© 2009 Microchip Technology Inc. SD41369A-page 11
the Initialize() is called only once while the remaining functions are executed repeatedly. This method organizes the embedded firmware application into a logic sequence of events:
PICDEMTM Lab Development Board User’s Gu ide
void main(void)
{
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
}
}
1. Initalize():
- Initializes the microcontroller, the peripherals used in the application and any global variables used by multiple functions.
2. Get_Inputs():
- Obtains any input information either on-chip (from internal registers, etc...) or off-chip (pin voltage levels).
3. Decide():
- Makes decisions based on the input information gathered in the previous function to manipulate global variables.
4. Do_Outputs():
- Based on the decisions made in the previous function, this function outputs data onto the pins of the microcontroller or to registers within the device.
5. Timing():
- This function determines how fast the software control loop executes.
Example 2-1 shows a typical main() calling the various functions that make up the software control loop.
EXAMPLE 2-1: TYPICAL SOFTWARE CONTROL LOOP MAIN() USED IN
LABS
An infinity loop will be used by all labs in this user’s guide created using a while loop that repeatedly call the functions within the curly braces as long as there is power to the microcontroller.
Global variables are used wherever needed in lieu of passing variables between functions.

2.4 MPLAB® IDE DOWNLOAD INSTRUCTIONS

SD41369A-page 12 © 2009 Microchip Technology Inc.
The following steps outline how to download the latest version of the MPLAB IDE and HI-TECH C mended that all open programs and applications are closed to expedite the installation process.
®
PRO for the PIC10/12/16 MCU Families compiler. It is strongly recom-
Getting Started
1. Using a PC that is connected to the internet, navigate to the MPLAB® IDE down-
load page at the following url:
www.microchip.com/mplab
This page outlines the MPLAB IDE and also features downloadable plug-ins, User’s 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
proceed with the installation.
6. In the next window, read through the MPLAB IDE License Agreement and ensure
that the I accept the terms of the license agreement radio button is selected. Click Next>
7. In the Setup Type window select the setup type (complete is recommended for
new users) and click Next>
8. In the Choose Destination Location it is recommended to use the default direct
C:\Program Files\Microchip\. Click Next>
9. Accept the Application Maestro License agreement in the next window and click
Next>
to continue.
10. Click Next>
take several minutes to complete).
11. During the installation process, the user will be prompted to install the free
HI-TECH C the user install the compiler at this point. Select Yes to launch the installer. In the
installer window, click Next to continue. (See Figure 2-3.)
Tools x.xx Installation window should now be open. Click Next> to
®
to continue with the installation.
to continue.
to continue.
in the Start Copying Files window to start the installation (this may
®
PRO for the PIC10/12/16 MCU Compiler. It is recommended that
© 2009 Microchip Technology Inc. SD41369A-page 13
PICDEMTM Lab Development Board User’s Gu ide

FIGURE 2-3: HI TECH INSTALLER WINDOW

12. In the next window, accept the terms of the license agreement and click Next to
continue. (See Figure 2-4.)

FIGURE 2-4: HI TECH LICENSE AGREEMENT

13. In the next window, select any components in addition to the HI-TECH C the PIC10/12/16 MCU Family Compiler to install (additional components are not
required to complete the labs in this user's guide) and click Next to continue.
(See Figure 2-5.)
®
Pro for
SD41369A-page 14 © 2009 Microchip Technology Inc.
Getting Started

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 Read quick start gui de now? radio button and click Finish to
proceed. (See Figure 2-7.)
© 2009 Microchip Technology Inc. SD41369A-page 15
PICDEMTM Lab Development Board User’s Gu ide

FIGURE 2-7: HI TECH INSTALL CONFIRMATION

16. The MPLAB and prompt the user to restart the computer before using the software. To begin
using the tools, select the Yes, I want to restart my computer radio button and click Finish to end the installation process and restart the computer.
Following restart, the user will be given the option to view a variety of documentation.
To view a document, simply highlight and click View Selected File.
The MPLAB Compiler are now both installed and ready to use. The user is now ready to complete the labs included in this user’s guide.
Note: A comprehensive introduction to the “HI-TECH C® PRO for the
®
Tools Install Shield Wizard Complete window should soon open
®
IDE and HI-TECH C® PRO for the PIC10/12/16 MCU Family Lite Mode
PIC10/12/16 MCU Family Lite Mode Compiler Tutorial” (DS41322) is
provided on the accompanying CD-ROM.

2.5 INSTALLING THE INCLUDED LAB FILES

The PICDEM™ Lab Development Kit CD-ROM includes a .zip file called PICDEM_Lab.zip. This file provides a location for the user to save any projects created while completing the labs in this user's guide and contains solutions for each lab in a folder labeled solution. To install this folder, simply extract the contents of the .zip file to the C:\ directory.
Note: Lab folders must be installed to the C:\ to be used by the MPLAB IDE.
SD41369A-page 16 © 2009 Microchip Technology Inc.

Chapter 3. General Purpose Input/Output Labs

3.1 INTRODUCTION

The following labs cover some of the fundamental features of the General Purpose Input/Output (GPIO) peripherals available on the PIC16F690. As the name implies, these peripherals are used for general purpose applications that can monitor and control other off-chip devices. Some PIC peripherals on-chip including the PIC16F690 used in the following labs. Therefore, the PORTx naming convention is used. Available ports on the PIC16F690 are:
•PORTA
•PORTB
•PORTC
Reading through the data sheet highlights some of the unique characteristics associ­ated with each port and the reader is encouraged to explore these in greater detail once comfortable with the labs in this user’s guide. The labs will focus on two of the port peripherals: PORTC and PORTA. Labs will be naturally divided into two sections since these are General Purpose Input/Output peripherals:
• Output Labs
• Input Labs
Output labs will introduce the reader to concepts necessary to configuring these periph­erals for output to off-chip devices using applicable registers by lighting 8 LEDs con­nected to the PORTC pins
The Input labs will then add a push button interfacing to one of the PORTA pins to high­light concepts necessary for configuring these peripherals to receive information from off-chip devices. Finally, interrupts will be used to optimize the application for different purposes.
PICDEMTM LAB DEVELOPMENT
BOARD USER’S GUIDE
®
microcontrollers have multiple GPIO

3.2 GENERAL PURPOSE INPUT/OUTPUT LABS

• Output Labs:
- Lab 1: Light LEDs
- Lab 2: Flash LEDs (Delay Loop)
- Lab 3: Simple Delays Using Timer0
- Lab 4: Rotate LEDs
• Input Labs:
- Lab 5: Adding a Push Button
- Lab 6: Push Button Interrupt
- Lab 7: Push Button Interrupt-on-Change
- Lab 8: Using Weak Pull-ups
© 2009 Microchip Technology Inc. DS41369A-page 17
PICDEMTM Lab Development Board User’s Gu ide
U2
1 2 3 4 5 6 7 8 9
10
20 19 18 17 16 15 14 13 12
11
RC0 RC1 RC2
RC3
RC4
RC5
RC6
RC7
J9J8
R8 470
R4 470
R7 470
R6 470
R5 470
R3 470
R2 470
R1 470
LED8 LED7 LED6 LED4 LED3 LED2 LED1LED5
V
SS

3.3 GPIO OUTPUT LABS

3.3.1 Reference Documentation

All documentation is available on the PICDEM™ Lab Development Kit accompanying CD-ROM.
• PIC16F690 Data Sheet (DS41262)
- Section 2.2.2.2: Option Register
- Section 2.2.2.3: Interrupt Control Register INTCON
- Section 4: I/O Ports
- Section 5: Timer0 Module
• Timers: Timer0 Tutorial (Part 1) (DS51628)
• Timers: Timer0 Tutorial (Part 2) (DS51702)
“Introduction to MPLAB
Family Lite Mode Compiler Tutorial” (DS41322)

3.3.2 Equipment Required for GPIO Output Labs

To complete the labs in this section, the following components are required:
1. 8 – Light Emitting Diodes
2. 8 – 470Ω resistors
3. PIC16F690 populating socket U2
4. Assorted jumper wires
®
IDE and HI-TECH C® PRO for the PIC10/12/16 MCU

3.3.3 PICDEM Lab Development Board Setup for GPIO Output Labs

The GPIO output labs will require that the PICDEM Lab Development Board be config­ured as shown in Figure 3-1 using the components listed in the previous section.

FIGURE 3-1: PICDEM LAB SCHEMATIC FOR GPIO OUTPUT LABS

DS41369A-page 18 © 2009 Microchip Technology Inc.
General Purpose Input/Output Labs
main()
Initialize()
Do_Outputs()
Loop Forever
Special care should be observed when connecting the LED jumper wires to the expansion headers surrounding the PIC16F690, as the PORTC pins are not in sequential order. The 470Ω resistors are used to limit the current across the LEDs to manufacturer specifications. Furthermore, the PIC16F690 Data Sheet electrical specifications (see Section 17.0) specify that each port pin should not source/sink more than 25 mA. The maximum output current sourced/sunk by all port pins combined should not exceed 200 mA. The 470Ω resistors keep all source current well within these specifications.

3.3.4 Lab 1: Light LEDs

3.3.4.1 NEW REGISTERS USED IN THIS LAB
To configure the peripherals used in this lab, the following registers are used:
1. PORTC Register: PORTC (Register 4-11 in Section 4 of the PIC16F690 Data
Sheet).
- 8-bit bidirectional port.
2. PORTC Tri-State Register: TRISC (Register 4-12 in Section 4 of the PIC16F690
Data Sheet).
- Configures corresponding bits in PORTC as either input or output.
3. Analog Select Register High and Analog Select Register Low: ANSELH and
ANSEL (Registers 4-4 and 4-3 in Section 4 of the PIC16F690 Data Sheet).
- Configure associated pins for analog or digital input signals.
3.3.4.2 OVERVIEW
This first lab demonstrates how to output data from the PORTC peripheral on the PIC16F690 to its associated pins. LEDs connected to PORTC pins will light when the associated pin is driven high (approx. V (approx. V need to be configured as output using the TRISC register. Also, PORTC pins RC0, RC1, RC2, RC3, RC6 and RC7 are configurable for both analog and digital signals. On start-up, any analog/digital functional pin is defaulted to analog. Therefore, this application will require that these pins be configured as digital by configuring the associated bits in the ANSEL and ANSELH analog select registers.
FIGURE 3-2: MAIN() SOFTWARE CONTROL LOOP FLOWCHART FOR
SS). The port peripherals will all default to input on start-up and will therefore
LAB 1
DD) or turn the LED OFF when driven low
© 2009 Microchip Technology Inc. DS41369A-page 19
PICDEMTM Lab Development Board User’s Gu ide
Figure 3-2 shows the software control loop that will be implemented in this lab. At device power-up, the first functional block called from the main() is Initialize(). This function will initialize the PORTC peripheral as follows:
• Clear the PORTC register data
• Configure the ANSEL and ANSELH bits so that all associated PORTC pins are
digital
• Configure the associated PORTC pins as all output using the TRISC register
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.
The next function called from main() is Do_Outputs(). This function will assign values to the PORTC register that will drive the associated pins high or low to light the LEDs connected.
3.3.4.3 PROCEDURE
The following steps will demonstrate how to create a new project in MPLAB
more in-depth tutorial is provided in the document “Introduction to MPLA B
HI-TECH C
(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>
®
PRO for the PIC10/12/16 MCU Family Lite Mode Compiler Tutorial”
to continue. (See Figure 3-3.)
®
IDE. A
®
IDE and

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.
DS41369A-page 20 © 2009 Microchip Technology Inc.
General Purpose Input/Output Labs

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.
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.
© 2009 Microchip Technology Inc. DS41369A-page 21
PICDEMTM Lab Development Board User’s Gu ide

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
visible, it can be opened by selecting View>Project
resemble Figure 3-8.
®
IDE Workspace should now be open. If the Project window is not
. The Project window should
DS41369A-page 22 © 2009 Microchip Technology Inc.
General Purpose Input/Output Labs
//Clear PORTC to a known state PORTC = 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;//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

FIGURE 3-8: PROJECT WIN DOW

10. Double click on the GPIO_Lab1.c source file in the Project window to open.
11. Copy/paste the code in Example 3-1 into the Initialize() section labeled:
//ADD INITIALIZE CODE HERE
EXAMPLE 3-1: INITIALIZE() CODE FOR LAB 1
© 2009 Microchip Technology Inc. DS41369A-page 23
PICDEMTM Lab Development Board User’s Gu ide
RC0 = 1;//Make RC0 (pin 16) HIGH (approx. Vdd) RC1 = 0;//Make RC1 (pin 15) LOW (approx. Vss) RC2 = 1;//Make RC2 (pin 14) HIGH (approx. Vdd) RC3 = 1;//Make RC3 (pin 7) HIGH (approx. Vdd) RC4 = 0;//Make RC4 (pin 6) LOW (approx. Vss) RC5 = 1;//Make RC5 (pin 5) HIGH (approx. Vdd) RC6 = 0;//Make RC6 (pin 8) LOW (approx. Vss) RC7 = 1;//Make RC7 (pin 9) HIGH (approx. Vdd)
Initialize(); //Initialize the relevant registers
while(1) //Code within curly braces will loop forever {
Do_Outputs(); //Perform any outputs
}
12. Copy/paste the code in Example 3-2 into the Do_Outputs() section labeled: //ADD DO_OUTPUTS CODE HERE
EXAMPLE 3-2: DO_OUTPUT() CODE FOR LAB 1
13. Copy/paste the code in Example 3-3 into the main() section labeled: //ADD MAIN CODE HERE
EXAMPLE 3-3: MAIN() CODE FOR LAB 1
The project is now ready to compile and download to the PIC16F690.
14. Compile the project ensuring no errors.
15. Connect the PICkit™ 2 Programmer/Debugger to an available USB port on the PC and then to the ICSP™ connector ICSP1 (J6) on the PICDEM Lab Develop­ment Board. The PICkit 2 should recognize if a power source is not connected to the PIC16F690 and provide target power.
16. In the MPLAB™ IDE Project Workspace, select
Programmer>Select Programmer>PICkit 2
.
17. The PICkit 2 Programmer/Debugger toolbar should now be visible in the workspace as shown in Figure 3-9.
DS41369A-page 24 © 2009 Microchip Technology Inc.
General Purpose Input/Output Labs
Legend:
1. Program the target device
2. Read target device memories
3. Read the target EEDATA memory
4. Verify the contents of the target device
5. Erase the target device memories
6. Verify that target memories are erased
7. Bring target MCLR
to VDD
8. Bring target MCLR to VIL
9. Re-establish PICkit 2 connection
1 2 3 4 5 6 7 8 9
R8 470
R4 470
R7 470
R6 470
R5 470
R3 470
R2 470
R1 470
LED8 LED7 LED6 LED4 LED3 LED2 LED1LED5
V
SSLED ON LED OFF

FIGURE 3-9: PICkit 2 PROGRAMMER/DEBUGGER TOOLBAR

© 2009 Microchip Technology Inc. DS41369A-page 25
8. Press button1 shown in Figure 3-9 to program the PIC16F690.
3.3.4.4 TESTING THE APPLICATION
Once programmed, the LEDs connected to the individual PORTC pins should now resemble the output shown in Figure 3-10.

FIGURE 3-10: LAB 1 LED OUTPUT

The solution for this project is located in the C:\PICDEM_Lab\GPIO_Labs\GPIO_Lab1\solution directory.

3.3.5 Lab 2: Flash LEDs (Delay Loop)

3.3.5.1 OVERVIEW
This lab implements a software delay to flash the LEDs connected to the PORTC pins on/off in 1 second intervals. As configured, the PIC16F690 executes 1 million instruc­tions per second. At this rate, the software loop execution needs to be slowed down so that the LED flashing is visible to the eye. This is done using a delay routine within the Timing() functional block called from the main() software control loop as shown in Figure 3-11.
Loading...
+ 67 hidden pages