PIC microcontroller tutorial

CLICK here for a quick PIC microcontroller tutorial

PIC microcontroller is very convenient choice to get started with a microcontroller projects. In this tutorial we will study:

PIC microcontroller introduction

I am here

A Microcontroller is an inexpensive single-chip computer. The microcontroller’s most important feature is its capabilities of STORING and RUNNING a program.

Every Microcontroller (also MCU) consists of several major units:

  • Input / Output Ports
  • Control Pins: reset, power, clock
  • Processor (CPU)
  • Memory (RAM, ROM, EEPROM)
  • Serial and parallel ports
  • Timers
  • Analog-to-digital (A/D) and digital-to-analog (D/A) converters

Characteristics of the RISK (Reduce Instruction Set Control) system:

  • Instruction set of 35 commands
  • Instructions are carried out in 2 clock cycles
  • You can calculate the execution time of the command in accordance with the frequency clock (if the frequency clock is 20Mhz, execution time of a command is 200ns)
  • The ports of 28/40/44 pins microcontrollers are the same

Microcontrollers PICmicro MCU from Microchip Company divided into 4 large families. Each family has a variety of components that provide built-in special features:

  1. The first family, PIC10 (10FXXX) - is called Low End.
    The PIC10FXXX devices from Microchip Technology are low-cost, high-performance, 8-bit, fully static, Flash-based CMOS microcontrollers. They employ a RISC architecture with only 33 single-word/ single-cycle instructions. The 12-bit wide instructions are highly symmetrical. The easy-to-use and easy to remember instruction set reduces development time significantly. The PIC10FXXX devices contain an 8-bit ALU and working register.

  2. The second family, PIC12 (PIC12FXXX)– is called Mid-Range.
    The PIC12FXXX most popular among these starter their way in this field. Mid-Range devices feature 14-bit program word architecture and are available in 8 to 64-pin packages that offer an operating voltage range of 1.8-5.5V, small package footprints, interrupt handling, an 8-level hardware stack, multiple A/D channels and EEPROM data memory. Mid-range devices offer a wide range of package options and a wide range of peripheral integration. These devices feature various serial analog and digital peripherals, such as: SPI, I2C™, USART, LCD and A/D converters.
  3. The third family is PIC16(16FXXX).
    With six variants ranging from 3.5K-14 Kbytes of Flash memory, up to 256 bytes of RAM and a mix of peripherals including EUSART, CCP and onboard analog comparators. These devices are well suited for designers with applications that need more code space or I/O than 14-pin variants supply, and are looking to increase system performance and code efficiency by employing hardware motor control and communications capability.
  4. The fourth family is PIC 17/18(18FXXX).
    The PIC18 family utilizes a 16-bit program word architecture and incorporates an advanced RISC architecture with 32 level-deep stack, 8x8 hardware multiplier, and multiple internal and external interrupts. With the highest performance in Microchip’s 8-bit portfolio, the PIC18 family provides up to 16 MIPS and linear memory. PIC18 is the most popular architecture for new 8-bit designs where customers want to program in C language.

CLICK here to learn more about PIC microcontrollers from Microchip

How to choose/select a PIC microcontroller

Each type of PIC microcontroller provides a different combination of features, thus the most suitable can be selected for any given application. Some of the main selection criteria are:

When developing an embedded system, the number and type of inputs and outputs need to be determined. After the hardware requirements have been established, the program need to be written and tested. Once the size of the program known, the chip memory size can be determined.
The following table is the summary information for selected PIC flash microcontrollers as a guide to the features available:

PIC # # of pins I/O pins Program

ROM

words

File

RAM

bytes

EEPROM

bytes

Analogue

inputs

Timers

8/16

bits

Max clock

(MHz)

Internal osc.

(MHz)

In-circuit

debug

Serial

comms

12F675 8 6 1k 64 128 4x10-bit 1/1 20 4 YES NO
16F628A 18 16 2k 224 128 NO 2/1 20 4 NO UART
16F630 14 12 1k 64 128 NO 1/1 20 4 YES NO
16F648A 18 16 4k 256 256 NO 2/1 20 4 NO UART
16F676 14 12 1k 64 128 8x10-bit 1/1 20 4 YES UART
16F73 28 22 4k 192 NO 5x8-bit 2/1 20 NO NO ALL
16F77 40 33 8k 368 NO 8x8-bit 2/1 20 NO NO ALL
16F818 18 16 1k 128 128 5x10-bit 2/1 20 8 YES I2C,SPI
16F84 18 13 1k 64 64 NO 1/0 10 NO NO NO
16F84A 18 13 1k 64 64 NO 1/0 20 NO NO NO
16F88 18 16 4k 368 256 7x10-bit 2/1 20 8 YES ALL
16F874A 40 33 4k 192 128 8x10-bit 2/1 20 NO YES ALL
16F876A 28 22 8k 256 368 5x10-bit 2/1 20 NO YES ALL
16F877A 40 33 8k 256 368 8x10-bit 2/1 20 NO YES ALL
18F2320 28 25 4k 512 256 10x10-bit 1/3 40 8 YES ALL
18F6520 64 52 16k 2048 1024 12x10-bit 1/3 40 NO YES ALL
18F8621 80 68 32k 3840 1024 16x8-bit 1/3 40 10 YES I2C,SPI
18F8720 80 68 64k 3840 1024 16x10-bit 1/3 40 NO YES ALL

Source: "PIC microcontrollers" by Martin Bates

The PIC16 family is the most common used family from the PIC families. Compared to PIC 17/18 families, the PIC16 family are easy to study and can be used to create “smart” applications.

The great advantage of this PIC is a Flash memory, allowing to burn to the memory unlimited number of times. You can write the program and burn it to the memory inside the microcontroller.

You conduct a test of what was written on the assembled circuit. If you find a mistake or want to make another change in the program, after the change, you can burn the new program once again to the same microcontroller. During the burning process, the old program is deleted, and instead the new program is burned to the FLASH memory. This process can be to done tens of thousands of times. Another advantage is that the price is low.

Examples of applications and some ideas for educational projects that are based on PIC microcontroller

The PIC microcontrollers are widely used in industry and education fields (projects, labs). In fact, almost any systems where there is a need to control certain processes, to obtain information from external sources, and interpret collected information, the microcontrollers is used.

For example, the ABS (an Anti-lock Braking System) is a safety system which prevents the wheels on a motor vehicle from locking while braking, includes a microcontroller. Likewise, all electronics devices in the household are based on microcontrollers, because there is need to monitor certain processes or perform some actions.

"Car with remote control” - This project includes a simple transmitter and receiver. One microcontroller is located inside the car and the other inside the remote.

"Voice recognition" – This project includes a microcontroller with A/D converter. Let’s assume the user records a name and the phone number. The information will be converted to digital information and will be stored in the memory. At any time, the user can speak up the desire name and microcontroller, after recognizing the name, will display the phone number.

"Smart Car" - This project includes two sensors. The 2 sensors are connected to the microcontroller and transmitting a comprehensive data on:

  • fuel consumption
  • a distance to travel relatively to the fuel consumption
  • elapsed trip time
  • a trip distance
All the information can be displayed on the LCD.