zy99 发表于 2005-6-27 16:25:43

请教bascom中的看门狗问题。

看门狗对于保持AVR的稳定有重要的作用。



最近,我在使用bascom制作一个小程序,需要用到看门狗。

可是我那本书里没有讲这个问题,而且bascom-avr的帮助文件里也没有。



在汇编里,好像是用 “wdr”实现的,,,



我想问一下,在bascom里,是用什么语句实现看门狗功能的。

包括使能和复位。



可否给一个简短的示例程序。



谢谢大家。

zy99 发表于 2005-6-28 10:41:02

没有人理,四处的翻了翻,结果找到了一个帮助文件,和前人的一个例子,我修改了一下,放在了下面。



呵呵。



已经明白了~!!



我猜看门狗 赋值的时候,范围只能16~2048,且为2的n次方。





The Watchdog Timer



The Watchdog Timer is clocked from a separate on-chip oscillator which runs at 1MHz. This is the typical value at VCC = 5V.



By controlling the Watchdog Timer pre-scaler, the Watchdog reset interval can be adjusted from 16K to 2,048K cycles (nominally 16 - 2048 ms). The RESET WATCHDOG- instruction resets the Watchdog Timer.

Eight different clock cycle periods can be selected to determine the reset period.

If the reset period expires without another Watchdog reset, the AT90Sxxxx resets and executes from the reset vector.

==================================

$regfile = "8515def.dat"

$crystal = 8000000

Config Watchdog = 2048



Dim N1 As Long

Stop Watchdog



N1 = 0



Start Watchdog



Do

N1 = N1 + 1



Print N1

Waitms 2



Loop

Stop Watchdog

End

zy99 发表于 2005-6-28 10:43:32

我试验了一下,只记到106 就溢出了,,,这样算来,最大才200多ms。

zy99 发表于 2005-6-28 11:21:49

CONFIG WATCHDOG



Action

Configures the watchdog timer.





Syntax

CONFIG WATCHDOG= time





Remarks



Time        The interval constant in mS the watchdog timer will count to before it will reset your program.



Possible settings :

16 , 32, 64 , 128 , 256 , 512 , 1024 and 2048.

When the WD is started, a reset will occur after the specified number of mS.

With 2048, a reset will occur after 2 seconds, so you need to reset the WD in your programs periodically with the RESET WATCHDOG statement.





See also

START WATCHDOG , STOP WATCHDOG , RESET WATCHDOG





Example

'-----------------------------------------------------

'                (c) 1999 MCS Electronics

' WATCHD.BAS demonstrates the watchdog timer

'-----------------------------------------------------

Config Watchdog = 2048                                        'reset after 2048 mSec

Start Watchdog                                                'start the watchdog timer

Dim I As Word

For I = 1 To 1000



Print I                               'print value

'Reset Watchdog

'you will notice that the for next doesnt finish because of the reset

'when you unmark the RESET WATCHDOG statement it will finish because the

'wd-timer is reset before it reaches 2048 msec

Next

End

machao 发表于 2005-6-29 12:55:06

你选择了最好的方式:应该先看BASCOM-AVR的再线帮助。它的帮助已经非常好了,还有许多简单例程参考。
页: [1]
查看完整版本: 请教bascom中的看门狗问题。