📄 baojian.c
字号:
#include <intrins.h>
#include"stc12c2052.h"
#define heatlow P3_5
#define heathigh P3_7
#define D1 P1_0
#define D2 P1_1
#define D4 P1_3
#define larmlight P1_4
#define D3 P1_2
#define bell P3_4
#define Door P1_7
#define strong_key P1_5
#define mid_key P1_6
#define lack_key P3_3
#define on_off P3_2
#define uchar unsigned char
#define uint unsigned int
#define _BIN(a,b,c,d,e,f,g,h) ((a<<7)+(b<<6)+(c<<5)+(d<<4)+(e<<3)+(f<<2)+(g<<1)+(h<<0))
#define _bin _BIN // _bin,_BIN均可
#define _20S 400
#define _60S 1200
#define _6S 120
#define _15S 300
#define _2S 40
#define _12S 240
#define _30fen 36000
#define _7fen5 9000
#define _1S 20
#define _05S 10
#define _01S 2
//************************************************
//公用变量
///******************************************
uchar mode=0x00;
uchar liaocheng=0x00;
uchar bell_style=0x00;
uchar time_going=0x00;
uchar step=0x00;
uint time_start=0x00;
uint time_count=0x0000;
uint time_fly=0x00;
uint time_fly1=0x00;
uint time_bell=0x00;
uint time_flash=0x0000;
bit power_flag=0;
//***************************************************/
//50ms定时器0中断服务程序
/////////////////////////////////////////////////////
void timer0_50ms (void) interrupt 1 using 3
{
TH0=0xfa;
TL0=0x00;
time_start++;
time_count++;
}
/***************************************************
//delay05S()延时程序
/////////////////////////////////////////////////////
void delay05S(void)
{
uchar i,b;
for(i=0x5;i>0;i--)
{
for(b=0x5;b>0;b--);
}
}
//***************************************************/
//LED_flash()定时器1中断服务程序
/////////////////////////////////////////////////////
void timer1_LED (void) //interrupt 3 using 2
{
//TH1=0x00;
//TL1=0x00;
time_flash++;
switch(mode)
{
case 0x01:
{
if(time_flash>4000)
{
P3M1=_bin(1,0,1,0,1,1,0,0);//P3M1=0x0C; P3_3,P3_2//设为强输出驱动LED
_nop_();
P1M1=_bin(1,1,1,0,0,0,0,0);//P1M1=_0x30; P1_6,P1_5//设为强输出驱动LED
_nop_();
mid_key=lack_key=1;
_nop_();
strong_key=~strong_key;
_nop_();
time_flash=0x00;
}
break;
}
case 0x02:
{
if(time_flash>4000)
{ _nop_();
P3M1=_bin(1,0,1,0,1,1,0,0);//P3M1=0x0C; P3_3,P3_2//设为强输出驱动LED
_nop_();
P1M1=_bin(1,1,1,0,0,0,0,0);//P1M1=_0x30; P1_6,P1_5//设为强输出驱动LED
_nop_();
strong_key=lack_key=1;
_nop_();
mid_key=~mid_key;
_nop_();
time_flash=0x00;
_nop_();
}
break;
}
case 0x03:
{
if(time_flash>4000)
{ _nop_();
P3M1=_bin(1,0,1,0,1,1,0,0);//P3M1=0x0C; P3_3,P3_2//设为强输出驱动LED
_nop_();
P1M1=_bin(1,1,1,0,0,0,0,0);//P1M1=_0x30; P1_6,P1_5//设为强输出驱动LED
_nop_();
mid_key=strong_key=1;
_nop_();
lack_key=~lack_key;
_nop_();
time_flash=0x00;
_nop_();
}
break;
}
default :break;
}
}
//***********************************************
//strong(); 强加热程序
//***********************************************
void strong(void)
{
TR0=1;
TR1=0;
if(mode!=0x01)
{liaocheng=0x00;}
D1=D2=D3=D4=0;
bell=0;
step=0x01;
mode=0x01;
// bell_style=0x02;
}
//***********************************************
//mid(); 中加热程序
//***********************************************
void mid(void)
{
TR0=1;
TR1=0;
if(mode!=0x02)
{liaocheng=0x00;}
bell=0;
D1=D2=D3=D4=0;
step=0x01;
mode=0x02;
}
//***********************************************
//lack(); 弱加热程序
//***********************************************
void lack(void)
{
TR0=1;
TR1=0;
if(mode!=0x03)
{liaocheng=0x00;}
D1=D2=D3=D4=0;
bell=0;
step=0x01;
mode=0x03;
}
//*********************************************
//alarm();
//*********************************************
void alarm(void)
{
if(time_count>_7fen5)
{
if(D4==0)
{
D4=1;time_count=0x00;
}
else if(D3==0)
{
D3=1;time_count=0x00;
}
else if(D2==0)
{
D2=1;time_count=0x00;
}
else if(D1==0)
{
D1=1;
time_count=0x00;
// larmlight=0;
//TR0=0;
TR1=1;
liaocheng++;
bell_style=0x01;
}
if((D1==1)&(liaocheng<3))
{
mode=0x00;
P3M1=_bin(1,0,1,0,1,1,0,0);
P3M0=_bin(0,0,0,0,0,0,0,0);
P1M1=_bin(1,1,1,0,0,0,0,0);
P1M0=_bin(1,0,0,0,0,0,0,0);
_nop_();
strong_key=mid_key=lack_key=1;
heathigh=0;
if((time_count>_60S)&(liaocheng<3))
{
TR1=0;
TR0=0;
mode=0x00;
bell=0;
time_count=0x00;
P3M1=_bin(1,0,1,0,1,1,0,0);
P3M0=_bin(0,0,0,0,0,0,0,0);
P1M1=_bin(1,1,1,0,0,0,0,0);
P1M0=_bin(1,0,0,0,0,0,0,0);
_nop_();
strong_key=mid_key=lack_key=1;
}
}
if(liaocheng>=3)
{
TR1=1;
TR0=0;
power_flag=0;
heathigh=0;
//time_count++;
/*
if(time_count>10)
{
larmlight=~larmlight;
time_count=0x00;
}
*/
bell_style=0x02;
P3M1=_bin(1,0,1,0,1,1,0,0);
P3M0=_bin(0,0,0,0,0,0,0,0);
P1M1=_bin(1,1,1,0,0,0,0,0);
P1M0=_bin(1,0,0,0,0,0,0,0);
_nop_();
strong_key=mid_key=lack_key=1;
mode=0x00;
}
}
}
//*********************************************
//power();
//************************************************
void power(void)
{
if(power_flag)
{
// P3M1=_bin(0,0,0,0,0,0,0,0);
D1=D2=D3=D4=1;
power_flag=0;
on_off=1;
TR0=0;
TR1=0;
bell=0;
strong_key=mid_key=lack_key=1;
step=0x00;
mode=0x00;
larmlight=1;
time_count=0x00;
liaocheng=0x00;
heatlow=0;heathigh=0;
}
else
{
// P3M1=_bin(1,0,1,1,1,1,0,0);
D1=D2=D3=D4=0;
on_off=1;
TR0=0;
TR1=0;
bell=0;
time_count=0x00;
strong_key=mid_key=lack_key=1;
power_flag=1;
heatlow=1;
}
}
//**********************************************
//working()
//**********************************************
void working(void)
{
switch(mode)
{
case 0x01:
{
switch(step)
{
case 0x01:
{
P3M1=_bin(1,0,1,0,1,1,0,0);
heathigh=1;
time_fly=time_start;
if(time_start>(_15S-time_fly1))
{
TR0=0;
heathigh=0;
time_start=0x00;
time_fly=0x00;
step++;
TR0=1;
}
break;
}
case 0x02:
{ P3M1=_bin(1,0,1,0,1,1,0,0);
if(time_start>_20S)
{
heathigh=1;
time_start=0x00;
step++;
}
break;
}
case 0x03:
{ P3M1=_bin(1,0,1,0,1,1,0,0);
if(time_start>_6S)
{
heathigh=0;
time_start=0x00;
step++;
}
break;
}
case 0x04:
{ P3M1=_bin(1,0,1,0,1,1,0,0);
if(time_start>_12S)
{
heathigh=1;
time_start=0x00;
step++;
}
break;
}
case 0x05:
{ P3M1=_bin(1,0,1,0,1,1,0,0);
if(time_start>_2S)
{
heathigh=0;
time_start=0x00;
step++;
}
break;
}
case 0x06:
{ P3M1=_bin(1,0,1,0,1,1,0,0);
if(time_start>_60S)
{
heathigh=1;
time_start=0x00;
step=0x03;
}
break;
}
default : break;
}
break;
}
case 0x02:
{
switch(step)
{
case 0x01:
{
P3M1=_bin(1,0,1,0,1,1,0,0);
heathigh=1;
time_fly1=time_start;
if(time_start>(_20S-time_fly)) //
{
TR0=0;
heathigh=0;
time_start=0x00;
time_fly1=0x00;
step++;
TR0=1;
}
break;
}
case 0x02:
{ P3M1=_bin(1,0,1,0,1,1,0,0);
if(time_start>_20S)
{
heathigh=1;
time_start=0x00;
step++;
}
break;
}
case 0x03:
{ P3M1=_bin(1,0,1,0,1,1,0,0);
if(time_start>_6S)
{
heathigh=0;
time_start=0x00;
step++;
}
break;
}
case 0x04:
{ P3M1=_bin(1,0,1,0,1,1,0,0);
if(time_start>_60S)
{
heathigh=1;
time_start=0x00;
step=0x03;
}
break;
}
default : break;
}
break;
}
case 0x03:
{
switch(step)
{
case 0x01:
{
P3M1=_bin(1,0,1,0,1,1,0,0);
heathigh=1;
if(time_start>(_05S)) //-time_fly
{
TR0=0;
heathigh=0;
time_start=0x00;
step++;
TR0=1;
}
break;
}
case 0x02:
{ P3M1=_bin(1,0,1,0,1,1,0,0);
if(time_start>_60S)
{
heathigh=1;
time_start=0x00;
step=0x01;
}
break;
}
default : break;
}
break;
}
default:break;
}
}
//键盘扫描void key(void);
///////////////////////////////////////////////////////
void key(void)
{
bit temp;
temp=on_off;
_nop_();
P3M1=0xa8;//_bin(1,0,1,0,1,0,0,0);
_nop_();
P3M0=0x00;//_bin(0,0,0,0,0,0,0,0);
_nop_();
// P1M1=_bin(0,1,1,0,0,0,0,0);
// P1M0=_bin(0,0,0,0,0,0,0,0);
on_off=1;
_nop_();
while(!on_off)
{ _nop_();
while(!on_off);
power();
}
on_off=temp;
if(power_flag)
{
temp=strong_key;
// P3M1=_bin(1,0,1,0,1,1,0,0);
// P3M0=_bin(0,0,0,0,0,0,0,0);
P1M1=_bin(1,1,0,0,0,0,0,0);
_nop_();
strong_key=1;
_nop_();
while(!strong_key)
{ _nop_();
while(!strong_key);
strong();
}
_nop_();
strong_key=temp;
_nop_();
temp=mid_key;
_nop_();
// P3M1=_bin(1,0,1,0,1,1,0,0);
// P3M0=_bin(0,0,0,0,0,0,0,0);
P1M1=_bin(1,0,1,0,0,0,0,0);
// _nop_();
// P1M0=0x00;//_bin(0,0,0,0,0,0,0,0);
_nop_();
mid_key=1;
_nop_();
while(!mid_key)
{ _nop_();
while(!mid_key);
mid();
}
mid_key=temp;
_nop_();
temp=lack_key;
_nop_();
P3M1=_bin(1,0,1,0,0,1,0,0);
_nop_();
P3M0=0x00;//_bin(0,0,0,0,0,0,0,0);
_nop_();
P1M1=_bin(1,1,1,0,0,0,0,0);
_nop_();
P1M0=_bin(1,0,0,0,0,0,0,0);
_nop_();
lack_key=1;
_nop_();
while(!lack_key)
{ _nop_();
while(!lack_key);
lack();
}
lack_key=temp;
}
_nop_();
P3M1=_bin(1,0,1,0,1,1,0,0);
_nop_();
P3M0=_bin(0,0,0,0,0,0,0,0);
_nop_();
P1M1=_bin(1,1,1,0,0,0,0,0);
_nop_();
P1M0=_bin(1,0,0,0,0,0,0,0);
}
void bell_time1(void) interrupt 3 using 2
{
TH1=0x4C;
TL1=0x00;
time_bell++;
switch(bell_style)
{
case 0x01:
{
if(bell)
{
if(time_bell>_01S)
{
bell=~bell;
time_bell=0x00;
}
}
else
{
if(time_bell>_2S)
{
bell=~bell;
time_bell=0x00;
}
}
break;
}
case 0x02:
{
if(bell)
{
if(time_bell>_01S)
{
bell=~bell;
time_bell=0x00;
larmlight=1;
}
}
else
{
if(time_bell>_01S)
{
bell=~bell;
time_bell=0x00;
larmlight=0;
}
}
break;
}
default :break;
}
}
void Door_protect(void)
{
if(Door==0)
{
TR0=TR1=0;
power_flag=0;
strong_key=mid_key=lack_key=1;
larmlight=0;
liaocheng=0x00;
heatlow=0;heathigh=0;
mode=0x00;
}
else if((mode==0x00)&(liaocheng==0x00))
{
larmlight=1;
}
}
//************************************//
//main()
//////////////////////////////////////
void main(void)
{
P3M1=_bin(1,0,1,0,1,1,0,0);
P3M0=_bin(0,0,0,0,0,0,0,0);
P1M1=_bin(1,1,1,0,0,0,0,0);
P1M0=_bin(1,0,0,0,0,0,0,0);
D1=D2=D3=D4=larmlight=1;
heatlow=heathigh=bell=0;
strong_key=mid_key=lack_key=0;
on_off=1;
TH0=0x4C;
TL0=0x00;
TH1=0x4C;
TL1=0x00;
TMOD=0x11;
ET0=ET1=EA=1;
while(1)
{
key();
timer1_LED();
working();
alarm();
Door_protect();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -