PIC16F877
PIC16F877 StudioCPU emulator · debugger · virtual peripheral laboratory
Ready
0 cycles
Registers8-bit MCU · 14-bit code
Next PC: 000
Execution listingclick address to toggle breakpoint
Memoryphysical
SS:SP / ports
Trace
VIRTUAL HARDWARE LABORATORY

PIC16F877 peripherals

PORTB is the 8-bit data bus. PORTA bits 0–3 select an external latch; pulse RA4 high to write it. Select switches, keypad or buttons as the PORTB input source. Configure TRIS directions in your program.

LED bankLatch 0
D7 D6 D5 D4 D3 D2 D1 D0
Each data bit drives one LED.
Toggle switchesPORTB input
8-BIT INPUT BANK
Select Switches; set TRISB = 0xFF to read.
4-digit 7-segment displayLatches 1–4
One latch per digit. Low nibble selects 0–F.
2×16 character LCDLatches 5 / 6
VSS VDD VO RS RW E D0 D1 D2 D3 D4 D5 D6 D7 A K
5: command (1 clear, 0x80 line 1, 0xC0 line 2). 6: ASCII character.
4×4 hexadecimal keypadPORTB input
Select Keypad; read 0–15 while held, 0xFF when released.
Buttons & buzzerLatch 7 / RB0 INT
START/STOP/IRQ are input bits 0/1/2. IRQ also pulses RB0. MCLR resets CPU. Latch 7 controls a 660 Hz buzzer.
Serial terminalLatch 8
External parallel-to-serial teaching bridge. Write an ASCII byte; the hardware USART has a separate terminal below.
256-byte data EEPROM
EEPROM survives MCLR and program reload. Full Reset clears it. Timing is a deterministic teaching approximation.
PIC16F877 on-chip peripherals 4 MHz nominal
Hardware USART output
SSP transactions
I/O BUS
Idle

PIC16F877 wiring & instruction guide

External laboratory board

PORTB (RB7–RB0) is an eight-bit data bus. RA3–RA0 select a board latch, and a rising RA4 edge clocks the byte into it. RA4 is treated as having an external pull-up. Configure TRISA = 0 and TRISB = 0 for output. The board is an external teaching accessory, not extra PIC memory or instructions.

LatchOutput
Latch 0LED bank
Latches 1–44-digit 7-segment display
Latches 5 / 62×16 character LCD
Latch 7 / RB0 INTButtons & buzzer
Latch 8Serial terminal
BANKSEL ADCON1
MOVLW 6
MOVWF ADCON1
BSF STATUS, RP0
CLRF TRISA
CLRF TRISB
BCF STATUS, RP0
CLRF PORTA       ; select LED latch; RA4 low
MOVLW 0xAA
MOVWF PORTB
BSF PORTA, 4     ; rising clock: capture data
BCF PORTA, 4

To read inputs, choose their source above the lab and set TRISB to 0xFF. Switches return eight bits; keypad returns 0–15 or 255; buttons return a bit mask. PORT writes and bit operations follow PIC read-modify-write behaviour, so always configure direction first.

PIC16F877 device model

Original PIC16F877: 8,192 × 14-bit program words, 368 bytes of RAM in four banks, 256 EEPROM bytes, 33 I/O pins across PORTA–PORTE, an eight-level return stack and all 35 instructions. STATUS RP1:RP0 select the direct bank; IRP extends FSR for indirect addressing. BANKSEL emits two real instructions. CALL/GOTO take an 11-bit operand and use PCLATH for program pages.

RAM: 020–07F, 0A0–0EF, 110–16F and 190–1EF. The top 16 addresses in each bank share RAM 070–07F. Enter a three-digit memory address to inspect any bank. PORTA/PORTE start in analogue mode. Set ADCON1=6 for the external digital lab.

On-chip peripheral lab

AN0–AN7 inputs accept 0–5 V. ADCON0 starts conversion; ADCON1 controls channel configuration, voltage references and result alignment. Conversion completes after 12 simulated instruction cycles. Set voltages after loading a demo. Timer0 supports internal and external clocks; Timer1 supports prescaling, overflow and external pulses; Timer2 supports PR2, prescaling and postscaling. CCP capture uses the edge buttons (rising except mode 4); compare uses Timer1 and PWM uses Timer2 on RC2/RC1. The display samples pin levels; it does not draw a waveform.

The hardware USART supports asynchronous byte transmit and a two-byte receive FIFO with overrun. Enable SPEN/TXEN/CREN in code. At 4 MHz the simulator applies baud-rate frame delays; receive bytes are injected by the lab. The original parallel serial bridge remains available independently.

MSSP supports deterministic byte exchanges with a configurable reply and completion flags, plus I²C start, restart, stop, receive and acknowledge control completion. PSP host write/read simulates PORTD buffer strobes and flags. These are register-level teaching models: synchronous/9-bit USART, I²C slave addressing/arbitration, SPI clock phase waveforms and electrical bus contention are not modelled.

EEPROM and single-word flash writes require the 55/AA EECON2 unlock sequence. EEPGD selects flash; completion takes four simulated cycles. Reverse Step restores flash, EEPROM, peripheral buffers, counters, output and CPU state. Already played sound cannot be reversed. SLEEP pauses the runner; use an enabled interrupt to wake. Watchdog timing is nominal. This is an educational instruction simulator, not a silicon timing validation tool.

Microchip PIC16F87X datasheet, DS30292D

Assembly and Hex

All 35 documented instructions are assembled, decoded and executed. File destinations are W/0 or F/1; omitted destination defaults to F. Decimal is the default; use 0xAA, H'AA', B'10101010', or D'170'. Supports labels, EQU, CBLOCK/ENDC, ORG, DW, __CONFIG and DE at ORG 0x2100. Standard device symbols are built in. Macros and external include processing are not implemented; LIST/INCLUDE device headers are accepted for compatibility.

Hex mode accepts standard Intel HEX with checksums, or four-digit 14-bit words such as 000: 30AA 0086. Intel HEX uses byte addresses; the listing and word-entry format use word addresses. Saving Hex exports Intel HEX. Assembly/Hex switching reassembles or disassembles; original comments and labels cannot be reconstructed from opcodes.

Debugging

F7 executes one instruction. Gold register highlights remain until another instruction executes. F8 steps over CALL; Pause can interrupt it. Click an execution address to toggle a breakpoint. Run stops before that address; Step executes through it. Full Reset clears CPU, memories, breakpoints, trace and hardware while retaining the editor text. MCLR retains program and EEPROM.

Choose a demo, press Assemble & load, then Step or Run. Input demos loop: use Pause to inspect them. Font settings include a master Panel font control and independent window controls.

Keyboard shortcuts

F5RunF6PauseF7StepF8Step over CALLCtrl/⌘ + EnterAssemble / loadCtrl/⌘ + OOpen sourceCtrl/⌘ + SSave named fileCtrl/⌘ + RFull ResetTab / Shift+TabIndent / unindent

Name your file

.asm

Guided tour

1Choose a demo or type/import a program. The editor starts blank.
2Assemble & load. The listing shows real 14-bit instruction words.
3Step with F7. Gold highlights show the last instruction’s changes until the next instruction.
4Click an address for a breakpoint. Inspect banked RAM, stack, trace and EEPROM.
5Open Wiring guide for the external lab. Select inputs and configure TRIS in code.
6Use Panel font for all windows or each window’s own font control.