(新手分享单片机延时开关源码),WiFi老是断线就想了个办法让它6小时重启,效果还行。
单片机源程序如下:
- #include <reg51.h>//11.0592
- typedef unsigned char u8;
- typedef unsigned int u16;
- typedef unsigned long u32;
- sfr AUXR = 0x8e;
- sfr WDT_CONTR = 0xc1; //看门狗
- sbit P31 = P3^1;
- sbit P30 = P3^0;
- u16 jishimun;
- u16 jishimun2;
- u16 jishimun3;
- u16 jishimun4;
- bit on_off;
- void InitTimer0(void)
- {
- AUXR &= 0x7f; //???0?12T??
- TMOD = 0x01;
- TH0 = 0x0DC;
- TL0 = 0x00;
- EA = 1;
- ET0 = 1;
- TR0 = 1;
- }
- void main(void)
- {
- InitTimer0();
- while (1);
- }
- void Timer0Interrupt(void) interrupt 1//10000us时间
- {
- WDT_CONTR=0X3E;//看门狗自动重新计数12MHZ=4.19S
- TH0 = 0x0DC;
- TL0 = 0x00;
- jishimun++;
- jishimun2++;
- jishimun4++;
- if(jishimun>200)//2s时间
- {
- jishimun=0;
- P31=!P31;
- }
- if(jishimun2>36000)//6分钟
- {
- jishimun2=0;
- // P30=!P30;
- jishimun3++;
- }
- if(jishimun3>100)//6x100=6H
- {
- jishimun3=0;
- P30=0;
- on_off=1;
- jishimun4=0;
- }
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
延时开关stc15f104w.rar
(28.4 KB, 下载次数: 19)
|