基于51单片机的看门狗程序

上传人:简****9 文档编号:107279337 上传时间:2019-10-18 格式:DOC 页数:5 大小:11.80KB
返回 下载 相关 举报
基于51单片机的看门狗程序_第1页
第1页 / 共5页
基于51单片机的看门狗程序_第2页
第2页 / 共5页
基于51单片机的看门狗程序_第3页
第3页 / 共5页
基于51单片机的看门狗程序_第4页
第4页 / 共5页
基于51单片机的看门狗程序_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

《基于51单片机的看门狗程序》由会员分享,可在线阅读,更多相关《基于51单片机的看门狗程序(5页珍藏版)》请在金锄头文库上搜索。

1、基于51单片机的看门狗程序include sbit CS= P27; sbit SO= P26; sbit SCK= P25; sbit SI= P24; #define WREN 0x06 /#define WRDI 0x04 /#define RDSR 0x05 /#define WRSR 0x01 /#define READ0 0x03 /#define READ1 0x0b /#define WRITE0 0x02 /#define WRITE1 0x0a /#define uchar unsigned charuchar ReadByte() /read a byte from de

2、vicebit bData;uchar ucLoop;uchar ucData;for(ucLoop=0;ucLoop8;ucLoop+)SCK=1;SCK=0;bData=SO;ucData=1;if(bData) ucData|=0x01; return ucData;void WriteByte(uchar ucData)/write a byte to deviceuchar ucLoop;for(ucLoop=0;ucLoop8;ucLoop+)if(ucData&0x80)=0) /the MSB send firstSI=0;elseSI=1;SCK=0;SCK=1;ucData

3、=1;uchar ReadReg() /read registeruchar ucData;CS=0;WriteByte(RDSR);ucData=ReadByte();CS=1;return ucData;uchar WriteReg(uchar ucData) /write registeruchar ucTemp;ucTemp=ReadReg();if(ucTemp&0x01)=1) /the device is busyreturn 0;CS=0;WriteByte(WREN);/when write the WREN, the cs must have a high levelCS=

4、1;CS=0;WriteByte(WRSR);WriteByte(ucData);CS=1;return 1;void WriteEpm(uchar cData,uchar cAddress,bit bRegion)/* 写入一个字节,cData为写入的数,cAddress为写入地址,bRegion为页 */while(ReadReg()&0x01)=1); /the device is busyCS=0;WriteByte(WREN); /when write the wren , the cs must have a high levelCS=1;CS=0;if(bRegion=0) Wr

5、iteByte(WRITE0); /write the page addrelseWriteByte(WRITE1); WriteByte(cAddress);WriteByte(cData);SCK=0; /CS=1;uchar ReadEpm(uchar cAddress,bit bRegion)/* 读入一个字节,cAddress为读入地址,bRegion为页 */uchar cData;while(ReadReg()&0x01)=1);/the device is busyCS=0;if(bRegion=0)WriteByte(READ0); elseWriteByte(READ1);WriteByte(cAddress);cData=ReadByte();CS=1;return cData;main()WriteReg(0x00);/set the watchdog time as 1.4sCS=1;CS=0; /reset the watchdog

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 商业/管理/HR > 管理学资料

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号