发个测试看门狗的代码供参考:
#include "reg51.h"
sfr WDT_CONTR = 0xc1;
sbit P32 = P3^2;
sfr P0M1 = 0x93;
sfr P0M0 = 0x94;
sfr P1M1 = 0x91;
sfr P1M0 = 0x92;
sfr P2M1 = 0x95;
sfr P2M0 = 0x96;
sfr P3M1 = 0xb1;
sfr P3M0 = 0xb2;
sfr P4M1 = 0xb3;
sfr P4M0 = 0xb4;
sfr P5M1 = 0xc9;
sfr P5M0 = 0xca;
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
// WDT_CONTR = 0x23; //使能看门狗,溢出时间约为0.5s
WDT_CONTR = 0x24; //使能看门狗,溢出时间约为1s
// WDT_CONTR = 0x27; //使能看门狗,溢出时间约为8s
P32 = 0; //测试端口
while (1)
{
// WDT_CONTR = 0x33; //清看门狗,否则系统复位
WDT_CONTR = 0x34; //清看门狗,否则系统复位
// WDT_CONTR = 0x37; //清看门狗,否则系统复位
// Display(); //显示模块
// Scankey(); //按键扫描模块
// MotorDriver(); //电机驱动模块
}
}
|