Microchip's PIC family (born 1976, became Microchip's flagship after 1989) is the 8051's chief 8-bit rival. PICs are RISC-style, with a small fixed instruction set, single-cycle execution for most ops, and Harvard architecture.
7.1 The PIC families
- PIC10/12/16: 8-bit, baseline/midrange. PIC16F877A is the legendary teaching/hobby chip.
- PIC18: 8-bit, enhanced. More memory, more peripherals, C-friendly.
- PIC24, dsPIC: 16-bit. dsPIC has DSP extensions (MAC unit).
- PIC32: 32-bit, MIPS-based.
7.2 The PIC16F877A: the lab favorite
A 40-pin DIP. Specs:
- 8 KB Flash program memory.
- 368 bytes RAM (data).
- 256 bytes EEPROM (non-volatile data).
- 5 I/O ports (A, B, C, D, E) totaling 33 pins.
- 3 timers (Timer0 8-bit, Timer1 16-bit, Timer2 8-bit with PR2).
- 10-bit ADC, 8 channels.
- USART, SPI, I²C (combined as MSSP).
- 2 CCP (Capture/Compare/PWM) modules.
7.3 PIC instruction set (35 instructions)
The PIC16's flagship feature is its tiny instruction set: 35 instructions. This sounds wonderful for "RISC purity" but has trade-offs.
Categories:
- Byte-oriented file-register operations: ADDWF, ANDWF, CLRF, COMF, DECF, INCF, MOVF, MOVWF, NOP, RLF, RRF, SUBWF, SWAPF, XORWF, etc.
- Bit-oriented: BCF, BSF, BTFSC, BTFSS.
- Literal and control: ADDLW, ANDLW, CALL, CLRWDT, GOTO, IORLW, MOVLW, RETFIE, RETLW, RETURN, SLEEP, SUBLW, XORLW.
Compare to the 8051's ~110 mnemonics or x86's hundreds. Why is small not necessarily better?
Anticipated confusion. "If RISC has fewer instructions, isn't it simpler?" Yes, simpler hardware. But you write more lines of code to do the same thing. PIC16 has no
MOVbetween two RAM locations — you mustMOVF src, WthenMOVWF dst, two instructions instead of one. It has no multiply (16F877A; later PIC18s added one). It has only 8-bit ALU, so 16-bit math is multi-instruction. A program that takes 100 instructions on an 8051 might take 200 on a PIC16. RISC's simplicity buys speed-per-instruction (mostly 1 cycle on PIC) but at the cost of more instructions. The two effects roughly cancel for typical code.
7.4 PIC banked memory
Another quirk: the PIC16's data memory is split into four banks of 128 bytes. To access an SFR, you must first switch to its bank by writing to the RP0/RP1 bits of the STATUS register. If you forget to switch banks, your MOVWF TRISA writes to the wrong place and your I/O direction is silently wrong. Newer PIC18s have linear addressing; PIC16 programmers learned to insert BANKSEL macros everywhere.
7.5 PIC programming
Modern PIC programming is in C. The MPLAB X IDE plus the XC8 (8-bit), XC16 (16-bit), or XC32 (32-bit) compiler is the standard toolchain. A "Hello LED" in C for PIC16F877A:
#include <xc.h>
#define _XTAL_FREQ 4000000
void main(void) {
TRISB = 0x00; // PORTB all outputs
while (1) {
PORTB = 0xFF; // all on
__delay_ms(500);
PORTB = 0x00; // all off
__delay_ms(500);
}
}Programming the chip is via PICkit (USB programmer, ~$50) or ICSP from an in-circuit debugger.
7.6 Real-world PIC
PIC16F877A is in countless industrial control panels, irrigation controllers, hobby robots, RFID readers, pinball-machine refurbishments, science fair projects. Microchip ships hundreds of millions of PICs per year. They are cheap (some PIC10s under $0.50), low-power, easy to source. The 8051 vs PIC choice is a religious war among embedded engineers — the truth is they are roughly equivalent capability with very different programming flavors.