This is the AVR watchdog timeout

Publisher:MysticEssenceLatest update time:2015-10-23 Source: eefocusKeywords:AVR  watchdog  watchdogtimeout Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Reset detection and watchdog control of AVRATMEGA16

  System control and reset
  Detection of reset source
   JTAG reset indication
   Watchdog reset indication
   BOD reset indication
   RESET pin reset indication
   Power-on reset indication
  Watchdog control

In order to simplify the program, various data are not output to the outside. It is recommended to use JTAG ICE hardware emulator when learning.
Fuse bit setting
1 Enable BOD function BODEN=0
2 Select BOD level BODLEVEL=1 2.7V (VCC=3V) (optional)
   BODLEVEL=0 4.0V (VCC=5V) (optional)
*/

#include
#include
//The clock is set to internal RC 1MHz, F_CPU=1000000. Other clocks can also be used.
#include

//Pin definition

#define WDT_EN   7 //PA7 Watchdog feeding control pin
      // High level, do not feed the dog
      // Low level, feed the dog

#define LED_JT   4 //PA4 JTAG reset indication
#define LED_WD   3 //PA3 watchdog reset indication
#define LED_BO   2 //PA2 BOD reset indication
#define LED_EXT    1 //PA1 RESET pin reset indication
#define LED_PO   0 //PA0 power-on reset indication
//The above signals are all valid at low level


int main(void)
{
   unsigned char CPU_STATUS;
   unsigned char i;
   //Power-on default DDRx=0x00,PORTx=0x00 input, no pull-up resistor
   PORTB =0xFF;          //Unused pins enable internal pull-up resistors.
   PORTC =0xFF;
   PORTD =0xFF;
   PORTA =0xFF;
   DDRA =(1<

   CPU_STATUS =MCUCSR;    //Read MCU control and status registers
   //You can directly observe the status of MCUCSR during JTAG debugging.
   CPU_STATUS&=0x1F;
   switch (CPU_STATUS)
   {
   case (1<  //Reset caused by JTAG?
       PORTA&=~(1<        break;
   case (1<  //Reset caused by watchdog?
       PORTA&=~(1<        break;
   case (1<  //Reset caused by BOD?
       PORTA&=~(1<        break;
   case (1< //Reset caused by RESET pin?
       PORTA&=~(1<        break;
   case (1<  //Reset caused by power-on?
       PORTA&=~(1<        break;
   default:     //Multiple resets occur at the same time?
       PORTA=~CPU_STATUS;
       break;
   }
   MCUCSR=0x00;    //Clear flag
   
   for(i=0;i<200;i++)
       _delay_ms(10);   //Delay 2 seconds
   wdt_enable(WDTO_2S); //Enable watchdog, overflow time is about 2 seconds
   while(1)
{
       if (!(PINA&(1<            wdt_reset();   //If PA7 is low, reset watchdog (feed dog)
   }
}

Keywords:AVR  watchdog  watchdogtimeout Reference address:This is the AVR watchdog timeout

Previous article:AVR debug fuse bit description, and pin failure
Next article:AVR microcontroller TC0 timer overflow routine

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号