Become a subscriber (Free)

Join 29,000 other subscribers to receive subscriber sale discounts and other free resources.
:
:
Don't worry -- your e-mail address is totally secure. I promise to use it only to send you MicroZine.

Beginners guide to the PIC Microcontroller

Introduction

This guide will show you what a PIC microcontroller is and what you can do with it.


First of all what is a PIC microcontroller?

A microcontroller is a self contained fully functional computer with built in peripherals.

The idea of a microcontroller is that it can stand alone and does not require any other circuitry to do a useful task.  Normal processors such as those found in desktop PCs require a multitude of circuitry before you can get anywhere near a useful system.

Another important point about a microcontroller is that it is not intended to be a super-duper all singing all dancing mega MIP device it is intended for doing fairly simple tasks that do not require huge amounts of processing power.

Note : You can now get DSP microcontrollers which do allow very complex operation at high speed - but these require advanced knowledge of signal processing mathematics.

Peripherals

Having said that a microcontroller is actually extremely efficient for doing fairly simple tasks for the simple reason that it has built in peripherals.

These include such as timers, ADCs, analogue comparators, pulse width modulators, USARTs...and more.  
Ths is one I find amazing the 12f675 is has only 8 pins (the same as a 555).

It has :

*Two timers.
*One analogue comparator.
*10 bit 4 input ADC.
*Six usable I/O pins (you need one for power and and one for Ground)
*1024 program memory words (program space).
*64 Bytes Ram
*128 bytes EEPROM
*Internal oscillator.
*External clock capable to 20MHz
*ICSP port.

Phew - just compare that to a 555  = 1 comparator!

A 12F675 tutorial is available on the site.

However I would not recomment that you use it, as a beginner, since although it is a powerful device it only has 8 pins (two of which are power and ground). So pins are multiplexed for programming and for use. This makes it more difficult to use since you have to program the device then set it up for use.

If you use a larger pinned device such as a 16F628 (18pins), 16F88 (18 pins) or a 16F877 (40 pins) or even 18F2550 (28 pins) or 18F4550 (40pins) then you are going to find it a lot easier to allocate pins to different functions - and you can leave the programmng port connected to only the ICSP programmer while experimenting with the other pins of the device..

Low pin count devices are really for a finalized "minimized" project - e.g. if you are building a small footpring PCB then the smaller devices will save money. Go for larger ones for experimentation (they also have more RAM and Flash program memory (EEPROM) making it easier to create programs..

The other point is that most internal peripherals work in more-or-less the same way even between different families i.e. 12F, 16F, 18F - of course there are enhancements but the basic functionality is the same e.g.. for timers and comparators etc.

Simple Tasks

Actually the 'simple tasks' are only simple in comparison to the computing power of a PC.  In reality the microcontroller is ideal for tasks that require low level hardware control.

These ready-to-use peripherals save you from having to wire up extra circuitry all you have to do is program the internal peripheral to configure the microcontroller for your application.


Project examples

Examples of what you can make using a microcontroller are:

*Inductance/Capacitance meter.
*Ultrasonic range finder.
*Universal Infrared controller.
*Frequency counter.
*X10 home automation controller.
*Metal detector.
*Home security alarm.
*Servo controller.
*Dot matrix led controller.
*Binary clock.
*Seven segment Digital clock.

...and many more...

... In fact the list is endless because
you can make up virtually any electronic
project you can think of and...

...a microcontroller makes it easy.

The website and this guide focus on only a few microcontrollers in the PIC range since all PIC devices share common internal  peripherals (so learning about a peripheral means you have learned the peripheral for all PIC devices):

12F675 - 8 pin.
16F88 - 18 pin.
16F877 - 40 pin.

Note: Sometimes there are small differences - so check the data sheet - but in general the peripherals are identical across the same range of devices.

Structure of a microcontroller

CPU

All microcontrollers have a Central Processing Unit (or CPU) and this is responsible for taking the data, processing it and spitting out a result.

For the PIC microcontroller mid range devices (16F) the processing block is 8 bits wide so the microcontroller works only with data having 8 bits in it.

Memory

PIC Microcontrollers have three types of memory:

  1. Program memory.
  2. Data memory.
  3. EEPROM memory
Memory Architecture

PIC devices use a Harvard architecture which simply means that Data memory and Program memory are entirely separate.   

The idea is that you can get a speed improvement by storing the program and the data  in separate memory sections because you can retrieve data from both sections at the same time.  

For a von-neumann architecture (where the same memory is used to store program and data) the processor has to fetch the program instruction and then fetch the data so it works more slowly.

For this reason you will see references to the PIC saying it has 12bit or 14bit architecture etc. - this refers only to the program memory - all you really need to know is the data memory size as this is the fundamental unit that the microcontroller operates on - it's usually 8 bit.

Program memory

Program memory is based on Flash technology (this is the 12bit or 14bit spec.).  This is non volatile memory which stores your program instructions.

Note: non-volatile means that it keeps its contents even when the power is turned off so it's ready to go as soon as power is applied.

This is also the memory that you program using an external programmer (using the PIC ICSP port) and programmed from a PC using the programming software e.g. ICPROG.

Data memory

Data memory is simply memory based on SRAM technology.  This type of memory retains its values only while the power is on.

Unlike Flash memory you can easily change the values stored in data memory while the program is running.  

So you can create counters to store the number of events detected or temporarily store the intermediate result of a computation.  This is memory that stores changing data i.e. you store variables in Data Memory.

EEPROM memory

EEPROM memory is another data store - it's a cross between the program memory and data memory.  You can store any data in it and retrieve any data from it - but  it takes more effort to store and retrieve data.

This is because it is also non-volatile just like the flash memory but under program control you can change the stored values just like data memory but when the power goes off it keeps the stored values.

It is Electrically Erasable PROM : Non volatile Data Memory.

Note: Newer devices let you alter the program memory itself - which is why bootloading is possible.

EEPROM usage

For a normal program you would use EEPROM to store program settings that you need to keep between power cycling of the device.

For example if you had designed a programmable power supply you would want the microcontroller to remember the last voltage so the unit powers up to the same voltage at the next session.


Next time...

... Ports - Using microcontrollers to communicate with the 'real' world.

New! Comments

Have your say about what you just read! Leave me a comment in the box below.



Claim Your: Useful

"Arduino Software Guide"

   Right Now...




Privacy Policy | Contact | About Me

Site Map | Terms of Use



Visit our Facebook Page:

   Click Here



Sign up for MicroZine
''The'' Microcontroller Newsletter

Enter your first Name and primary email address in the form below:


And receive absolutely FREE a full project for:

"Measuring Analogue Voltages
Without An ADC"

(Using only one pin).

Instant Download:
You Can
Get It Right Now

Warning: This project could be  Removed 
at any time.  

It will  NOT be 
available indefinitely SO
To avoid 
disappointment  get it:

Now



:
:
Don't worry -- your e-mail address is totally secure. I promise to use it only to send you MicroZine
Remember this is a project with full description and fully debugged C Source code - and it's not available from the main website.

You can only get it through this newsletter.

To get exclusive access Enter your first name Name and primary email address Now in the form above.:



But wait !

There's more...

You'll receive more
free and exclusive reports as well as site information and site product updates


Scroll up to the form above and sign up NOW. Don't forget it's FREE and if you don't like it, you can unsubscribe at any time.

Click Here Now to use the form above to get your Valuable information absolutely free.



Readers Comments

"I wanted to thank
you so so so much
for all the information
you have provided in
your site it's

SUPERB and FANTASTIC."

- Ranish Pottath

"This site really is
the best and my favorite.
I find here many useful
projects and tips."

- Milan

bursach<at>gmail.com<

"Awesome site,
very, very easy and nice
to navigate!"


- Matt
matt_tr<at>
wolf359.cjb.net


Learn Microcontrollers

"Interested in
Microcontrollers?"

Sign up for The
Free 7 day guide:

FREE GUIDE : CLICK HERE


"I am a newbie to PIC
and I wanted to say
 how great your
site has been for me."


- Dave

de_scott<at>bellsouth.net

"Your site is a great
and perfect work.
congratulations."


- Suresh

integratredinfosys<at>
yahoo.com

"I couldn't find the correct
words to define
yourweb site.

Very useful, uncovered,
honest and clear.

Thanks so much for
your time and works.
Regards."


- Anon

Recent Articles

  1. How to use the DHT22 (or DHT11) with an Arduino; full code and description. Also including a comparison of the DHT11 vs DHT22.

    The Essential Guide to the DHT22/11 humidity sensor including a library code guide for the Arduino. Learn how to determine Humidity, Dew point and Heat Index.

    Read more

  2. How to Use the MAX7219 to drive an 8x8 LED display Matrix on the Arduino.

    The Essential Guide to the MAX7219; What it is and how you can easily use one in any of your projects.

    Read more

  3. How to use a DS18B20 (single or multiple on one wire) for temperature measurement using the Arduino Uno.

    How to Easily Use the DS18B20 Maxim One-Wire thermometer with Arduino example code showing external or parasitic power modes.

    Read more