|
我用到了while循环,目前方便起见,我把while部分的代码贴出来了
增加有色字体部分会出现不定时复位的现象
while(1)
{
flag = 0;
if((key1click == 1)&&(IsKey1Click == false))
{
delay_NOP(1000);
if ((P1IN&BIT0) == 0)
IsKey1Click = true;
key1click = 0;
gLongKeyTimer = 0;
}
if(IsKey1Click == true)
{
if (gLongKeyTimer > 3)
{
IsKey1Click = false;
ucCurKeyValue = 0;
keyvalue=0x60;
}
else if ((P1IN&BIT0) != 0)
{
IsKey1Click = false;
keyvalue=0x51;
}
}
switch(SCREENSTATE)
{
case 0:
{
DisplayMeterAddr();
switch(keyvalue)
{
case 0x51:
SCREENSTATE=1;
break;
case 0x54:
break;
default:
break;
}
}
break;
case 1:
{
DisplayInsFlow(0);
switch(keyvalue)
{
case 0x51:
SCREENSTATE=2;
break;
case 0x60:
gFlag_StartSetZero=true;
SCREENSTATE=250;
break;
default:
break;
}
}
break;
case 2:
{
DisplayCumFlow2();
switch(keyvalue)
{
case 0x51:
SCREENSTATE=3;
break;
default:
break;
}
}
break;
case 3:
{
DisplayTemp(0);
switch(keyvalue)
{
case 0x51:
SCREENSTATE=4;
break;
default:
break;
}
}
break;
case 4:
{
DisplayTemp(1);
switch(keyvalue)
{
case 0x51:
SCREENSTATE=5;
break;
default:
break;
}
}
break;
case 5:
{
DisplayTemp(2);
switch(keyvalue)
{
case 0x51:
SCREENSTATE=6;
break;
default:
break;
}
}
break;
case 6:
{
DisplaySysTime(0);
switch(keyvalue)
{
case 0x51:
SCREENSTATE=7;
break;
default:
break;
}
}
break;
case 7:
{
DisplaySysTime(1);
switch(keyvalue)
{
case 0x51:
SCREENSTATE=0;
break;
default:
break;
}
}
break;
case 101:
break;
case 250:
DisplayCalib();
switch(keyvalue)
{
case 0x51:
SCREENSTATE=1;
break;
default:
break;
}
break;
default:
break;
}
keyvalue=0;
CurTimer_1s = Timer_1s;
CurTimer_500ms = Timer_500ms;
if(Timer_1s%5==0)
{
testtempfunc();
}
GP2_init();
fire_flag=0;
timer500ms_flag=0;
VCC_OFF;
VCA_OFF;
VCB_OFF;
flag =MeasDeltaTime(&lTOF,IsFirstDownFlow);
#if CALCULATETIME
if (flag == RET_OK)
{
if (CaculateDeltaTime(lTOF,&SampleBufLen) != 1)
counter_overflow++;
else
{
counter_overflow = 0;
CalibAndCorrect();
#if 0
gInsFlow = (float)glCurSampleData*23120.57; gInsFlow /=ulTOF_counterflow0 ; gInsFlow *=224 ; gInsFlow /=ulTOF_downflow0 ; gInsFlow*=3600 ;
if (CurTimer_500ms != oldCacuTimer_500ms) {
if (CurTimer_500ms > oldCacuTimer_500ms)
t = 0.5 * (CurTimer_500ms - oldCacuTimer_500ms);
else
t = 0.5 * (CurTimer_500ms + 120 - oldCacuTimer_500ms);
oldCacuTimer_500ms = CurTimer_500ms;
fmid = gInsFlow*t;
fmid *=277.7778;
glCumFlow +=fmid;
} #endif
}
gSensorFault = false;
counter_overflow = 0;
}
else if (flag != 0)
{
if (counter_overflow > 10)
{
gSensorFault = true;
if (flag == TDC_FAULT)
{
GP2_init();
delay_NOP(1000); //10ms
counter_overflow = 0;
}
}
else
counter_overflow++;
}
#endif
} |
|