按键喂狗

来源:互联网 发布:兰州网络教育学生平台 编辑:程序博客网 时间:2024/04/30 11:50
#include <reg52.h>sfr WDTRST = 0xA6;sbit  K1 = P3^0; sbit  K2 = P3^1;sbit  LED1=P1^1;sbit  LED2=P1^2;void DelayUs2x(unsigned char t);//us级延时函数声明 void DelayMs(unsigned char t); //ms级延时main(){   LED1=0;   DelayMs(100);   LED1=1;   DelayMs(100);   TMOD=0x01;   TH0=0xc6;      //定时16ms   TL0=0x66;   EA=1;   ET0=1;   WDTRST=0x1e;   //在程序初始化中激活看门狗。   WDTRST=0xe1;   //先送1E,后送E1   if(K1==0)   {     TR0=1;   }   while(1)   {         if(K2==0)     {       TR0=0;     } LED2=1; LED1=1; DelayMs(100); LED2=0; DelayMs(100);   }}void Time0(void) interrupt 1{   TH0=0xc6;      //定时16ms   TL0=0x66;   WDTRST=0x1e;   //喂狗指令   WDTRST=0xe1;}void DelayUs2x(unsigned char t){    while(--t);}void DelayMs(unsigned char t){      while(t--) {     //大致延时1mS     DelayUs2x(245); DelayUs2x(245); }}

0 0
原创粉丝点击