ADEL Processor Simulator

ADEL: Architecture Design that's Easy to Learn · 16-bit instructions · 8-bit datapath · single-cycle execution
Processor architecture, assembler, and simulator developed by Adelson Chua

Assembly

Write your program here
Click a line number to set a breakpoint. Editing clears breakpoints.

Machine code

Click for more details
AddrHexAssembly

Architectural state

PC
00
R0
00
R1
00
R2
00
R3
00
ADEL processor datapath

Execution trace

CyclePCInstructionEffect at edge

Getting started

Getting started

ADEL means Architecture Design that's Easy to Learn. Its single-cycle processor uses 16-bit instructions, an 8-bit datapath, four registers (R0–R3), and an 8-bit program counter. Instruction memory holds up to 256 words.

  1. Choose File → Load Templates for an example, or File → New Assembly to write a program.
  2. Edit the Assembly panel. The live assembler updates Machine code and instruction ROM when the source is valid.
  3. Choose Step to execute one cycle. Follow the register values, datapath probes, and Execution trace.
  4. Choose Run for continuous execution and Pause to inspect the current state. Use File → Save Assembly to keep your source.

Click a Machine code instruction to inspect its encoding. Undo restores the previous cycle, and Reset starts execution again from address zero.

Edits are autosaved as a draft in this browser, including unfinished or empty source. The draft returns when you reload the page. Loading a demo preserves it; use File → Restore saved draft to return to it. The draft includes the selected I/O and Free play register assignments; execution restarts from the beginning.

Before replacing edited source, choose Cancel, Continue without saving, or Save and continue. Saving downloads an assembly file. A browser draft is separate from that file and is available only in this browser; editing another program replaces the draft. If autosaving is unavailable, use File → Save Assembly.

Supported instruction set

ALU instructions use OP Rd, Rs1, Rs2. Add I for an immediate operand: OPI Rd, Rs1, value. All four registers are writable; clear a register explicitly when a program needs a constant zero.

InstructionsResult or branch condition
ADD, ADDIAdd the two operands.
SUB, SUBISubtract the second operand from the first.
AND, ANDIBitwise AND.
OR, ORIBitwise OR.
BEQ Rs, targetBranch when Rs = 0.
BNE Rs, targetBranch when Rs ≠ 0.
BLT Rs, targetBranch when signed Rs < 0.
BGT Rs, targetBranch when signed Rs > 0.

Results wrap to eight bits. Decimal immediates and branch offsets must be −128 through 127. Hexadecimal (0x00–0xFF) and binary (0b00000000–0b11111111) literals specify 8-bit patterns: 0xF0, 0b11110000, and -16 are equivalent. Decimal 240 is out of range. An explicit minus sign denotes a signed value, so -0x10 also means −16. Signed comparisons interpret register values as −128 to 127.

A branch target can be a label or an offset from −128 to 127. A taken branch computes PC + offset from the branch instruction's own address. Other instructions advance to PC + 1. Both updates wrap within the 256-word address space.

Example: count five iterations

ANDI R0, R0, 0
ANDI R1, R1, 0
ADDI R2, R0, 5
loop:
ADDI R1, R1, 1
SUBI R2, R2, 1
BNE  R2, loop
done:
BEQ  R0, done

The loop leaves R1 = 5 and R2 = 0. The final self-branch holds execution at done. Use #, ;, or // for comments.

Interfacing I/O

Choose View → I/O configuration to attach a peripheral. Each interface connects through one 8-bit register, R3 in dedicated configurations. One attached interface leaves three registers for program calculations.

Read the device's displayed pin mapping before writing the program. Output bits drive the device; input devices update their assigned bits. Use masks such as ANDI R1, R3, 1 to read one input without changing the other bits.

  • None: disconnect peripherals and use all four registers for your program.
  • Dedicated configurations: selecting a device loads its matching ADEL example. If your assembly has unsaved file changes, a dialog asks before replacing it or changing the I/O.
  • Free play: select a device and register for each slot. Allow enough unassigned registers for your program, and use separate registers for independent input devices. Select None to leave a slot empty. The table uses R3; substitute the slot's assigned register.
