bit·dojo CH32V003 register practice

bit-dojo: learn bitwise register tricks on a CH32V003

A free, interactive game for learning the bitwise operations embedded C is built on. Write real register code, such as GPIOC->CFGLR |= (GPIO_Speed_10MHz | GPIO_CNF_OUT_PP) << (4*1);, against a simulated CH32V003 RISC-V microcontroller, and see every bit change.

What you practise

24 levels in 5 chapters

Bits & hex

  1. 1. One bit — Write an expression with only bit 5 set.
  2. 2. A nibble mask — Write a mask with bits 4, 5, 6 and 7 set — nothing else.
  3. 3. Everything but — Write a value with every bit set except bits 4-7.
  4. 4. Place a field — Put the 4-bit value 0b1001 into bits 8-11 (everything else 0).

Set · clear · toggle · test

  1. 5. Set a bit — Set bit 3 of reg. Leave every other bit alone.
  2. 6. Clear a bit — Clear bit 7 of reg. Leave every other bit alone.
  3. 7. Toggle a bit — Flip bit 0 of reg: 0 → 1, 1 → 0. Others unchanged.
  4. 8. Test a bit — Write an expression that is true (non-zero) exactly when bit 2 of reg is 1.
  5. 9. Two at once — Set bits 1 and 6 of reg, and clear bit 0. Others unchanged.

Fields

  1. 10. Clear a field — Clear bits 4-7 of reg (make them 0000). Others unchanged.
  2. 11. Write a field — Make bits 4-7 of reg hold the value 9 (0b1001). Others unchanged.
  3. 12. Read a field — Store the value of bits 8-11 of reg into val (as a number 0-15).

Real CH32V003 registers

  1. 13. Wake up port C — Turn on the clock for GPIOC. Don't disturb the other peripherals.
  2. 14. PC1 as output — Configure PC1 as a 10 MHz push-pull output. Other pins keep their setup.
  3. 15. LED on with BSHR — Drive PC1 high using GPIOC->BSHR. Other outputs unchanged.
  4. 16. LED off with BSHR — Drive PC1 low using GPIOC->BSHR. Other outputs unchanged.
  5. 17. From reset to light — Starting from reset: light the LED on PC1. Don't break anything else.
  6. 18. Button input — Make PD2 an input with the internal pull-up enabled.
  7. 19. Is it pressed? — Write an expression that is true when the button on PD2 is pressed.

Bug hunt

  1. 20. Where did the UART go? — This enables GPIOC but kills the serial port. Fix it.
  2. 21. The LED won't light — PC1 should be a 50 MHz push-pull output. The LED stays dark. Fix it.
  3. 22. Never pressed — This should be true when PD2 is pressed, but it never is. Fix it.
  4. 23. Silent port — Perfect-looking code, dark LED. Fix it.
  5. 24. Bit 31 — Set bit 31 of reg — without undefined behaviour.

Open the sandbox to experiment with a whole simulated chip.

Cheat sheet

About

bit-dojo logo
bit·dojo v0.1.0

Learn the bitwise tricks embedded C runs on by writing real register code for a simulated CH32V003 RISC-V microcontroller.

🤖 Vibe-coded with Claude Code in September 2026: the simulator, levels, visualizer, logo and tests were all written by Claude, directed by e-labInnovations.

Register layouts and macro values follow ch32fun. Your progress is saved only in this browser. MIT licensed.