In the past, when programming microcontrollers, the most annoying thing was that every time you downloaded a program, you had to cut off the power, click download, and then power on to download the program to the microcontroller. If this operation happened once or twice, it was tolerable, but often we need to debug the code and perform download operations multiple times. Constant power off and on is undoubtedly a great damage to the microcontroller.
According to the data sheet of stc12c5a60s2 (an enhanced 51 MCU, compatible with stc89c52 MCU), the MCU system can be soft reset to make the MCU run the system startup code (this part of the code is different from our user code). This is also the principle when we power off and then power on. The system is soft reset by writing 60H to IAP_CONTR (C7H), and then automatically downloading. There are two ways to start the MCU after resetting. One is to start from the user program area. We usually press the reset button to start in this way. The other is to start from the ISP program area. Power off startup belongs to this method. This startup method can be achieved by setting IAP_CONTR. We need to download the program, so we need to start from the ISP program area. For specific register settings, please refer to the official data sheet.
The specific implementation steps are as follows:
First, download the following code to the microcontroller using our old method.
IAP_CONTR EQU 0C7H
ORG 0000H
LJMP START
ORG 0023H
LJMP SERIAL
START:
LCALL SERIALINIT
MainLoop:
SJMP MainLoop
SERIALINIT:
MOV SP,#60H
MOV SCON,#50H
MOV TMOD,#20H
MOV TH1,#0FDH
MOV TL1,#0FDH
SETB TR1
SETB ES
SETB EA
SERIAL:
PUSH ACC
PUSH PSW
JNB RI,RIGO
CLR RI
MOV A,SBUF
CJNE A,#0AFH,RIGO;
NOP
NOP
NOP
MOV IAP_CONTR,#60H
RIGO:
POP PSW
POP ACC
RETI
END
Then set stc-isp as follows
Custom commands can be modified according to your needs, and the code should also be modified accordingly.
The main principle of the above code is to open the microcontroller serial port interrupt. When using stc-isp to download the program, the software will first write the AFH command to the microcontroller. When the microcontroller detects this command through the serial port, it will perform a system soft reset. After the system soft reset, the microcontroller system code will download the user code to the microcontroller.
Every time you download the code, you need to add the above code to your own code.
Of course, there is more than one way to send a specific command through the serial port to perform a soft reset of the system. For example, you can also set a button and run MOV IAP_CONTR, #60H when it is detected that the button is pressed. The core is the command MOV IAP_CONTR, #60H, but under what circumstances to run this command needs to be designed according to your own ideas and actual use.
Previous article:51 MCU timer and baud rate
Next article:8051-stc cold start automatic download line principle and DIY
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- What is the rigidity setting of Panasonic servo drive?
- How to change the inertia ratio of Panasonic servo drive
- What is the inertia ratio of the servo motor?
- Is it better for the motor to have a large or small moment of inertia?
- What is the difference between low inertia and high inertia of servo motors?
- About the development of ST's 8032 core microcontroller uPSD3234A-40u
- I burned a stmf103 minimum board today
- Basic knowledge of embedded Linux development
- Hall Effect Current Sensors in Telecom Rectifiers and Server Power Supplies
- MSP430 has 5 low power modes
- Some recent updates of MicroPython
- Media Interview: Qorvo Experts Talk About UWB
- Xi'an Datang Telecom_FPGA Experience
- What is the general speed of stm32 reading and writing TF?
- FPGA_100 Days Journey_DA Design