Tools & Downloads   /   Programmers & ICSP

How to Program a PIC Microcontroller & Read an Encoder

Introduction: From electronic toys & games to microwave ovens, microcontrollers can be found just about anywhere these days!

Published

At a glance

CategoryProgrammers & ICSP
IncludesDownload files
Reading time~2 min
Jump to a section
  1. Step 1: Materials
  2. Step 2: Power Supply Setup
  3. Step 3: Breadboard Setup
  4. Related projects

Introduction: From electronic toys & games to microwave ovens, microcontrollers can be found just about anywhere these days! But how can we make these small computers work for our own electronics projects? That's where this tutorial comes in - with detailed instructions showing you what to do every step of the way. At the end of this project, your microcontroller will even be able to track the speed of a motor!
How to Program a PIC Microcontroller & Read an Encoder
What to know: Before we get started though, there's some prior knowledge that will not be covered in this guide. If you'd like to brush up your knowledge on any of those topics (listed below), feel free to check out the links.

Voltage: https://learn.sparkfun.com/tutorials/voltage-curre...

Voltage Measurement: https://learn.sparkfun.com/tutorials/how-to-use-a-...

Breadboarding: https://learn.sparkfun.com/tutorials/how-to-use-a-...

Oscilloscope Use: http://eeshop.unl.edu/pdf/OscilloscopeTutorial--Be...

Step 1: Materials

Note: Materials listed with an asterisk can be substituted depending on what you may have available. The components used for this tutorial that fall into that category are listed in parentheses. Please note that substitutions may render portions of this guide irrelevant (i.e. a portion of code may not work if a different microcontroller is used).

Software:

MPLAB X IDE (Free from: http://www.microchip.com/pagehandler/en-us/family...
MPLAB XC8 (Free from: http://www.microchip.com/pagehandler/en_us/devtoo...

Hardware:

DC Power Supply
Banana Cables
Breadboard
Wires
PIC Programmer/Debugger* (MPLAB ICD 3)
RJ11 Connector [Included with MPLAB ICD 3] USB 2.0 Cable [Included with MPLAB ICD 3] PIC Microcontroller* (PIC18F4520) - Be sure to use a DIP microcontroller so that it can be put into a breadboard.
Device with a rotary encoder* (Pololu Item # 2269)
10Ohm Resistor
RJ-11 to Breadboard Adapter (DigiKey # H11394-ND)

Oscilloscope (Optional) - Allows you to see encoder signals
Oscilloscope Probes x 2 (Optional)
Multimeter (Optional) - Helpful for debugging issues

Step 2: Power Supply Setup

After acquiring the necessary equipment, our next task is to setup the breadboard & get power to the PIC microcontroller (MCU). That means it's time to hook up the DC power supply.

Power Supply: As you'll see in the picture of the Acopian DC power supply pictured in this step, each power supply channel has three colored connectors to which banana cables can be connected. For the purposes of this tutorial, we'll need +5V and +0V (ground) from the power supply. In order to supply +5V and +0V, connect the negative terminal and grounded terminal of the power supply together (the green and black terminals in the picture provided). Then attach a banana cable to both the positive (red) terminal and the grounded (green) terminal that will be connected to the breadboard. How to Program a PIC Microcontroller & Read an EncoderThese terminals, found on the breadboard, are shown with connected banana cables in step 3.

 

Step 3: Breadboard Setup

Breadboard: It's time to setup the breadboard. After many wiring disasters of my own, I would suggest that you keep wire colors consistent. In this tutorial you'll see +5V wires in red and +0V wires in green with the exception of the wires in the RJ-11 to breadboard connector (which were wired by a company). Please also note that it is helpful to setup +5V and +0V on the breadboard's terminal strips.

 

For more detail: How to Program a PIC Microcontroller & Read an Encoder

Programmers & ICSP

Calculator Test using PIC24FJ64GA006 with Proteus Simulation

Introduction The Calculator Test using EASYHDL is a practical microcontroller project built on the PIC24FJ64GA006 and simulated in Proteus. This project demonstrates...

Programmers & ICSP

PID Controlled Oven using TMS320F28027PT with Proteus Simulation

IntroductionThis project demonstrates a PID controlled oven implemented using a PICCOLO TMS320F28027PT microcontroller and verified through Proteus simulation.It is a practical microcontroller...

Programmers & ICSP

PICCOLO Motor Controller Sample Design using TMS320F28023PT with Proteus Simulation

IntroductionThis project demonstrates a PICCOLO motor controller sample design implemented using the TMS320F28023PT Piccolo microcontroller and tested through Proteus simulation. It focuses...

Programmers & ICSP · PIC16F84A

PIC Musical Doorbell using PIC16F84A with Proteus Simulation

IntroductionThis microcontroller project demonstrates a musical doorbell built around a PIC16F84A and a simple piezo sounder.Using two push buttons, the system allows...

Programmers & ICSP · PIC16F877A

EPE PIC/LCD Demo using PIC16F877 with Proteus Simulation

IntroductionThe EPE PIC/LCD Demo is a classic microcontroller project that demonstrates how a PIC16F877 can fully control a PG12864F graphical LCD.Designed as...

Programmers & ICSP · PIC16F628A

DHT11 Low Cost Humidity Sensor using PIC16F628A with Proteus Simulation

IntroductionThis microcontroller project demonstrates how to interface a low-cost DHT11 temperature and humidity sensor with a PIC16F628A using a Proteus simulation environment.The...

Ibrar Ayyub

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough...