我以前设计的一台仪器的程序中有类似的东西,看下这个函数**********************************************************************
Function name: SetParameter()
Parameter:void
Return: void
Description: set test parameter
Version: 0.0
Author:Bill Liu
Last update date: 2015/10
**********************************************************************/
void SetParameter()
{
static ui8 spt = 0; //define first into set parameter interface flag
static ui8 spn = 1; // define parameter number variable
static ui8 i = 0;
ui8 ktem = 0; //define keyboard in temp variable
if(spt == 0)
{
Soundbell100ms();
LCDClearScreen(); // clear screen
memset(interface.String,0,strlen(interface.String));
spt = 1;
LCDDisplayString(1, 0,"Dis:");
LCDDisplayString(1, 10,"II:");
LCDDisplayString(2, 0,"Speed:");
LCDDisplayString(3, 0,"Freq:");
LCDDisplayString(4, 0,"T_Cycle:");
Displayfloat(1,4,parameter.Displacement,1);
DisplayLongInt(1,13,parameter.WCycles);
DisplayLongInt(2,6,parameter.SpeedL);
DisplayLongInt(3,5,parameter.SpeedC);
DisplayLongInt(4,8,parameter.TCycleValue);
LCDCurPOn(1, 4);
}
Delayxms(200,SYSCLOCK);
ktem = GetKeyboardIn();
switch(ktem)
{
case 0x70: //F1 key down
spt = 0;
interface.flag = 'P'; //to set accelerate interface
break;
case 0x26: //Arrow(up) key down
Soundbell100ms();
switch(spn)
{
case 1:
memset(interface.String,0,strlen(interface.String));
i = 0;
LCDDisplayString(1,4," ");
Displayfloat(1,4,parameter.Displacement,1);
spn = 5;
LCDCurPOn(4, 8);
break;
case 2:
memset(interface.String,0,strlen(interface.String));
i = 0;
LCDDisplayString(1,13," ");
DisplayLongInt(1,13,parameter.WCycles);
spn = 1;
LCDCurPOn(1, 4);
break;
case 3:
memset(interface.String,0,strlen(interface.String));
i = 0;
LCDDisplayString(2,6," ");
DisplayLongInt(2,6,parameter.SpeedL);
spn = 2;
LCDCurPOn(1, 13);
break;
case 4:
memset(interface.String,0,strlen(interface.String));
i = 0;
LCDDisplayString(3,5," ");
DisplayLongInt(3,5,parameter.SpeedC);
spn = 3;
LCDCurPOn(2, 6);
break;
case 5:
memset(interface.String,0,strlen(interface.String));
i = 0;
LCDDisplayString(4,8," ");
DisplayLongInt(4,8,parameter.TCycleValue);
spn = 4;
LCDCurPOn(3, 5);
break;
}
break;
case 0x28: //Arrow(down) key down
Soundbell100ms();
switch(spn)
{
case 1:
memset(interface.String,0,strlen(interface.String));
i = 0;
LCDDisplayString(1,4," ");
Displayfloat(1,4,parameter.Displacement,1);
spn = 2;
LCDCurPOn(1, 13);
break;
case 2:
memset(interface.String,0,strlen(interface.String));
i = 0;
LCDDisplayString(1,13," ");
DisplayLongInt(1,13,parameter.WCycles);
spn = 3;
LCDCurPOn(2, 6);
break;
case 3:
memset(interface.String,0,strlen(interface.String));
i = 0;
LCDDisplayString(2,6," ");
DisplayLongInt(2,6,parameter.SpeedL);
spn = 4;
LCDCurPOn(3, 5);
break;
case 4:
memset(interface.String,0,strlen(interface.String));
i = 0;
LCDDisplayString(3,5," ");
DisplayLongInt(3,5,parameter.SpeedC);
spn = 5;
LCDCurPOn(4, 8);
break;
case 5:
memset(interface.String,0,strlen(interface.String));
i = 0;
LCDDisplayString(4,8," ");
DisplayLongInt(4,8,parameter.TCycleValue);
spn = 1;
LCDCurPOn(1, 4);
break;
}
break;
case 0x1B: //Esc key down
spt = 0;
spn = 1;
i = 0;
LCDCurOff();
GetSpeedL(parameter.SpeedC, parameter.Displacement);
if(parameter.SpeedL>7500)
{
parameter.SpeedL = 7500;
if(mode.testmode == 1)
parameter.SpeedC = parameter.SpeedL * 30 / parameter.Displacement;
}
InitPCAflag = 0;
interface.flag = '2'; //enter new test interface
break;
case 0x6C://Enter key down
Soundbell100ms();
switch(spn)
{
case 1:
if(interface.String[0] != 0)
parameter.Displacement = atof(interface.String);
memset(interface.String,0,strlen(interface.String));
if(parameter.Displacement <0.1 )
parameter.Displacement = 0.1;
else if(parameter.Displacement > 100)
parameter.Displacement = 98;
i = 0;
LCDDisplayString(1,4," ");
Displayfloat(1,4,parameter.Displacement,1);
spn = 2;
LCDCurPOn(1, 13);
break;
case 2:
if(interface.String[0] != 0)
parameter.WCycles = atol(interface.String);
memset(interface.String,0,strlen(interface.String));
i = 0;
LCDDisplayString(1,13," ");
DisplayLongInt(1,13,parameter.WCycles);
if(mode.Warning != 0)
{
parameter.Wcounts = parameter.Tcounts + parameter.WCycles;
}
spn = 3;
LCDCurPOn(2, 6);
break;
case 3:
if(interface.String[0] != 0)
parameter.SpeedL = atol(interface.String);
memset(interface.String,0,strlen(interface.String));
if(parameter.SpeedL < 23)
parameter.SpeedL = 23;
else if(parameter.SpeedL > 7500)
parameter.SpeedL = 7500;
memset(interface.String,0,strlen(interface.String));
i = 0;
LCDDisplayString(2,6," ");
DisplayLongInt(2,6,parameter.SpeedL);
spn = 4;
LCDCurPOn(3, 5);
break;
case 4:
if(interface.String[0] != 0)
parameter.SpeedC = atol(interface.String);
memset(interface.String,0,strlen(interface.String));
if(parameter.SpeedC>7200)
parameter.SpeedC = 7200;
memset(interface.String,0,strlen(interface.String));
i = 0;
LCDDisplayString(3,5," ");
DisplayLongInt(3,5,parameter.SpeedC);
spn = 5;
LCDCurPOn(4, 8);
break;
case 5:
if(interface.String[0] != 0)
parameter.TCycleValue = atol(interface.String);
memset(interface.String,0,strlen(interface.String));
if(parameter.TCycleValue > 1000000)
parameter.TCycleValue = 1000000;
memset(interface.String,0,strlen(interface.String));
i = 0;
LCDDisplayString(4,8," ");
DisplayLongInt(4,8,parameter.TCycleValue);
spn = 1;
LCDCurPOn(1, 4);
break;
}
break;
default:
if(ktem > 0x29 && ktem <=0x39 )
{
Soundbell100ms();
interface.String[i] = ktem;
i++;
switch(spn)
{
case 1:
LCDDisplayString(1,4," ");
LCDDisplayString(1,4,interface.String);
break;
case 2:
LCDDisplayString(1,13," ");
LCDDisplayString(1,13,interface.String);
break;
case 3:
LCDDisplayString(2,6," ");
LCDDisplayString(2,6,interface.String);
break;
case 4:
LCDDisplayString(3,5," ");
LCDDisplayString(3,5,interface.String);
break;
case 5:
LCDDisplayString(4,8," ");
LCDDisplayString(4,8,interface.String);
break;
}
}
break;
}
}
//End of function SetParameter() |