Timers of PIC microcontroller How to generate delay

Timers of PIC microcontroller How to generate delay

PIC microcontrollers are a very useful and versatile tool for use in many electronic projects. They are very inexpensive and easy to find. They are also very powerful and many are capable of speeds up to 64 MIPS using the internal oscillator block, about 16 times faster than most comparable AVR microcontrollers. PICs are also easy to program, however getting the project set up can some times be tricky. These instructions will walk through the process of setting up the software, creating a new project, and programming some very simple functions to test the configuration and ensure everything is working. They are designed to be very open ended; after the project is created and the basics are finished the reader is encouraged to explore all the features and extras not covered in these instructions. Also you will find that these instructions will start out walking through step by step, but as the instructions near the end the reader is encouraged to explore other ways of accomplishing the tasks and make the project their own.
What you will need To build a project with a PIC microcontroller only requires a few items.

  • PIC microcontroller
    • These instructions are for programming a PIC18F series MCU, although others are similar.
    • Obtained from Microchips website.
    • Microchip allows students with valid .edu email addresses sample PIC’s for free!
    • The PIC I am using to create these instructions is a PIC18F22K80
  • PICkit 3 In-Circuit Debugger
    • Available from Microchip.
    • Costs $45 for general public, and #34 with student discount if you have an .edu email address.
    • There are also other programmers which will work just as well; however, this is the best one for starting out.
  • Breadboard and breadboard wires
  • LEDs, buttons, potentiometers, or anything else you would like to connect to the PIC

Step 1: Build Hardware

Build Hardware

Before doing any programming the first step is to build the hardware. Although the PIC18F portfolio is very large, many of the chips have several commonalities. For more detailed information see the “Guidelines for Getting Started with PIC18Fxxxx Microcontrollers” section in your devices datasheet. For detailed pin-outs of the PIC microcontroller see the “Pin Diagram” section in your devices datasheet.

Note: VDD = Positive Voltage and VSS = Ground.

  1. Connect the MCLR pin through a 1kΩ resistor to VDD.
  2. Connect a 0.1μF capacitor between every pair of adjoining VDD-VSS pairs or AVDD-AVSS pairs.
  3. Connect a 10μF capacitor between VCAP and Vss.
  4. Connect MCLR pin to pin 1 of the PICkit 3.
  5. Connect VDD to pin 2 of the PICkit 3.
  6. Connect VSS to pin 3 of the PICkit 3.
  7. Connect PGD pin to pin 4 of the PICkit 3.
  8. Connect PGC pin to pin 5 of the PICkit 3.
  9. Leave pin 6 of the PICkit 3 unconnected.
  10. Connect any analog inputs to pins with ANx functionality where x is a number.
  11. Connect any digital inputs or outputs to pins with Rxy functionality where x is a letter identifying the port, and y is a number identifying the bit.

For my example I have an LED connected between RA0 and ground, the wiper of a potentiometer connected to AN1, and a DPST switch connected to RA2. You may find it easier to program the PIC if you have sketched down a schematic of your circuit.

Step 2: Get Software

Get Software

These instructions will use XC8 compiler and MPLAB X IDE by Microchip. This step will explain how to get these tools and ensure they have been installed correctly.

  1. To get the latest version of the software visit Microchips website at http://www.microchip.com/pagehandler/en-us/family/mplabx/
  2. Select the software for your OS and follow the standard installation instructions.

Note: If you are using Windows 8 you may need to run the installers in compatibility mode for Windows 7.

  1. Once the software is installed, start MPLAB X
  2. In the menu bar select Tools->Options
  3. In the Options dialog select the Embedded tab and ensure XC8 is listed in the Toolchain list.
  4. If it is listed select OK and move on the next step.
  5. If it is not listed ensure that instillation has completed, and click Scan for Build Tools button.
  6. If still not listed, look on Microchips forum for help with your specific problem.

Step 3: Create New Project

 Create New Project

In this step we will create a new project based on a template from Microchip.

  1. On the menu bar select File->New Project…
  2. In the new file dialog box expand Samples and select Microchip Embedded
  3. In the project box select PIC18 C Template
  4. Select Next
  5. Give the project any name you like
  6. Choose a location to save the project to in the Project Location box
  7. Leave the Project Folder as default options
  8. Check “Set as Main Project” box
  9. Select Finish

The project will now show up in Project Explore on the left hand side of the screen.

Source: Timers of PIC microcontroller How to generate delay

About The Author

Ibrar Ayyub

I am an experienced technical writer with a Master's degree in computer science from BZU Multan University. I have written for various industries, mainly home automation and engineering. My writing style is clear and simple, and I am skilled in using infographics and diagrams. I am a great researcher and am able to present information in a well-organized and logical manner.

Follow Us:
LinkedinTwitter