include "REG52.H"
#include"intrins.h"
#include"12864.h"
#include"ds1302.h"
uint num,maibo;
bit wanbiflag=0;
sbit k1=P1^0;
sbit k2=P2^0;
sbit LED=P1^4;
uint i,time;
int n=0;
void Bee_Speak(unsigned int t)
{
LED=0;
delay(t);
LED=1;
delay(t);
}
void t0_init() //定时器、计数器设置函数
{
TMOD=0x11; //指定定时/计数器的工作方式为3
TH1=0; //定时器T0的高四位=0
TL1=0; //定时器T0的低四位=0
IT1=1;
EA=1; //系统允许有开放的中断
ET1=1; //允许T0中断
// EX1=1;
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
ET0=1;
TR0=0;
TR1=1; //开启中断,启动定时器
}
void main()
{
lcd_init();
ds1302_init();
Locat_XY(0,0);
Write_Datas("00时00分00秒");
t0_init();
while(1)
{
if(k1==0)
{
Locat_XY(0,1);
Write_Datas("开始测量");
Locat_XY(0,2);
Write_Datas(" ");
i=0;
time=200;
num=0;
EX1=1;
TR0=1;
wanbiflag=0;
}
if(k2==0)
{
EX1=1;
}
}
}
void int0() interrupt 2
{
num=num++;
}
void t0() interrupt 1
{ uchar Temp_Data[3] ;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
i=i+1;
if(i==time)
{
EX1=0;
TR0=0;
Temp_Data[n]=num-2;
n++;
}
if (n=3)
{ maibo= (Temp_Data[0]+Temp_Data[1]+Temp_Data[2])/3;
maibo=maibo*6;
wanbiflag=1;
}
if((maibo>120)||(maibo<50)){Bee_Speak(50);Bee_Speak(50);Bee_Speak(50);}//上下限报警
}
void timer1() interrupt 3
{
fen = BCD_Decimal(read_1302(0x83));
shi = BCD_Decimal(read_1302(0x85));
miao = BCD_Decimal(read_1302(0x81));
write_date(0x82,fen);
write_date(0x80,shi);
write_date(0x84,miao);
Locat_XY(5,1);
Write_Dat(num/1000+'0');
Write_Dat(num%1000/100+'0');
Write_Dat(num%100/10+'0');
Write_Dat(num%10+'0');
if(wanbiflag==1)
{
Locat_XY(0,1);
Write_Datas("测量完毕");
Locat_XY(0,2);
Write_Dat(maibo/1000+'0');
Write_Dat(maibo%1000/100+'0');
Write_Dat(maibo%100/10+'0');
Write_Dat(maibo%10+'0');
wanbiflag=0;
}
}
|