|
適合各種沒有休眠功能的焊臺(tái),輸出用繼電器控制,原理是在烙鐵手柄內(nèi)裝滾珠開關(guān),烙鐵長(zhǎng)時(shí)間不動(dòng)關(guān)閉電源。代碼如下
#include "STC15F104E.H" //單片機(jī)頭文件
#define uint unsigned int //宏定義無(wú)符號(hào)整型數(shù)據(jù)
#define uchar unsigned char //宏定義無(wú)符號(hào)字符型數(shù)據(jù)
sbit jy=P3^4; //烙鐵繼電器
sbit zd=P3^2; //震動(dòng)開關(guān)
uint xs,xms,cs; //中斷計(jì)時(shí)變量
bit ZT=0,dj=0,zd_sign=0;
void Timer0Init();
void jc()//次數(shù)檢測(cè)
{
static uint count=0;
if (zd==1&&zd_sign==0)
{
count++;
if(count>=10000)
{
count=0;
if(zd==1)
zd_sign=1;
}
}
if(zd==0&&zd_sign==1)
{
zd_sign=0;
cs++;xs=0;//cs是動(dòng)作次數(shù)
}
if(cs>=5&&xs==60) //一分鐘內(nèi)動(dòng)作超過5次
{ cs=0;ZT=0;xs=0;}//次數(shù)歸零重新計(jì)數(shù)
if(cs<=4&&xs==60) //一分鐘內(nèi)動(dòng)作低于4次
{ZT=1;cs=0;}
if(ZT==1&&xs==400)//400秒無(wú)動(dòng)作
{jy=0;cs=0;}//關(guān)閉電源
if(jy==0&&cs>=2)//拿起手柄
jy=1;//恢復(fù)供電
}
void Timer0Init(void) //1毫秒@11.0592MHz
{
AUXR |= 0x80; //定時(shí)器時(shí)鐘1T模式
TMOD &= 0xF0; //設(shè)置定時(shí)器模式
TL0 = 0xCD; //設(shè)置定時(shí)初始值
TH0 = 0xD4; //設(shè)置定時(shí)初始值
TF0 = 0; //清除TF0標(biāo)志
TR0 = 1; //定時(shí)器0開始計(jì)時(shí)
}
/***************主程序****************/
void main()
{ Timer0Init();
//定時(shí)器初始化
EA=1; //開總中斷
ET0=1;
cs=0;
xms=0;
xs=0;
jy=1;
P3M1=0x00;
P3M0=0x30;
while(1)
{
jc();
}
}
void timer0() interrupt 1
{
xms++; //中斷變量Cnt50ms自+1
if(xms>=1000) //1秒
{
xms=0; //中斷變量Cnt50ms清0
xs++; //計(jì)數(shù)清0
}
}
|
評(píng)分
-
查看全部評(píng)分
|