Available I/O devices
DeviceRegister mappingHow to use it
8-bit LED bankR3[7:0] → LED7…LED0Write a byte. Each 1 lights its corresponding LED.
8 momentary pushbuttonsR3[7:0] = B7…B0 inputs, active highHold a button with the pointer, Space, or Enter. Read its bit; releasing the button clears it.
4 switches + 4 LEDsR3[7:4] = SW3…SW0 inputs; R3[3:0] = LED3…LED0 outputsToggle switches and read the high nibble. Write the low nibble to control the LEDs.
RGB LEDR3[5:4] = red; [3:2] = green; [1:0] = blue; [7:6] unusedWrite intensity 0–3 for each color channel.
2-digit 7-segmentR3[7:4] = left digit; R3[3:0] = right digitWrite a byte to display two hexadecimal digits, 00–FF.
Raw 7-segment digitR3 bits 0–6 = a…g; bit 7 = decimal pointSet individual segment bits to 1 to light them. This common-cathode digit uses a raw segment pattern.
8×8 LED matrixR3[7] = WR; [6] = pixel; [5:3] = row; [2:0] = columnSet the pixel and coordinates, then pulse WR from 0 to 1 to store one pixel in the 8×8 display.
Timer with displayR3[7] = RUN; [6] = RESET; [5:0] = prescaler PRUN increments the 32-bit count every P+1 CPU cycles. RESET has priority and clears count/phase. Pausing holds them; changing P clears the phase.
Ultrasonic distance sensorR3[7] = TRIG; [6] = READY; [5:0] = distance in cmSet the simulated distance from 0 to 63 cm (default 20). Pulse TRIG low → high to start a measurement. READY clears during measurement and rises after 2 + distance subsequent CPU cycles; then read bits 5–0.
Piezo / buzzerR3[7] = ON; [6:0] = frequency codeEnable a tone at 100 + 15 × code Hz. Clear ON to silence it. Press Step once to allow browser audio.
8-bit ADCR3[7:0] = ADC input codeMove VIN from 0 to 5 V. Read round(VIN / 5 × 255), from 0 to 255.
8-bit DACR3[7:0] = DAC output codeWrite 0–255 to set VOUT = code / 255 × 5 V.
8-channel relay boardR3[7:0] → K7…K0Set a bit to energize its relay and connect COM to NO. Clear it to connect COM to NC.
PWM outputR3[7] = enable; [6:0] = duty codeOne period lasts 127 CPU cycles; duty is code / 127 × 100%. Code 0 stays low and 127 stays high. Disabling resets phase and drives low.
Hobby servo motorR3[7] = enable; [6:0] = positionEnable to map codes 0–127 to 0–180°. Disabling holds the shaft at its last angle.
DC motor + H-bridgeR3[7] = enable; [6] = direction; [5:0] = speedDirection 0 is clockwise, 1 counterclockwise. Enabled speed 0–63 advances 0–12° per CPU cycle. Disabling or speed 0 stops motion.
4-coil stepper motorR3[3:0] = D, C, B, A coils; [7:4] unusedSend 1, 3, 2, 6, 4, 12, 8, 9 for successive half-steps. Reverse the sequence to reverse motion; 0 releases the coils.
4×4 keypadR3[7:4] = row outputs; [3:0] = column inputsDrive one row high, then read the columns while a key is held. Scan each row to identify the key.
Rotary encoder + LEDsR3[7] = A; [6] = B; [5] = PUSH; [4:0] = LED outputsDrag between 15° detents. Each detent sends a complete A/B cycle on a 400 ms phase timer, independent of the CPU. Use Run at 60 cyc/s to sample changes. Hold the knob for PUSH; bits 4–0 drive the LEDs.
8-bit shift registerR3[3] = DIR (1 output, 0 input bank); [2] = latch/capture; [1] = CLK; [0] = DATAFor output, set DATA before each rising CLK edge, then pulse latch/capture low → high to update the eight outputs. For input, pulse latch/capture to sample the input bank; read its MSB on DATA before each rising CLK edge.
16 × 4-bit memoryR3[7] = R/W; [6] = EN; [5] = ADDR; [4] unused; [3:0] = payloadWith ADDR=1, pulse EN low → high to latch an address. With ADDR=0, pulse EN to write (R/W=0) or read (R/W=1). Read data drives bits 3–0 while read EN stays high.
16×2 LCDR3[7] = BL; [6] = E; [5] = RW; [4] = RS; [3:0] = dataKeep RW=0. Select command/data with RS, send the high nibble then the low nibble, and pulse E high → low for each.
SPI flash memoryR3[3] = CS, active low; [2] = CLK; [1] = MOSI output; [0] = MISO inputSelect the flash with CS low. Use mode 0, MSB first: sample MISO on rising CLK edges. Send 9F then dummy bytes for ID 7F 32 01.
I²C temperature / light sensorR3[1] = SDA, 0 pulls low / 1 releases; [0] = SCLAddress 0x48 exposes temperature, light, and ID A5. Write a register pointer, then use repeated START to read. Release SDA explicitly for reads and ACK sampling; finish with NACK and STOP.

Step and Run execute instructions and advance clocked device state. Switches, buttons, and sliders can also update their input values while the processor is paused. Undo restores the preceding processor cycle and its saved device state.

Reset restarts the processor and power-cycles every I/O device. It clears matrix pixels, LCD text, RAM, counters, PWM phase, shift-register storage, and pending transfers. SPI flash returns to FF. Motor and rotary positions return to zero, pending rotary steps are canceled, and momentary inputs are released. Peripheral assignments, switches, ADC voltage, sensor settings, ultrasonic target distance, and external shift-register input pins are preserved. Active input devices then supply their current values.

File → Load Templates includes the examples available for the current I/O configuration. Peripheral mappings and examples use the same ADEL instruction set as the processor.

Simulator controls

ControlAction
FileCreate, load, or save assembly source; choose a template.
StepExecute one processor cycle while paused.
UndoRestore the previous cycle while paused.
BreakpointsClick an executable source line number to pause Run before that instruction. Click again to remove its breakpoint. Run continues past the current stop once; Step executes one instruction. Reset retains breakpoints. Editing, loading, or replacing the source clears them.
Run / PauseStart or pause continuous execution.
ResetReset the processor and I/O devices, clearing display data, device memory, counters, and pending transfers. Keep peripheral assignments and external input settings.
View → AppearanceChoose Light mode or Dark mode for the workbench and Assembly editor. The browser remembers your selection.
View → Simulation speedSet the continuous execution rate from 1 to 60 cycles per second.
View → Show datapathShow or hide the diagram. Attached I/O stays visible; Free play places its two peripherals side by side. Datapath animations are disabled while the diagram is hidden.
View → Datapath animationsToggle the flash effect on changing datapath values.

While paused, Right Arrow executes one cycle when focus is outside menus, dialogs, and form controls.

Drag a divider between the top panels to change their widths. Double-click a divider to restore the default widths.

Drag the horizontal bar below the top panels to change all three panel heights. You can also use the Assembly editor's bottom-right resize handle. Double-click the bar to restore the default height, which shows at least 13 assembly lines.

About this simulator

When we first introduced computer architecture to freshmen students in EEE 113, we used MARIE (Machine Architecture that is Really Intuitive and Easy). While it was designed to be simple, explaining state transitions and microcoded execution to students who had barely been introduced to digital logic is a little tricky to pull off. And for the curious ones who wanted to know what was actually happening inside the processor, many of its internal components remained abstracted away. It made me wonder: how can we expect students to understand how a processor works if they can't see what it's made of?

So I decided to try a different approach. What if we designed a processor so simple that every component could be traced back to the logic gates, flip-flops, and memories that students had just learned? No complicated control sequences, no hidden magic. Just a handful of registers, multiplexers, an ALU, and some control logic, all connected together to execute instructions. And thus, ADEL (Architecture Design that's Easy to Learn) was born.

With this simulator, I want students to go beyond simply writing programs and observing the results. I want them to see why each instruction works, follow the signals through the datapath, and realize that a processor isn't really as mysterious as it first seems. After all, even the most sophisticated processors are built upon the same fundamental building blocks. Sometimes, understanding something complex simply means starting with something simple.

— Adel

ADEL (Architecture Design that's Easy to Learn)

Architecture conceptualized by Adelson Chua.

Development is ongoing; feedback is appreciated!

From EEEI, UP Diliman, for EEE 113 students and anyone curious about what goes on inside a processor.

Feel free to explore, experiment, and learn how a processor really works!

Save your assembly changes?

Your Assembly editor has unsaved file changes.

This action replaces your current assembly. Save a file before continuing.

Choose I/O configuration

Fixed configurations use R3. Free play can map up to two peripherals to R0–R3.

Instruction encoding

How the selected assembly instruction becomes a 16-bit ADEL machine word.

Stepper motor reference

Four coil outputs · eight-phase half-step sequence

The port is R3 in dedicated mode, or the assigned register in Free play. Each output bit energizes one coil.

Coils and phases

Port bitCoilMeaning
[0]A1 energizes the coil; 0 releases it. Bits 7–4 are unused.
[1]B
[2]C
[3]D
Eight repeating coil patterns for half-step rotation The forward order is decimal 1, 3, 2, 6, 4, 12, 8, 9, then 1 again. Read the sequence backward to reverse rotation. Forward: move to the next pattern, then wrap to 1 AA+BBB+C CC+DDD+A 1326 41289 Reverse: visit the same adjacent patterns backward
The numbers are decimal coil masks. Holding a pattern holds position; each adjacent transition moves one half-step.

Move and hold

  1. Write a valid coil pattern to establish the initial phase.
  2. Write the next adjacent pattern for each forward half-step, or the previous pattern for reverse motion.
  3. Keep the current pattern to hold position. Write zero to release all coils.
ANDI R0, R0, 0   # Establish a constant zero.
ORI  R3, R0, 1   # A: establish the starting phase.
ORI  R3, R0, 3   # A+B: one forward half-step.
ORI  R3, R0, 2   # B: another forward half-step.
ORI  R3, R0, 3   # A+B: one reverse half-step.
hold:
BEQ  R0, hold    # Keep A+B energized and hold position.

The simulator uses 0.9° per half-step, or 400 half-steps per turn. The first pattern after release establishes a phase without movement. Skipped phases or invalid coil masks flag a sequence error and leave the position unchanged. Reset clears the error and position.

Add delay instructions between patterns to slow movement. The File → Load Templates example demonstrates a complete forward and reverse sequence.

4×4 keypad reference

Drive one row · read the active column

The port is R3 in dedicated mode, or the assigned register in Free play. The upper nibble drives rows; the lower nibble reads columns.

Rows, columns, and key labels

Row outputCOL0
bit 0 · 01
COL1
bit 1 · 02
COL2
bit 2 · 04
COL3
bit 3 · 08
ROW0 · bit 4 · 10123A
ROW1 · bit 5 · 20456B
ROW2 · bit 6 · 40789C
ROW3 · bit 7 · 80*0#D

Masks in the table are hexadecimal. Rows run from top to bottom; columns run from left to right. Signals are active high.

For key 5, drive 20 to select ROW1. While the key is held, COL1 reads high and the port reads 22.

Scan a key

  1. Write one row mask: 10, 20, 40, or 80.
  2. Read the low nibble with ANDI and mask 0F. A held key in the selected row sets its column bit.
  3. If the result is zero, select the next row. Combine the selected row and returned column to identify the key.
  4. After accepting a key, keep scanning its row until the columns return to zero. This counts one event per press.
# Poll key 5 in the second row; R2 records its column mask.
ANDI R0, R0, 0   # Establish zero for constants and branches.
ANDI R2, R2, 0
poll:
ORI  R3, R0, 32  # 0x20: drive ROW1 only.
ANDI R1, R3, 2   # 0x02: test COL1, the column of key 5.
BEQ  R1, poll    # Wait until key 5 is held.
ANDI R2, R3, 15  # Save the returned column mask (0x02).
release:
ANDI R1, R3, 15
BNE  R1, release # Wait for release before accepting another press.
BEQ  R0, poll

The simulator models one held key at a time. Use File → Load Templates for a complete four-row scanner.

Rotary encoder reference

15° detents · independent A/B timing · five LED outputs

The port is R3 in dedicated mode, or the assigned register in Free play. Drag the outer ring between 15° detents. Hold the center knob for PUSH.

Port signals

Port bitsSignalUse
[7], [6]A, B inputsRead both together with mask C0 to identify their phase.
[5]PUSH inputMask 20 reads high while the knob is held.
[4:0]LED4…LED0 outputsWrite a five-bit value; each set bit lights its LED.

From a detent to A/B transitions

The knob snaps to 24 positions per turn. Each snap queues one complete A/B cycle; queued cycles run in order, including after mouse release.

Clockwise quadrature waveform The A and B pair follows 00, 01, 11, 10, 00 for clockwise rotation. B rises before A. Each emitted phase uses a 400 millisecond wall-clock timer, including the final idle phase. CPU speed and pausing do not control the timer. A · bit 7B · bit 6 0001111000 Idle400 ms400 ms400 ms400 ms Counterclockwise: 00 → 10 → 11 → 01 → 00
Read A/B as a pair. Masked port values in hexadecimal are 00, 40, C0, 80, 00 for clockwise motion.

Each phase uses a 400 ms wall-clock timer, including the final 00 interval. A/B continues changing while the CPU is paused. Changing simulation speed changes how often your program samples the inputs.

Capture a complete step

  1. Wait for idle 00 before accepting a new step.
  2. Read A/B together with mask C0. Keep the previous phase and direction in the program's control flow.
  3. Ignore repeated samples. Follow adjacent phases in the chosen direction, including any reversal back through previous phases.
  4. Count once when a complete valid sequence returns to 00.
  5. If a phase jump is invalid, discard the incomplete step and wait for 00 to synchronize again.

The File → Load Templates example implements this state machine and resets the five-LED count when PUSH is held.

Use Run at 60 cyc/s for the best capture. A faster simulation gives the polling loop more samples per phase. Slow execution can miss transitions; polling cannot recover a complete cycle that passed between samples. Use Step to inspect the instructions and Run to capture rotation.

Read inputs and write LEDs

ANDI R1, R3, -64 # 0xC0: sample A and B together.
ANDI R2, R3, 32  # 0x20: sample PUSH separately.
ANDI R0, R0, 0   # Prepare an LED value.
ORI  R0, R0, 5   # 00101 lights LED2 and LED0.
ANDI R3, R3, -32 # 0xE0: Preserve input bits and clear the five LED bits.
OR   R3, R3, R0  # Apply the LED value.

These instructions show individual port operations. The full template uses the same atomic A/B reads while validating the complete phase sequence.

16 × 4-bit memory reference

Latch an address · transfer a four-bit value

The port is R3 in dedicated mode, or the assigned register in Free play. Sixteen locations each store one nibble, from 0 to 15.

Control bits and shared payload

Port bitsSignalAction
[7]R/WData phase: 0 writes; 1 reads.
[6]ENA rising edge commits one address or data transfer.
[5]ADDR1 selects address capture; 0 selects data transfer.
[4]UnusedKeep this bit zero for simple commands.
[3:0]PayloadAddress 0–15 during address capture; data 0–15 during a write or read.
Address capture followed by a data transfer With ADDR high, prepare an address while EN is low and raise EN to capture it. Lower EN, select ADDR low and the read or write direction, then raise EN to transfer data at the stored address. 1. Latch addressADDR=1 · payload=addressEN: 0 → 1 2. Transfer dataADDR=0 · R/W=0 or 1EN: 0 → 1 Lower EN between transfers. The selected address stays latched for later reads or writes.
ADDR chooses how the shared payload is used. R/W controls only the data phase; address capture accepts either R/W level.

Write, then read the same location

  1. Set ADDR=1 and place the address in bits 3–0 with EN low. Raise EN to latch the address.
  2. Lower EN. Set ADDR=0, R/W=0, and the data nibble. Raise EN to write the selected location.
  3. Lower EN. Keep ADDR=0 and set R/W=1. Raise EN to load the selected cell into the read latch.
  4. While read EN stays high, read bits 3–0 with mask 0F. Lower EN before the next transfer.
# Store 9 at address 3, then read it into R2.
ANDI R0, R0, 0   # Establish zero for command constants.
ORI  R3, R0, 35  # 0x23: ADDR=1, EN=0, address=3.
ORI  R3, R0, 99  # 0x63: EN rises and captures address 3.
ORI  R3, R0, 9   # 0x09: EN=0, ADDR=0, R/W=0, data=9.
ORI  R3, R0, 73  # 0x49: EN rises and writes 9.
ORI  R3, R0, -128 # 0x80: EN=0, ADDR=0, R/W=1.
ORI  R3, R0, -64 # 0xC0: EN rises and captures read data.
ANDI R2, R3, 15  # R2=9; strip the control bits.
ANDI R3, R3, -65 # 0xBF: lower EN to finish.
done:
BEQ  R0, done

Holding EN high performs one transfer. The read latch drives only bits 3–0 while R/W=1, EN=1, and ADDR=0. Reset clears all sixteen cells, the selected address, and the read latch.

Shift-register GPIO reference

Eight pins · one direction for the whole bank

The port is R3 in dedicated mode, or the assigned register in FreePlay. Its four control bits operate the separate GPIO bank, P7…P0.

Control bits

Port bitSignalAction
[3]DIR1: all eight GPIO pins are outputs. 0: all are inputs and their toggles are editable.
[2]LATCH / CAPRising edge: output mode copies the shift byte to the pins; input mode captures the eight pins.
[1]CLKRising edge: shift one bit. Lower CLK before the next bit.
[0]DATAOutput mode: bit to shift in. Input mode: captured bit to read.

Output: shift first, latch once

Shift eight serial bits, then latch them onto eight GPIO outputs In output mode, DATA enters bit zero at the right. Rising clock edges move existing bits toward bit seven at the left. The example shift byte is A5, binary 10100101. A separate rising LATCH edge copies all eight bits to the GPIO pins. DIR=1: CLK↑ shifts toward bit 7 SHIFTGPIO 7 1 1 6 0 0 5 1 1 4 0 0 3 0 0 2 1 1 1 0 0 0 1 1 DATA LATCH↑ copies all eight bits A5 = 10100101; pins change only when LATCH rises
Send the most-significant bit first. Each CLK rising edge shifts left and inserts DATA into bit 0. A separate LATCH rising edge updates all eight pins together.
  1. Write port 08: DIR=1, CLK=0, LATCH=0.
  2. Send bits 7 through 0. Set DATA while CLK is low, then pulse CLK high → low for each bit.
  3. Keep CLK low and pulse LATCH high → low. The pins now show the completed byte.
# One output bit, then a separate latch pulse (R0=0):
ORI R3, R0, 9     # DIR=1, DATA=1, CLK=0
ORI R3, R0, 11    # CLK rises: shift this bit
ORI R3, R0, 9     # CLK falls
# Use 8,10,8 for a 0 bit; send all eight bits before latching.
ORI R3, R0, 13    # LATCH rises: update the GPIO pins
ORI R3, R0, 9     # Lower LATCH

Input: capture, read, then clock

  1. Write 00 to select input mode. Set the GPIO pin toggles.
  2. Write 04, then 00 to pulse CAP. This snapshots all pins and immediately exposes captured bit 7 on DATA.
  3. Read DATA before raising CLK. A CLK rising edge advances to the next captured bit. Collect eight bits, most-significant first.
  4. Pulse CAP again to read a new pin pattern. Toggle changes after capture apply to the next snapshot.
# One input bit after CAP, with R0=0:
ANDI R1, R3, 1   # Read the current captured bit
ORI  R3, R0, 2   # CLK rises: advance to the next bit
ORI  R3, R0, 0   # CLK falls; repeat for the next sample

DIR selects the whole bank. Changing direction alone does not shift or capture data. CAP/LATCH takes priority if it rises together with CLK; pulse the controls separately for clear transfers. After eight input shifts, DATA becomes zero until a new capture.

SPI flash reference

Mode 0 · MSB first · one 256-byte flash

The port is R3 in dedicated mode. In FreePlay, use the register assigned to the SPI peripheral. Software writes create the clock edges.

Connect the four signals

Port bitSignalMeaning
[3]CSOutput. 0 selects the flash; 1 ends the transaction.
[2]CLKOutput. Idle low; each rising edge transfers one bit.
[1]MOSIOutput. Command, address, or data sent to the flash.
[0]MISOInput. Data returned by the flash. Mask with 0x01.

Begin with CS=1, CLK=0 (port 0x08), then lower CS. Set MOSI before raising CLK. Sample MISO while CLK is high, then lower CLK. Transfer bit 7 first.

What one byte looks like

SPI mode 0: transmitting command 9F CS is low throughout eight clock pulses. CLK starts low. Rising edges sample MOSI bits 1,0,0,1,1,1,1,1, from bit seven to bit zero. MISO returns FF during the command byte. CS stays low for the following dummy bytes that clock out the ID. CS CLK MOSI MISO CS stays low for the reply 1 0 0 1 1 1 1 1 FF during the command byte ↑ sample ↑ sample bit 7 → bit 0
Command 0x9F = 10011111. Dotted lines mark the eight rising sampling edges. The flash returns FF during this command. Keep CS low while clocking the following ID bytes.

Mode 0 means CPOL=0, CPHA=0: clock low between transfers, capture on rising edges, prepare the next data bit on falling edges. See Microchip’s SPI timing reference.

# One bit with CS selected and R0=0:
ORI  R3, R0, 2    # CLK=0, MOSI=1
ORI  R3, R0, 6    # CLK rises
ANDI R1, R3, 1    # Read MISO into R1
ORI  R3, R0, 2    # CLK falls

Commands implemented by this flash

First byteFollowing bytesResult
9F · IDClock dummy bytes.MISO returns 7F 32 01, repeating if clocking continues.
03 · ReadThree address bytes, high first; then dummy bytes.MISO returns consecutive flash bytes.
06 · Write enableRaise CS.Sets the write-enable latch (WEL).
04 · Write disableRaise CS.Clears WEL.
05 · StatusClock dummy bytes.Returns 02 if WEL is set, otherwise 00.
02 · ProgramThree address bytes, then data bytes; raise CS.With WEL set, commits complete data bytes and clears WEL.

During a read, dummy MOSI bytes supply clocks. Only the returned MISO bytes after the command/address are the requested data.

Read ID, with CS low for all four bytes:
MOSI:  9F  00  00  00
MISO:  FF  7F  32  01

Program one byte, then read it back

  1. Send 06 in its own CS-low transaction; raise CS to set WEL.
  2. Lower CS and send 02 00 00 10 A5. Raise CS to program address 0x10.
  3. Lower CS and send 03 00 00 10 00. The final received byte is A5 when the location began as FF.

Model limits: Flash starts at FF. A 24-bit address uses its low eight bits to select storage; sequential accesses wrap through 256 bytes. Programming applies old AND new, so it clears bits. Reset restores FF; erase commands and busy delays are not modeled. An incomplete final byte is discarded; earlier complete program bytes still commit. WEL clears only when data commits.

I²C sensor reference

Two wires · address 0x48 · temperature, light, and ID

The port is R3 in dedicated mode. In FreePlay, use the register assigned to the I²C peripheral. ADEL is the controller (master); the sensor is the target.

Drive or release SDA

Port bitSignalMeaning
[1]SDAWrite 0 to pull the data line low. Write 1 to release it. Reads return the resolved line level.
[0]SCLClock output. 0 is low; 1 is high.

Released SDA can still read low. SDA reads 0 when the sensor pulls it low, even if software last wrote 1. Keep SDA released during sensor ACKs and incoming data.

Port value:  0 = SDA low,      SCL low
             1 = SDA low,      SCL high
             2 = SDA released, SCL low
             3 = SDA released, SCL high

Initialize the idle bus with port value 3, then write 1 to make START: SDA falls while SCL stays high. Write 0 to lower SCL before sending the first address bit.

Use explicit values 2 and 3 for ACK and read clocks, for example ORI R3,R0,3 with R0=0. Copying a sampled SDA=0 back into the output can hold the line low. The simulator keeps the output request separate from the sampled input.

START, eight bits, ACK, STOP

I2C address byte 90 with a ninth-clock ACK SDA falls while SCL is high to make START. Eight rising clocks transfer 1,0,0,1,0,0,0,0. On the ninth clock the controller releases SDA and the sensor holds it low for ACK. SDA rises while SCL is high to make STOP. SCL SDA 1 1 0 2 0 3 1 4 0 5 0 6 0 7 0 8 START STOP 9 0 ACK 0x90 = address 0x48 + write bit 0 sensor drives 0
0x90 = 10010000 sends seven-bit address 0x48 with the write bit. The controller releases SDA for clock 9; the sensor pulls it low to acknowledge.
  • START: SDA falls while SCL stays high. STOP: SDA rises while SCL stays high.
  • Send eight bits, most significant first. Keep data stable while SCL is high.
  • Clock 9 is the receiver’s reply: SDA low is ACK; released/high is NACK.
  • After a sensor data byte, the master drives ACK=0 to request another byte, or releases SDA for NACK=1 to finish.

These timing terms follow NXP UM10204, sections 3.1.1–3.1.6. The sensor registers below are specific to this simulator.

Select a register, then read it

The seven-bit address is 0x48. Append a direction bit: 0x90 writes and 0x91 reads. The first byte after a write address selects the register pointer.

START → 90 → ACK → 04 → ACK
repeated START → 91 → ACK → A5 → master NACK → STOP
  1. Send START, address 90, and pointer 04. Release SDA and check the sensor’s ACK after each byte.
  2. Issue another START without a STOP. This repeated START retains the pointer. Send read address 91 and check its ACK.
  3. Release SDA for all eight read clocks. Shift the sampled bits into a byte: ID A5 = 10100101.
  4. Release SDA on the ninth clock to send NACK, then send STOP. For multiple bytes, send master ACK between bytes and NACK after the last.
# STOP after a read, with R0=0:
ORI R3, R0, 0    # SDA low while SCL is low
ORI R3, R0, 1    # Raise SCL, keep SDA low
ORI R3, R0, 3    # Release SDA while SCL stays high

Read-only sensor bytes

PointerByteExample at 22.5 °C and light 420
00Temperature low byte2D
01Temperature high byte00: signed 0x002D ÷ 2 = 22.5 °C
02Light low byteA4
03Light high byte01: unsigned 0x01A4 = 420
04IdentificationA5

Read low byte first, then high byte. Interpret temperature as a signed 16-bit two’s-complement value divided by two. Light is unsigned. Change measurements with the peripheral’s controls.

Model limits: Only address 0x48 acknowledges. A write transaction accepts one pointer byte; additional data bytes receive NACK and do not alter measurements. Each completed read advances the eight-bit pointer, including the final NACK. Other pointer values return 00. This single-controller model omits clock stretching and arbitration.

16×2 LCD command & ASCII reference

Commands supported by this simulator's HD44780-style 4-bit interface.

Supported commands (RS = 0)

CommandMeaningSimulator behavior
0x01Clear displayFills both 16-character lines with spaces and returns the write address to line 1, column 1.
0x02Return homeMoves the write address to line 1, column 1 without erasing any characters already stored.
0x04Entry mode: decrementAfter each ASCII character is written, the address moves one position backward. The simulator wraps between the two visible lines.
0x06Entry mode: incrementAfter each ASCII character is written, the address advances one position. This is the normal mode for left-to-right text.
0x08Display offHides the characters without clearing display memory. A later display-on command shows the stored text again.
0x0CDisplay onShows the stored characters. Cursor and blink bits are not visually modeled.
0x80–0x8FSet line 1 address0x80 selects column 1 and 0x8F selects column 16 of the first line.
0xC0–0xCFSet line 2 addressLine 2 uses DDRAM addresses 0x40–0x4F; therefore 0xC0 selects line 2, column 1 and 0xCF selects column 16.

Printable ASCII data (RS = 1)

Send printable ASCII bytes 0x20–0x7E. The character is written at the current LCD address, then the address moves according to the selected entry mode. Each byte still uses two 4-bit transfers: high nibble first, then low nibble.

Hex0123456789ABCDEF
2xSP20!21"22#23$24%25&26'27(28)29*2A+2B,2C-2D.2E/2F
3x030131232333434535636737838939:3A;3B<3C=3D>3E?3F
4x@40A41B42C43D44E45F46G47H48I49J4AK4BL4CM4DN4EO4F
5xP50Q51R52S53T54U55V56W57X58Y59Z5A[5B\5C]5D^5E_5F
6x`60a61b62c63d64e65f66g67h68i69j6Ak6Bl6Cm6Dn6Eo6F
7xp70q71r72s73t74u75v76w77x78y79z7A{7B|7C}7D~7E—