请教 ATMEGA48 看门狗的问题
因为一个实验程序是用ATMEGA16来写的,后来转到ATMEGA48上准备洗PCB结果有问题,找了好久原来是ATMEGA48的看门狗没驯好,我的初始化是这样的,但是老有问题,//watchdog initialization
void watchdog_initial(void)
{
MCUSR=0x00;
WDTCSR=0x00;
WDTCSR=(1<<WDCE)|(1<<WDE);
WDTCSR=0x0f;
}
不知道那里有问题?? 实在没辙嘛 ATMEGA48的看门狗只能调用TMD的‘WDT。H’ 头文件来用了,照着datasheet来写还真不行,无语,从来没遇到过这么恶心的东东 http://cache.amobbs.com/bbs_upload782111/files_35/ourdev_600901H0EU4W.jpg
这个东东是什么玩意嘛!!!!!!!不能这么忽悠人嘛 (原文件名:2.jpg) 3楼的可用啊,看完之后
//看门狗初始化
void watchdog_init(void)
{
WDR();//喂狗
WDTCSR |= (1<<WDCE) | (1<<WDE);//置位WDCE后,方可更改WDP
WDTCSR = 0x0F;//使能看门狗
}
这样就搞定了 定时时间可以改回复【2楼】kuzhuu
----------------------------------------------------------------------- 手册上却是不行,我贴一段代码
//Watchdog initialize
// prescale: 1024K
void watchdog_init(void)
{
WDR (); //this prevents a timeout on enabling
WDTCSR = (1<<WDCE) | (1<<WDE);/* 30-Oct-2006 Umesh*/
WDTCSR = 0x29; //WATCHDOG ENABLED - dont forget to issue WDRs
}
void WDT_Prescaler_Change(void)
{
//CLI();
WDR();
/* Start timed equence */
WDTCSR = (1<<WDCE) | (1<<WDE);
/* Set new prescaler(time-out) value = 2K cycles (16ms) */
WDTCSR = (1<<WDE);// | (1<<WDP2) | (1<<WDP0);
//SEI();
m_Tick=0;
}
void WDT_off(void)
{
//CLI();
WDR();
/* Clear WDRF in MCUSR */
MCUSR &= ~(1<<WDRF);
/* Write logical one to WDCE and WDE */
/* Keep old prescaler setting to prevent unintentional time-out */
WDTCSR = (1<<WDCE) | (1<<WDE);
/* Turn off WDT */
WDTCSR = 0x00;
//SEI();
}
先 WDT_off,然后在初始化 刚好用到mega48的看门狗,直接拿来用了!!哈哈
页:
[1]