找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3374|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

關(guān)于mega328p watchdog

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:76658 發(fā)表于 2015-4-11 11:43 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
#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();
}

這個(gè)程序無法正常復(fù)位,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以及新型號的單片機(jī)(自帶產(chǎn)生中斷的),看門狗可能會在系統(tǒng)復(fù)位之后,依然運(yùn)行(除掉電復(fù)位外)。因此,需要在程序啟動早期,關(guān)閉看門狗。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();
}


但是這段程序我加了好幾個(gè)位置都不行,還是不斷地復(fù)位,等反復(fù)閃爍,哪位大神能狗解決這個(gè)問題?





分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表