In: Computer Science
Atmega128 and Pic24e have the reset interrupt at the program address 0x0. Write a function reset() that works for both chips to reset a program.
given is Atmega128 and Pic24e have the reset interrupt at the program address 0x0 to reset it by using
AVR Libc Reference manual specifies the usage of watchdog timer for software reset. by include avr/wdt.h header file
could easily enable watchdog timer.
Code for fucntion reset() in C programming language
#include <avr/wdt.h>
#define reset()
do
{
wdt_enable(WDTO_15MS);
for(;;)
{
}
} while(0);
For Atmega128 and Pic24e types of AVRs watchdog is remain enabled after reseting the software,so we
need to add a function in the .init3 section( it excutes before main()) so watchdog would be disabled early then so it does not resetting the program again and again.
#include <avr/wdt.h>
// Prototype of a Function
void wdt_init(void) __attribute__((naked)) __attribute__((section(".init3")));
// Implementation of Function
void wdt_init(void)
{
MCUSR = 0;
wdt_disable();
return;
}
Summary:- This code will reset the program for both the chips Atmega128 and Pic24e.