找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3169|回复: 0
收起左侧

关于mega328p watchdog

[复制链接]
ID:76658 发表于 2015-4-11 11:43 | 显示全部楼层 |阅读模式
#include <avr/wdt.h>
const int ledPin =  13;      // the number of the LED pin

void setup() {
  wdt_disable();
  Serial.begin(9600);
  Serial.println("System Init OK!");
  pinMode(ledPin, OUTPUT);
  Serial.println("Wait 5 Sec..");
  delay(5000);
  wdt_enable(WDTO_8S);
  Serial.println("Watchdog enabled!");
}

uint8_t timer = 0;
void loop() {
  if (!(millis() % 1000)) {
    Serial.print(millis());
    Serial.print("--");
    timer++;
    Serial.println(timer);
    digitalWrite(ledPin, digitalRead(ledPin) == 1 ? 0 : 1); delay(1);
  }
  //  wdt_reset();
}

这个程序无法正常复位,13引脚的灯一直闪烁。帖子里有人用了:
解决方案http://www.nongnu.org/avr-libc/u ... _avr__watchdog.html
这里的说明:
Note that for newer devices (ATmega88 and newer, effectively any AVR that has the option to also generate interrupts), the watchdog timer remains active even after a system reset (except a power-on condition), using the fastest prescaler value (approximately 15 ms). It is therefore required to turn off the watchdog early during program startup, the datasheet recommends a sequence like the following:
对于atmega88以及新型号的单片机(自带产生中断的),看门狗可能会在系统复位之后,依然运行(除掉电复位外)。因此,需要在程序启动早期,关闭看门狗。datasheet中推荐插入一段这样的程序:

#include <stdint.h>
#include <avr/wdt.h>

uint8_t mcusr_mirror __attribute__ ((section (".noinit")));

void get_mcusr(void) \
__attribute__((naked)) \
__attribute__((section(".init3")));
void get_mcusr(void)
{
mcusr_mirror = MCUSR;
MCUSR = 0;
wdt_disable();
}


但是这段程序我加了好几个位置都不行,还是不断地复位,等反复闪烁,哪位大神能狗解决这个问题?





回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表