Source: http://blog.sina.com.cn/s/blog_493520900100bpos.html
Question |
How to reset the AVR via software? |
Answer |
if you want to reset the AVR by software, you should use the internal watchdog. Simple to enable it and let it overflow. When the watchdog is triggered, the program counter returns to 0, clearing all registers and other tasks that are being performed, which has the same effect as lowering the reset foot down. You should not handle:--connect the external reset pin with another AVR pin. At a short reset time, the AVR pin will fail in three states, which will invalidate reset. --Jump to program address 0, skip to program address 0, this will not erase all registers, so you will not get a full "reset". The following is an example code (GCC) for every 30mS reset of the AVR: #include <avr/io.h> #include <avr/wdt.h>
int main (void) { Wdt_enable (WDTO_30MS); while (1) {}; } Or you can generate a macro: #include <avr/io.h> #include <avr/wdt.h>
#define RESET_AVR () wdt_enable (wdto_30ms); while (1) {}
int main (void) { RESET_AVR (); } |
AVR Programming _ How to reset the AVR by software? Go