1. Reasons Why the Microcontroller Cannot Download Programs
1. Check if the hardware connections are correct, and if the power supply is connected properly. On the correct basis, is there any broken line on the board? Pay attention to whether P1.5, P1.6, P1.7, the RST pin, and the download interface are connected correctly. By the way, if P1.5, P1.6, and P1.7 are used for other purposes, it may also cause download failures. I had a ds18b20 connected to P1.7, and it was always unable to detect the device. Additionally, when the download cable was connected to the board, the ds18b20 could not measure temperature and always displayed 0000000.
2. Is the power supply ripple too large? If it is too large, don’t forget to add bypass capacitors, a 100uF electrolytic capacitor in parallel with a 104 ceramic capacitor will do.
3. Is the microcontroller reset circuit correct? Can it ensure that the reset circuit resets the microcontroller once when powered on? If the reset circuit is correct, please check the resistance value of the reset circuit. This must not be ignored. Just a few days ago, I made this mistake; the reset resistor should not be less than 1K because if it is too small, the capacitor discharges too quickly, causing the high level at the microcontroller’s RST pin to last too short a time, leading to a failure to reset on power-up, thus preventing the program from downloading. A few days ago, I mistakenly used a 120-ohm resistor instead of a 10K one (because the color bands of the two are indistinguishable), and it took me many checks to figure out what was wrong. Hehe, don’t laugh at me for being a newbie.
4. I haven’t tried whether it can download without a crystal oscillator, but it seems that CPLDs can download programs without a crystal.
5. If there are large external loads, such as motor driver circuits, it can sometimes also cause program download failures, even if they do not share the same power supply.
6. Another careless mistake is that the microcontroller is not seated properly. I encountered this while debugging CAN. Communication was fine initially, but after I returned from a late-night snack, it kept failing. After checking for a long time and complaining, I could only lament my bad luck. The next day, feeling that it was a pity to be this unlucky, I touched the microcontroller and found it was slightly loose. After reseating it, the SJA1000 was able to communicate normally again. What a shock! If this happened during the defense, it would have been disastrous! Details determine strength; I have deep experience with this.
7. If the computer’s static voltage is too high, it can cause the microcontroller not to work, and naturally, it cannot download. My computer has a lot of static; it shocked me quite a bit.
2. Reasons Why the Microcontroller Can Download Programs but Cannot Execute Them
1. It is very likely that the EA pin of the microcontroller is not connected to VCC. It can download programs without being connected (and ALE will output half of the crystal frequency) — I wrote this wrong; I must have been too tired and confused, sorry. A senior pointed out that it is usually one-sixth — why am I always so careless?! Connecting EA to VCC means executing internal code; if not connected, it executes external ROM programs. We rarely use external EEPROMs now, so EA must be connected to VCC.
3. Microcontroller Anti-Interference Design
1. When we use the microcontroller timer to measure the frequency of a square wave, if the microcontroller has not been programmed, the square wave is good and standard. However, after programming, the shape of the square wave becomes unrecognizable, with a lot of noise. This can be frustrating. I suggest adding a 4.7K pull-up resistor and paying attention to the power supply filtering and bypassing in front. For low requirements, these two tricks can solve the issue. For higher requirements, isolate the two modules using optocouplers and use independent power supplies to reduce interference. Also, a pull-up resistor must be added to the P0 port.
2. When driving external high-power devices, always use optocouplers for isolation and independent power supplies; otherwise, the microcontroller may crash. A senior participated in the Guangxi Electronic Design Competition and was measuring liquid levels without using optocouplers for isolation, while also using the same power supply. As a result, the microcontroller kept crashing, and the digital tube flickered, which led to no output.
The above are all very novice experiences; I hope to receive criticism and guidance.
