📄 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 123
#define _15S 296
#define _2S 40
#define _12S 240
#define _30fen 36000
#define _7fen5 9000
#define _1S 20
#define _05S 90//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;
bit first_sel=0;
bit working_flag=0;
bit first_power_on=0;
/*****************************************************/
#include"stc_flash.c"
//***************************************************/
//50ms定时器0中断服务程序
/////////////////////////////////////////////////////
void timer0_50ms (void) interrupt 1 using 3
{
TH0=0x4c;
// TL0=0x00;
//TH0=0xfa;
TL0=0x00;
time_start++;
time_count++;
}
/***************************************************/
//delay05S()延时程序
/***************************************************/
void delay05S(void)
{
uchar i,b;
for(i=0x10;i>0;i--)
{
for(b=0x10;b>0;b--);
}
}
/***************************************************/
//delay1S()延时程序
/***************************************************/
void delay1S(void)
{
uint i,b;
for(i=0x1ff;i>0;i--)
{
for(b=0xaf;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(first_sel==0)
{
D1=D2=D3=D4=0;
working_flag=1;
step=0x01;
}
if(first_power_on==0)
{
first_power_on=1;
}
else
{
step=0x03;
heathigh=1;
}
first_sel=1;
time_fly1=0;
time_fly=0;
bell=0;
mode=0x01;
// bell_style=0x02;
}
//***********************************************
//mid(); 中加热程序
//***********************************************
void mid(void)
{
TR0=1;
TR1=0;
bell=0;
if(first_sel==0)
{
D1=D2=D3=D4=0;
working_flag=1;
step=0x01;
}
if(first_power_on==0)
{
first_power_on=1;
}
else
{
step=0x03;
heathigh=1;
}
first_sel=1;
time_fly1=0;
time_fly=0;
mode=0x02;
}
//***********************************************
//lack(); 弱加热程序
//***********************************************
void lack(void)
{
TR0=1;
TR1=0;
//D1=D2=D3=D4=0;
if(first_sel==0)
{
D1=D2=D3=D4=0;
working_flag=1;
step=0x01;
}
first_sel=1;
time_start=0x00;
time_fly1=0;
time_fly=0;
bell=0;
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=5600;
//larmlight=0;
//TR0=0;
liaocheng++;
first_sel=0;
flsh_sector_wr(0x1000,0x01,&liaocheng);
TR1=1;
bell_style=0x01;
}
////////////////////////////////////////////////
if((D1==1)&(liaocheng<10))
{
mode=0x00;
first_sel=0;
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;
//power_flag=0;
heathigh=0;
}
if((time_count>200)&(liaocheng<10))
{
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>=10)
{
TR1=1;
TR0=0;
power_flag=0;
if(Door==0)
{
delay05S();
liaocheng=0x00;
flsh_sector_wr(0x1000,0x01,&liaocheng);
}
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=0;
mode=0x00;
}
}
/****************************************************/
void bell_of_key(void)
{
bell=1;
delay1S();
bell=0;
}
//*********************************************
//power();
//************************************************
void power(void)
{
if(power_flag)
{
bell_of_key();
// 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;
first_power_on=0;
first_sel=0;
strong_key=mid_key=lack_key=0;
on_off=1;
step=0x01;
mode=0x00;
time_fly1=0x00;
time_fly=0x00;
larmlight=1;
time_count=0x00;
liaocheng=0x00;
heatlow=0;heathigh=0;
}
else
{
// P3M1=_bin(1,0,1,1,1,1,0,0);
bell_of_key();
first_sel=0;
D1=D2=D3=D4=1;
on_off=1;
TR0=0;
TR1=0;
first_power_on=0;
bell=0;
// step=0x01;
time_count=0x00;
strong_key=mid_key=lack_key=1;
power_flag=1;
time_start=0x00;
heatlow=1;
flsh_sector_rd(0x1000,0x01,&liaocheng);
}
}
/*
void trating(void)
{
if(!first_power_on)
{
first_power_on=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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -