|
使用内部rc
测试代码
uint8_t i;
//_delay_ms(2); //等待电平稳定
wdt_enable( WDTO_512MS);
if (MCUSR & _BV( WDRF))
{
//看门狗复位标志位
wdt_disable();
//MCUSR = 0;
DDRD |= (1<<PD7); //set led out
while(1)
{
_delay_ms(200);
ledYellowToggle();
wdt_reset();
}
}
else
{
}
wdt_enable( WDTO_512MS);
DDRD |= (1<<PD7); //set led out
ledYellowOn();
_delay_ms(100);
ledYellowOff();
for (i=0; i<200; i++)
{
wdt_reset();
_delay_ms(10);
}
//wdt_disable();
while(1)
{
_delay_ms(50);
ledYellowToggle();
}
相关宏定义
/* 看门狗 */
#define WDTO_1MS 0
#define WDTO_2MS 1
#define WDTO_4MS 2
#define WDTO_8MS 3
#define WDTO_16MS 4
#define WDTO_32MS 5
#define WDTO_64MS 6
#define WDTO_128MS 7
#define WDTO_256MS 0x20
#define WDTO_512MS 0x21
#define wdt_enable(value) \
__asm__ __volatile__ ( \
"in __tmp_reg__,__SREG__" "\n\t" \
"cli" "\n\t" \
"wdr" "\n\t" \
"sts %0,%1" "\n\t" \
"out __SREG__,__tmp_reg__" "\n\t" \
"sts %0,%2" "\n\t" \
: /* no outputs */ \
: "M" (_SFR_MEM_ADDR(WDTCSR)), \
"r" (_BV(4) | _BV(3)), \
"r" ((uint8_t) (_BV(3) | \
value) ) \
: "r0" \
)
#define wdt_disable() \
__asm__ __volatile__ ( \
"in __tmp_reg__, __SREG__" "\n\t" \
"cli" "\n\t" \
"sts %0, %1" "\n\t" \
"sts %0, __zero_reg__" "\n\t" \
"out __SREG__,__tmp_reg__" "\n\t" \
: /* no outputs */ \
: "M" (_SFR_MEM_ADDR(WDTCSR)), \
"r" ((uint8_t)(_BV(4) | _BV(3))) \
: "r0" \
)
如果在看门狗复位之前关闭看门狗是有效的, 但是在看门狗引起复位后就不能关闭看门狗了.
请教LGT,是这样设计的还是工程样片的bug, 后面的已经修正? 使用的是内部RC. |
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|