Syscall 2: Firmware, home

BenchChapter 11: Capstones

B89UART

The task

Send the knob's reading out of P1 as serial, one bit per tick of P2, in frames of 16 ticks.

A frame starts where the tick count from IN P2, MOD 16, is 0. Send a 0 there: the start bit.

Then send the reading's 7 bits, lowest first, and hold P1 high for the rest of the frame.

Read the knob on the start tick. The line rests high, a 1 is high, and a 0 is low.

The board

The chip of UARTChip u1 with 3 ports: P0 analog in, reaching V1, CH1; P1 digital out, reaching R1, D1, CH2; P2 timer 20 cycles.u1CHIP SC-2P0ANALOG INV1, CH1P1DIGITAL OUTR1, D1, CH2P2TIMER 20 CYCLES
The chip's ports, each with its kind and the parts its signal reaches. Cyan reads, lemon writes. On a narrow screen, scroll the board sideways to see all of it.
Sources
V1 3.5 V, V2 2 V square at 12.5 Hz, and V3 1 V square at 6.25 Hz
Resistors
R1 330 Ω
LEDs
D1 yellow
Probes
CH1 and CH2

Key idea

IN P2 returns the running tick count, so MOD 16 tells you where you are in the frame.

Hints

Each hint goes a step further than the one before. Open them one at a time.

Hint 1Show

Keep 127 minus the reading in B: shifted out, it gives each bit flipped, then 0 once spent.

Hint 2Show

A flipped bit minus 1 is nonzero for a 1 and 0 for a 0, and a spent B then reads high.

Solution

Reveal the Full SolutionThe complete program for UART. Open it only when you want the answer.

The reference program

The game's own solution. It passes every test and scores exactly par on every benchmark.

Start bit, seven data bits, and a line that rests high.

u1SC-2 standard

L: IN P2
MOD 16
JZ ST
MOV A, B
DIV 2
XCH
MOD 2
SUB 1
OUT P1
JMP L
ST: OUT P1
IN P0
NEG
ADD 127
MOV B, A
CYCLES
783
at par
ENERGY
1566
at par
NODES
1
at par
INSTRUCTIONS
15
at par