🔧

Introduction to PIC Microcontrollers

Jun 15, 2024

Introduction to PIC Microcontrollers

Key Topics Covered:

  1. What a microcontroller is
  2. Basic microcontroller systems
  3. Control capabilities of microcontrollers
  4. Building blocks of a microcontroller
  5. Connecting digital inputs and outputs
  6. Detailed look at PIC16F84A
  7. Memory organization and special function registers
  8. Basic assembly instructions and programming

What is a Microcontroller?

  • A small computer on a single integrated circuit.
    • Contains a processor, memory, programmable I/O pins, and peripherals.
  • Examples: ADCs, serial ports, timers.
  • Can perform tasks based on the program written into them.

Basic Microcontroller System

  • Components: Input, Control (Microcontroller), Output.
  • Inputs: switches, sensors, communication signals.
  • Outputs: visual, audio, communication, switching.

Control Capabilities

  • Programmable and configurable pins (either input or output).
  • Contains built-in peripherals like timers, ADCs, serial communication, etc.

Building Blocks of a Microcontroller

  • CPU: executes instructions and performs arithmetic.
  • Program Memory: stores the program.
  • Data Memory: stores user data (volatile RAM or non-volatile EEPROM).
  • I/O Pins: interface the microcontroller with external devices.
  • Timers: used for delays or real-time operations.
  • Peripherals: ADCs, serial communication, etc.

Connecting Digital Inputs and Outputs

  • PIC Microcontroller Capacity: sinks or sources max 25 mA per pin.
  • Configurations: Pull-Down and Pull-Up Resistors.
    • Pull-Down: Input connected to ground; ensures reliable logic state.
    • Pull-Up: Input connected to VCC; ensures reliable logic state.
  • Output: can be configured as sinking (current flowing into microcontroller) or sourcing (current flowing out).

PIC16F84A Overview

  • Ports: Port A (5 pins), Port B (8 pins), both programmable as I/O.
  • Special Pins:
    • MCLR Pin – Reset pin, should be logic high for normal operation.
    • VSS Pin – Ground.
    • VDD Pin – Positive supply (2V-5.5V).
    • Oscillator Pins – Used for oscillator input.

Memory Organization

  • Two memory blocks: Program Memory & Data Memory.
  • Data Memory:
    • Divided into Special Function Registers (SFR) and General Purpose Registers (GPR).
    • Further divided into Bank 0 and Bank 1.

Special Function Registers (SFR)

  • Tris Registers (A & B): Configure pins as input/output.
  • Port Registers (A & B): Read/write I/O pin states.
  • Status Register: Bit 5 (RP0) used to switch between banks.

Basic Assembly Instructions

  • Bit-Oriented Instructions: Affect a single bit in an 8-bit register (e.g., bit set file).
  • Byte-Oriented and Literal Instructions: Affect all 8 bits of a register (e.g., move literal to W).
  • Branching Instructions: Change the flow of execution (e.g., goto, call, return).

Steps to Configure I/O Pins

  1. Use Tris Registers to set pins as input/output.
  2. Configure pins in Bank 1.
  3. Switch between banks using Bit 5 of the Status Register.
  4. Read/Write states using Port Registers in Bank 0.

Example Program Breakdown

  1. Configure Pins: Tris A for Port A and Tris B for Port B.
  2. Switch Bank: Use bit 5 of Status Register.
  3. Access Ports: Use Port Registers to read/write pin states.
  4. Endless Loop: Execute indefinitely to maintain state.

Simulation and Debugging

  • Use MPLAB IDE for writing and simulating programs.
  • Use PIC Simulator IDE to visualize and validate pin states.

Problem Statement Interpretation

  1. Identify input/output pins based on the problem statement.
  2. Translate statements into assembly instructions and flowcharts.
  3. Ensure correct initialization of pins and peripherals.
  4. Use special function registers appropriately as per the problem requirements.