This is a small toy with a very simple circuit. I haven't touched a 51 microcontroller in a long time; I bought quite a few 51s and STM8s that have been gathering dust. I made a small tool to use them.
The microcontroller reads the I/O port voltage via ADC, converts the voltage into a PWM output with a fixed duty cycle to drive a MOSFET. The recommended operating voltage is 6.5V-20V (maximum 35V; LDOs seem to be 35V, be aware of high voltage difference causing overheating).
You can choose a suitable MOSFET; this one can withstand up to 60V, but it's unnecessary to use such a high voltage. This one was chosen mainly because it's cheap, costing around 30 cents. If you have the resources, you can use an easier-to-drive one.
Considering the microcontroller's driving capability isn't very good, the output frequency is set relatively low to reduce switching losses, but you definitely won't see flickering when driving LEDs.
Note: There is no reverse connection protection; pay attention to polarity.
The output was tested using three 10R 3W metal film resistors connected in parallel, equivalent to 3.3R. With a 12V power supply and a duty cycle set to around 60%, the board did not overheat. Currently, I don't have a motor on hand. If you have LEDs, I recommend connecting a small resistor in series.

Adjust the PWM


using a potentiometer. ... For programming, use STC_ISP. Download link: https://download.ihsdus.cn/down/2022down/1/21/TCICP.rar?timestamp=655c6678&auth_key=1d8fd78df58a3b8e9e9f7be34fc1ff5a
After opening, please set the parameters as shown in the image. You can then use any serial port programming tool to program it.
To program the circuit board, connect the DuPont wires to +5V GND RXD TXD. Configure the serial port as shown in the image, paying attention to the selected options. Refer to the tutorial: https://zhuanlan.zhihu.com/p/593000651.
Finally, connect the wires according to the silkscreen markings on the board.