PIC Microcontroller Basics: Complete Beginner's Guide
A PIC microcontroller is a complete tiny computer on one chip from Microchip Technology — CPU, flash, RAM and I/O peripherals built in. Unlike an 8085, which needs external memory and support chips, a PIC runs a full program with just power and a clock. That all-in-one design made PIC the favourite of hobbyists and product engineers for decades.
PIC teaches real embedded thinking: RAM measured in bytes, direct pin control, peripherals configured through registers. Millions of appliances, toys, car modules and industrial gadgets run PIC firmware, and the skills transfer directly to AVR, ARM and ESP32.
Key Concepts
- Harvard architecture: program and data memories sit on separate buses, so the CPU fetches the next instruction while executing the current one — a built-in two-stage pipeline.
- RISC set: mid-range PICs use only ~35 single-word instructions, each 14 bits wide — few, simple, predictable.
- PIC16F877A (the classic): 8K × 14-bit flash, 368 bytes RAM, 256 bytes EEPROM, 33 I/O pins, 8-channel 10-bit ADC, 3 timers, USART, SPI, I2C.
- Banked RAM: data memory is split into banks selected by STATUS bits — the classic beginner trap when a variable "disappears".
- Instruction cycle: four oscillator cycles = one instruction cycle, so 20 MHz → 5 MIPS (200 ns per instruction; branches take two).
- Peripherals: capture/compare/PWM, comparators and ADC let one chip handle motors, sensors and serial links with no extra hardware.
Formulas
Instruction rate = fosc / 4: at 20 MHz, instructions run at 5 MHz, 200 ns each — the basis of all delay-loop math. ADC conversion: D = (Vin / Vref) × 1023 for the 10-bit converter, so each step is Vref/1024 (≈ 4.88 mV at Vref = 5 V); inverted, Vin = D × Vref / 1023. Together they let you predict code timing and decode sensor voltages before touching hardware.
Worked Example
Read a temperature sensor on a PIC16F877A at 20 MHz, Vref = 5 V. Step 1: set ADCON0 to channel AN0 and enable the ADC; set ADCON1 for AN0-analog, rest digital. Step 2: set GO/DONE and wait ~20 µs for acquisition plus conversion. Step 3: read ADRESH:ADRESL = 0x0199 = 409. Step 4: Vin = 409 × 5/1023 ≈ 2.00 V. Step 5: with an LM35 at 10 mV/°C, that is 200 °C — plausible for an oven, suspicious for a room. Always sanity-check the physical meaning of the number.
Common Misconceptions
- "PIC is one chip." It is a family of hundreds — 8-bit PIC10/12/16/18, 16-bit PIC24/dsPIC, 32-bit PIC32. Choosing the right member is part of the design.
- "Harvard is slower." Separate buses let fetch overlap execute, so most instructions finish in one cycle — a genuine speed win.
- "Banks don't matter; the compiler handles it." In assembly, forgetting bank-select bits writes to the wrong register — the classic "does nothing on the bench" bug.
Real-World Applications
- Appliances: washing machines, microwaves and AC remotes run on cheap PIC12/PIC16 chips.
- Automotive: body-control modules, wiper timers and sensor interfaces.
- Toys: the 6-pin PIC10F blinks LEDs and beeps buzzers in millions of toys.
- Industry: dsPICs with DSP instructions drive motor-control and power-conversion loops.
The PIC formula: Harvard architecture plus a tiny RISC set plus rich peripherals, for pennies. Learn its banks, its 4-clock cycle and its ADC math, and you hold a complete model of how small microcontrollers turn code into physical action.