PIC16F877 Simulation Lab — interactive hardware simulator · all special function registers live · type instructions or run full programs
Only PORTA and PORTB are wired to breadboard hardware here (switches
and LEDs/7-seg), the same way a first PIC lab bench usually is. PORTC, PORTD and PORTE are still fully
live — read/write them from the editor, CLI, or the SFRs tab — they just aren't tied to a physical
component in this drawing. Any pin currently configured as an input (dashed ring, once you flip its TRIS
bit) can also be clicked directly on the chip body itself.
GIE0
INTF0
ISR fires0
Digit0
The same circuit style as the Breadboard tab, trimmed to just what this lesson needs:
one switch on RB0/INT and a 7-segment display wired straight to PORTC (RC0..RC7 → a..g,dp —
no jumpers to route). Flipping the switch pulses RB0 from 0 to 1, a real rising edge detected every
instruction against OPTION_REG<INTEDG> (default: rising). The
main program does nothing but GOTO $ — a pure infinite loop — yet
flipping the switch still genuinely vectors the CPU to 0x0004, clears GIE, advances the digit shown
on the 7-segment from inside the ISR, and RETFIE restores GIE and
drops back into that same infinite loop, exactly where it left off. Opening this tab loads the matching
tutorial program into the code editor automatically.
TMR00x00
TMR0 (dec)0
Prescaler0 / 2
T0CS0
T0SE0
PSA0
T0IF0
Only does anything while T0CS=1 and TRISA<4>=1 (RA4 configured as input)
This is the real PIC16F877 TMR0 module — the same block
diagram as the datasheet, animated from live silicon state, not a canned animation. Every instruction cycle
(Tcy = 4/Fosc, exactly one Fosc/4 pulse) is genuinely counted: with T0CS=0 (bit5 of
OPTION_REG) the left multiplexer selects the internal Fosc/4 clock;
set T0CS=1 to instead count edges arriving on the RA4/T0CKI pin (toggle it above, or from the
Breadboard tab's RA4 switch), with T0SE choosing rising or falling edge. PSA (bit3) routes
that clock either straight into TMR0 (PSA=1, prescaler bypassed — it's servicing the Watchdog Timer instead)
or through the programmable prescaler (PSA=0), whose 1:2 – 1:256 divide ratio comes from
PS2:PS0 (bits2:0). TMR0 increments on every pulse that reaches it and rolls 0xFF→0x00, which sets
INTCON<T0IF> — flashed red on the diagram below — exactly like
real hardware; software must clear it with BCF INTCON,T0IF (the sample
program does this every pass). Writing directly to TMR0 (MOVWF TMR0 /
CLRF TMR0) also clears the prescaler count, matching the datasheet
note that the prescaler is shared with the Watchdog Timer. Opening this tab loads a ready-to-run TMR0 demo
(1:64 prescale, polled overflow advancing the PORTB LEDs — visible in the CPU State panel, or wire PORTB to
LEDs on the Breadboard tab) into the code editor automatically.
W (working register)0x00
Active bank (RP1:RP0)0
STATUS Register Bits
bit7 IRP0
bit6 RP10
bit5 RP00
bit4 TO0
bit3 PD0
bit2 Z0
bit1 DC0
bit0 C0
Every STATUS bit is genuinely live here (an improvement on 16F84A-class demos that pin
IRP/RP1/TO/PD at 0): RP1:RP0 select the active register bank below,
IRP extends indirect addressing (FSR/INDF) into banks 2-3, and
TO/PD reflect the last CLRWDT/SLEEP — the
watchdog timer itself isn't simulated, so they never change on their own. Z, DC and C update with every
instruction that affects them.
Register File — All Four Banks
BANK 0 RP1:RP0 = 00
0x20 – 0x7F: General-purpose RAM (see grid below)
BANK 1 RP1:RP0 = 01
0xA0 – 0xFF: General-purpose RAM (see grid below)
BANK 2 RP1:RP0 = 10
0x110 – 0x16F: General-purpose RAM (see grid below)
BANK 3 RP1:RP0 = 11
0x190 – 0x1EF: General-purpose RAM (see grid below)
All four banks are fully live, including banks 2/3's real hardware SFRs:
EEDATA/EEADR/EEDATH/EEADRH (bank 2) and
EECON1/EECON2 (bank 3) drive the on-chip data EEPROM — set
EEADR, then BSF EECON1,RD to
read a byte into EEDATA, or load
EEDATA and BSF EECON1,WREN
then BSF EECON1,WR to write one (the EEPROM survives a Reset, just
like real non-volatile memory — only Reassemble clears it). Everything else in banks 2/3 besides the
universal PCL/STATUS/FSR/PCLATH/INTCON mirrors and the common 0x70-0x7F window is its own writable
general-purpose RAM, reachable directly or via indirect addressing with STATUS,IRP set.
General-Purpose RAM (0x20 – 0x7F)
A cell flashes briefly whenever an instruction changes it. Switch tabs above to inspect
any bank's copy of general-purpose RAM (0x70–0x7F is the same physical bytes in every bank).
Logic Analyzer — 4 Channels
Time/div
Name each channel and pick any pin (any port, wired to the breadboard or not) to
trace it live — captured instruction-by-instruction while running, so fast toggles aren't missed.
Time/div runs from 1 ms down to 1 ns; the drawing is laid out on that real time axis (cycles × Tcy),
so zooming in past one instruction's Tcy just shows a held value, same as a real instrument outrunning
its sample rate. This panel is global — it keeps running under the Interrupt (RB0/INT) and SFRs &
Memory tabs too, not just Breadboard — and Run/Stop here are the same Assemble & Run / Stop controls
as the ones next to the code editor, so you never have to leave this view to control the simulation.
How this demo works
• The PIC drives PORTB (RB0–RB7). Each RB pin wires straight into the
jumper matrix — click its L dot to route
that pin to an LED, or its S dot to route it onto the 7-segment bus
(bit0..7 → a,b,c,d,e,f,g,dp).
• Switches are wired to PORTA (RA0–RA5) whenever a pin is configured as an
input (TRISA bit = 1) — click to toggle, read with
MOVF PORTA,W / BTFSC PORTA,0.
Configure an RA pin as an output instead and its switch knob turns yellow,
showing the value the CPU is driving, and stops responding to clicks.
• Set TRISB = 0 before writing PORTB, otherwise the pins stay inputs
and nothing lights up.
• Bank switching is real, across all four banks. Instructions only carry a
7-bit register offset — PORTA/PORTB (bank 0) and TRISA/TRISB (bank 1) share the same offset, so which one
you actually hit depends on the live STATUS<RP1:RP0> bits at
that moment, exactly like real hardware. Writing MOVWF TRISB while
RP0=0 silently writes PORTB instead — BSF STATUS,RP0 before touching
TRISx, then BCF STATUS,RP0 before touching PORTx, exactly as the
default program does.
• The currently-executing instruction is highlighted directly in the Program Editor as the program runs.
CPU State
PC
W
Bank
Z
C
DC
0
0x00
0
0
0
0
PORTA
TRISA
PORTB
TRISB
0x00
0x3F
0x00
0xFF
PORTC
PORTD
PORTE
Stack
0x00
0x00
0x00
0/8
Clock (Fosc):Tcy = 0.500 µs/instr · up to 2.00 MIPS
Run speed:1/4FullFull speed (1×) — real-time-accurate at the selected clock
Demo pace:SlowFast~500 ms / instruction
Instructions: 0 ·
Simulated time: 0.000 ms ·
Real time: 0.000 ms ·
Achieved: —
All 35 mid-range instructions are supported one at a time (no labels/branch targets in
CLI mode — use the editor for that). Literals: 0x.. / b'..' / d'..' / H'..' / plain decimal. Any SFR name
(PORTB, TRISC, INTCON, ADCON1, …) or STATUS/INTCON bit name (Z, C, RP0, GIE, …) works as an operand.