Software reset method for Program Control
Microprocessor RESET method: RESET by hardware pin RESET; RESET by watchdog; RESET by program control (this method is called software RESET ). The software reset implementation method first declares a function pointer pointing to the position where the command is executed after the Reset: void (* app_start) (void) = 0x0000; you can modify the following address based on the position after the microprocessor is reset. Then, call app_start () in the place where you want to reset in your program, that is, jump to the 0x0000 position to execute the command. You can modify the above address (0x0000) based on the addresses reset by different microprocessor ). In implementation, you can jump to any position for execution or call function execution. The following test cases are based on Arduino. Note: In the AVR microprocessor, set BOOTRST to 1 so that the Arduino will no longer enter the boot zone when resetting. The function pointer reset method is as follows. Can you imagine that the program below will make the LED light shine?
/// 0. pin definition # define LED_PIN 13 // define the LED pin as data PIN 13 (DIG13) static void (* reset_this_CPU) (void) = 0x0000; // *** reset the CPU function pointer // 1. initialize void setup () {pinMode (LED_PIN, OUTPUT); // initialize DIG13 to OUTPUT digitalWrite (LED_PIN, HIGH); // DIG13 output high level delay (1000 ); // 1 second delayed digitalWrite (LED_PIN, LOW); // DIG13 output LOW-level delay (1000); // 1 second delayed reset_this_CPU (); // *** jump to the 0x0000 address pointer, that is, reset} // 2. loop void loop () {// nothing here !}
Conclusion This method can be used to reset a function in software or call any function using this function pointer.