基于51单片机的看门狗程序
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
{
uchar ucLoop;
for(ucLoop=0;ucLoop<8;ucLoop++)
{
if((ucData&0x80)==0) //the MSB send first
{SI=0;}
else
{SI=1;}
SCK=0;
SCK=1;
ucData<<=1;
}
}
uchar ReadReg() //read register
{
uchar ucData;
CS=0;
WriteByte(RDSR);
ucData=ReadByte();
CS=1;
return ucData;
}
uchar WriteReg(uchar ucData) //write register
{
uchar ucTemp;
ucTemp=ReadReg();
if((ucTemp&0x01)==1) //the device is busy
CS=1;
CS=0;
if(bRegion==0)
{ WriteByte(WRITE0);} //write the page addr
else
{WriteByte(WRITE1);}
WriteByte(cAddress);
WriteByte(cData);
SCK=0; //
CS=1;
}
uchar ReadEpm(uchar cAddress,bit bRegion)
return 0;
CS=0;
WriteByte(WREN);//when write the WREN, the cs must have a high level
CS=1;
CS=0;
WriteByte(WRSR);
WriteByte(ucData);
CS=1;
return 1;
}
void WriteEpm(uchar cData,uchar cAddress,bit bRegion)
基于51单片机的看门狗程序
#include <reg51.h>
sbit CS= P2^7;
sbit SO= P2^6;
sbit SCK= P2^5;
sbit SI= P2^4;
#define WREN 0x06 //
#define WRDI 0x04 //
#define RDSR 0x05 //
#define WRSR 0x01 //
WriteByte(cAddress);
cData=ReadByte();
CS=1;
return cData;
}
main()
{
WriteReg(0x00);//set the watchdog time as 1.4s
CS=1;
CS=0; //reset the watchdog
}
/*写入一个字节,cData为写入的数,cAddress为写入地址,bRegion为页*/
{
while((ReadReg()&0x01)==1); //the device is busy
CS=0;
WriteByte(WREN); //when write the wren , the cs must have a high level
/*读入ห้องสมุดไป่ตู้个字节,cAddress为读入地址,bRegion为页*/
{
uchar cData;
while((ReadReg()&0x01)==1);//the device is busy
CS=0;
if(bRegion==0)
{WriteByte(READ0); }
else
{WriteByte(READ1);}
#define READ0 0x03 //
#define READ1 0x0b //
#define WRITE0 0x02 //
#define WRITE1 0x0a //
#define uchar unsigned char
uchar ReadByte() //read a byte from device
{
bit bData;
uchar ucLoop;
uchar ucData;
for(ucLoop=0;ucLoop<8;ucLoop++)
{
SCK=1;
SCK=0;
bData=SO;
ucData<<=1;
if(bData)
{ ucData|=0x01; }
}
return ucData;
}
void WriteByte(uchar ucData)//write a byte to device
uchar ucLoop;
for(ucLoop=0;ucLoop<8;ucLoop++)
{
if((ucData&0x80)==0) //the MSB send first
{SI=0;}
else
{SI=1;}
SCK=0;
SCK=1;
ucData<<=1;
}
}
uchar ReadReg() //read register
{
uchar ucData;
CS=0;
WriteByte(RDSR);
ucData=ReadByte();
CS=1;
return ucData;
}
uchar WriteReg(uchar ucData) //write register
{
uchar ucTemp;
ucTemp=ReadReg();
if((ucTemp&0x01)==1) //the device is busy
CS=1;
CS=0;
if(bRegion==0)
{ WriteByte(WRITE0);} //write the page addr
else
{WriteByte(WRITE1);}
WriteByte(cAddress);
WriteByte(cData);
SCK=0; //
CS=1;
}
uchar ReadEpm(uchar cAddress,bit bRegion)
return 0;
CS=0;
WriteByte(WREN);//when write the WREN, the cs must have a high level
CS=1;
CS=0;
WriteByte(WRSR);
WriteByte(ucData);
CS=1;
return 1;
}
void WriteEpm(uchar cData,uchar cAddress,bit bRegion)
基于51单片机的看门狗程序
#include <reg51.h>
sbit CS= P2^7;
sbit SO= P2^6;
sbit SCK= P2^5;
sbit SI= P2^4;
#define WREN 0x06 //
#define WRDI 0x04 //
#define RDSR 0x05 //
#define WRSR 0x01 //
WriteByte(cAddress);
cData=ReadByte();
CS=1;
return cData;
}
main()
{
WriteReg(0x00);//set the watchdog time as 1.4s
CS=1;
CS=0; //reset the watchdog
}
/*写入一个字节,cData为写入的数,cAddress为写入地址,bRegion为页*/
{
while((ReadReg()&0x01)==1); //the device is busy
CS=0;
WriteByte(WREN); //when write the wren , the cs must have a high level
/*读入ห้องสมุดไป่ตู้个字节,cAddress为读入地址,bRegion为页*/
{
uchar cData;
while((ReadReg()&0x01)==1);//the device is busy
CS=0;
if(bRegion==0)
{WriteByte(READ0); }
else
{WriteByte(READ1);}
#define READ0 0x03 //
#define READ1 0x0b //
#define WRITE0 0x02 //
#define WRITE1 0x0a //
#define uchar unsigned char
uchar ReadByte() //read a byte from device
{
bit bData;
uchar ucLoop;
uchar ucData;
for(ucLoop=0;ucLoop<8;ucLoop++)
{
SCK=1;
SCK=0;
bData=SO;
ucData<<=1;
if(bData)
{ ucData|=0x01; }
}
return ucData;
}
void WriteByte(uchar ucData)//write a byte to device