📄 main.c
字号:
/*****************************************************************
* 浙江大学仪器系短学期实习项目:
* 电仪2004级
* 小组成员:韩灿 刘清文 赵岩 许琳燕
*
* 文件名 :
* 开发人 :韩灿
* 开发时间:2007-8-20
* 版本 : v1。1
* 修改者 : 韩灿 刘清文
* 修改时间:2007-8-31
* 修改说明:增加了状态机中上下限的读取
******************************************************************/
#include<statement.h>
#include<serial.h>
#include<18b20.h>
unsigned char flag;
unsigned char low1,low2,high1,high2,H,L;
unsigned char t, zz, key;
typedef enum { defaultState, currentTemp, transTemp,lowestTemp,highestTemp,high_alarm,low_alarm}Statement;
static Statement currentState = defaultState;
/*****************************************************************
* 函数名 : statementmach
* 功能 : 状态机
* 输入参数:
* Param1:unsigned char key
* Param2:
* Param3:
* 输出参数:
* Param1:
* Param2:
* Param3:
* 返回值 :
******************************************************************/
void statementmach(unsigned char key)
{
switch( currentState)
{
case defaultState : /////////////////
if(key==S0)
{
defaultDisplay(flag);
currentState = defaultState;
}
if (key == S1)
{
currentTempDisplay(t,zz);
currentState = currentTemp;
}
if(key == S2)
{
transTempDisplay(t,zz);
currentState = transTemp;
}
if(key==0xff)
{
defaultDisplay(flag);
currentState = defaultState;
}
break;
case currentTemp: /////////////////
if(key == S2)
{
transTempDisplay(t,zz);
currentState = transTemp;
}
if(key==S0)
{
defaultDisplay(flag);
currentState = defaultState;
}
if (key == S1)
{
lowestTempDisplay(low1,low2);
currentState = lowestTemp;
}
if (key == 0xff)
{
currentTempDisplay(t,zz);
currentState = currentTemp;
}
break;
case transTemp: ////////////////
if(key == S2)
{
high_alarmDisplay(H);
currentState = high_alarm;
}
if(key==S0)
{
defaultDisplay(flag);
currentState = defaultState;
}
if (key == S1)
{
currentTempDisplay(t,zz);
currentState = currentTemp;
}
if (key == 0xff)
{
transTempDisplay(t,zz);
currentState = transTemp;
}
break;
case high_alarm:
if(key==S0)
{
defaultDisplay(flag);
currentState = defaultState;
}
if (key == S1)
{
currentTempDisplay(t,zz);
currentState = currentTemp;
}
if(key == S2)
{
low_alarmDisplay(L);
currentState = low_alarm;
}
if (key == 0xff)
{
high_alarmDisplay(H);
currentState = high_alarm;
}
break;
case low_alarm:
if(key==S0)
{
defaultDisplay(flag);
currentState = defaultState;
}
if (key == S1)
{
currentTempDisplay(t,zz);
currentState = currentTemp;
}
if(key==S2)
{
transTempDisplay(t,zz);
currentState = transTemp;
}
if (key == 0xff)
{
low_alarmDisplay(L);
currentState = low_alarm;
}
break;
case lowestTemp: //////////////
if (key ==S1)
{
highestTempDisplay(high1,high2);
currentState = highestTemp;
}
if(key==S0)
{
defaultDisplay(flag);
currentState = defaultState;
}
if(key == S2)
{
transTempDisplay(t,zz);
currentState = transTemp;
}
if (key == 0xff)
{
lowestTempDisplay(low1,low2);
currentState = lowestTemp;
}
break;
case highestTemp:
if(key==S0)
{
defaultDisplay(flag);
currentState = defaultState;
}
if (key == S1)
{
currentTempDisplay(t,zz);
currentState = currentTemp;
}
if(key == S2)
{
transTempDisplay(t,zz);
currentState = transTemp;
}
if (key == 0xff)
{
highestTempDisplay(high1,high2);
currentState = highestTemp;
}
break;
default:
break;
}
}
void main()
{
unsigned char *z;
unsigned char trdata[6],t2,rec[3];
unsigned char i,j,k;
init_serialcomm();
t=readtemp(z);
low1=high1=t;
low2=high2=*z;
j=0;
rec[0]=0x20;
rec[1]=0x00;
while(1)
{
t=readtemp(z);
zz=*z;
if(low1>t) {low1=t;low2=*z;} /////判断最高最低温度
if(low1==t)
{
if(low2>*z) {low1=t;low2=*z;}
}
if(high1<t) {high1=t;high2=*z;}
if(high1==t)
{
if(high2<*z) {high1=t;high2=*z;}
}
if(!H_KEY)
{
delay10ms(20);
key = read (READ);
statementmach(key);
}
else
{
key=0xff;
statementmach(key);
}
i=0;
t2=zz;
trdata[0]=0xff;
trdata[1]=t;
trdata[2]=t2;
trdata[3]=0x01;
trdata[4]=flag;
trdata[5]=0x00;
while(i<6){
SBUF=trdata[i];
while(TI==0);
TI=0;
i++;
}
if(RI==1){
rec[j%2]=SBUF;
RI=0;
j++;
}
H=rec[0];
L=rec[1];
if(t>=H|t<L) {p27=0;sent_byte(0x88);} //超过报警上下限时报警
else {p27=1;sent_byte(0xa4);}
if(p00==1) flag=0x01;
else flag=0x02;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -