ci / linux-arm64 (push) Successful in 10m23s
hardware/bringup.md is the first hands on step: two 74LS161 counters for the low eight address bits, a 28C256, and eight lamps showing the fetched byte. It has the bill (80 to 120 CNY), a pin by pin table for both counters and the ROM, the reset network, three clock options (button, 74LS14 RC at 5 Hz, 1 MHz only later), how to burn the chip, what you should see, and the six things that usually go wrong. Two decisions recorded there: use a 28C256 EEPROM for bring up and keep the 27C512 UV part for later, because erasing for twenty minutes per fix kills debugging; and do not test with hello, which starts with a run of moves that light nothing -- the note gives a 16 instruction test tape that walks all eight opcodes so the lamp patterns differ. Also added: r8forge_tape_pack --raw writes the payload without the sixteen byte trailer, which is what a ROM burner wants; --verify checks the length instead of decoding a trailer that is not there any more. hardware/bringup.png is a block diagram (clock to counters, carry chain, address buses into the ROM, data bus to the lamps), not a breadboard top view: the first attempt at a placement picture came out as a drawer of unlabelled parts and said less than the pin table.
5.2 KiB
5.2 KiB
面包板第一块:ip 计数 + 取指 + 数据灯
目标:用最少的件看见机器在取指 —— 上电后,数据灯显示 ROM[0] 的字节,每来一个时钟地址 +1、数据灯变成下一条指令。这一步通了,后面才谈数据通路。
预计一个下午。器件约 ¥120。
1. 器件
| 件 | 数量 | 说明 | 约价 |
|---|---|---|---|
| 28C256(32K×8 EEPROM,DIP-28) | 1 | 调试阶段用它:5 V 就能烧,不用紫外线擦 ✗ 比 27C512 方便得多 | ¥12 |
| 74LS161 | 2 | ip 低 8 位 |
¥4 |
| 74LS14 | 1 | 复位去抖 + 慢速时钟(RC 振荡) | ¥2 |
| LED(红) | 8 | 数据灯 | ¥2 |
| 330 Ω | 8 | LED 限流 | ¥1 |
| 10 kΩ | 2 | 上拉 / RC | ¥0.5 |
| 100 nF | 2 | 去耦 / RC | ¥0.5 |
| 轻触按钮 | 2 | RESET、CLOCK(手动单步) | ¥2 |
| 面包板 830 孔 | 2 | 28 脚 DIP 要跨两块板(0.6 英寸宽) | ¥20 |
| 杜邦线 | 1 包 | ¥8 | |
| 5 V 2 A 适配器 | 1 | 或 USB 电源 | ¥25 |
| 合计 | ≈ ¥80~120 |
为什么用 28C256 而不是 27C512:两者都是 DIP-28、引脚兼容(A0..A14 / D0..D7 / ~CE / ~OE / ~WE),但 28C256 是 EEPROM,CH341A 直接烧;27C512 要紫外擦片器,改一次 20 分钟 —— 调试阶段 会疯掉。等机器稳定了再换 27C512 走"仪式"。
2. 接线表
74LS161 #1(ip[3:0])
| 脚 | 名 | 接到 |
|---|---|---|
| 1 | ~MR |
RESET 网络(10 kΩ 上拉到 5 V + 按钮到 GND + 100 nF 到 GND) |
| 2 | CP |
CLOCK(见 §3) |
| 3–6 | A B C D |
GND(不用预置;悬空会被预置成随机值) |
| 7 | CEP |
5 V |
| 10 | CET |
5 V |
| 9 | ~PE |
5 V |
| 11–14 | QA QB QC QD |
A0 A1 A2 A3(到 ROM) |
| 15 | TC |
到 #2 的 CET |
74LS161 #2(ip[7:4])
与 #1 相同,除了:
| 脚 | 名 | 接到 |
|---|---|---|
| 10 | CET |
#1 的 TC(15 脚) |
| 11–14 | QA..QD |
A4 A5 A6 A7 |
28C256(ROM)
| 脚 | 名 | 接到 |
|---|---|---|
| 1–10 | A0..A9 |
A0..A7 来自计数器,A8 A9 → GND |
| 11–13 | A10 A11 A12 |
GND |
| 14 | GND |
GND |
| 15–22 | D0..D7 |
数据灯(见 §2.4) |
| 23–25 | A13 A14 A15 |
GND |
| 26 | ~CE |
GND(常选中) |
| 27 | ~OE |
GND |
| 28 | VCC |
5 V |
| 1 | ~WE |
5 V(只读!接低会改写片子) |
引脚 1 在 28C256 上是
~WE(不是 A14),别接错:接低就成了写模式,上电瞬间会毁数据。
数据灯
D0..D7 → 330 Ω → LED → GND,8 组。LED 长脚朝 ROM。
复位网络
5 V ── 10 kΩ ──┬── ~MR(两片 161 的脚 1)
├── 按钮 ── GND
└── 100 nF ── GND
3. 时钟:先手动,再自动
调试时不要接 1 MHz —— 灯会糊成一片,看不出东西。
- 手动单步:一个按钮从 5 V 到
CP,串 100 nF 到 GND(RC 去抖),每按一下走一条指令 ✓ - 自动慢速:74LS14 的 RC 振荡,
R = 100 kΩ, C = 1 µF→ 约 5 Hz,肉眼能数 ✓ - 想看"真实的机器"再换 1 MHz 罐头晶振(那时就该上示波器了)。
4. 烧片子
# 1) 汇编出一条纸带
build/Release/r8forge examples/hello.r8asm > hello.rot8
# 2) 打成"一条指令一字节"的裸镜像(--raw 去掉 16 字节 trailer)
build/Release/r8forge_tape_pack hello.rot8 -o hello.bin --eprom --raw --verify
# hello.rot8: 727 instructions -> 727 bytes (100% of the text form), verified
# 3) CH341A 烧进 28C256(minipro / 官方软件都行)
注意:镜像里第 n 个字节就是第 n 条指令,低 3 位是操作码、高 5 位是 0 —— 所以数据灯上
只会看到 00..07 的字节,这是对的 ✓
5. 预期现象
| 操作 | 应该看到 |
|---|---|
| 上电 / 按 RESET | 数据灯 = ROM[0] 的字节(hello 是 > = 0x00 → 全灭 ✗ 不好看) |
| 每按一次 CLOCK | 地址 +1,数据灯变成下一条 |
| 按 RESET | 回到 ROM[0] |
别用
hello做第一次测试:它开头是一串>(0x00),灯全灭,看不出来 ✗。 用一个手写的测试纸带,让前 16 条都是不同的操作码:
-+.>-+.<-->+<.[-]
(这样每个字节 0..7 都会出现,8 颗灯的模式一眼能分辨 ✓)
6. 常见故障
| 现象 | 大概原因 |
|---|---|
| 数据灯全灭 | ~OE/~CE 没接低;或 ~WE 被接了低 |
| 数据灯全亮 | 数据线接反 / ROM 没插好 |
| 地址不跳 | CP 没接;或 CEP/CET/~PE 没拉高(74LS 输入悬空 = 高,但不可靠) |
| 地址乱跳 | A B C D 悬空,161 会预置成随机值 ✗ 必须接 GND |
| 按一下跳好几格 | 按钮没去抖(加 100 nF 或 74LS14) |
| 上电就乱 | 复位脉冲太短;把 100 nF 加大到 1 µF |
7. 通了之后
- 加 6116 + 74LS299:数据环 + 当前格寄存器(跑
-再+,看灯的位模式); - 加
dp计数器:跑><的纸带; - 加 微码 + 拍计数器:把前面几步串成一条指令流;
- 最后才是栈、串口、面板。
这一步的唯一目的:把"取指"这件事从抽象变具体。 8 颗灯跟着纸带一格一格变,比看 500 行 Verilog 有用得多。