经过两天的奋斗,程序OK了,用STC89C58算起来也不算慢,还是可以的.这是我改过的程序.
void main()
{
uint i;
uint D = 0,M_AB = 0,M_BA = 0; //D指AB两点距离,A到B的方位角,B到A的方位角.
Lcd_Init();
Disp_Wellcom();
Delay(2000);
Disp_Input_A();
Lcd_Writecom(0x92);
while(1)
{
num=20;
i=Keyscan();
switch(i)
{
case 1:
if (times<26)
{
times++;Key_Input(num,times);
}
break;
case 2:
if (times<26)
{
times++;Key_Input(num,times);
}
break;
case 3:
if (times<26)
{
times++;Key_Input(num,times);
}
break;
case 4:
if (times<26)
{
times++;Key_Input(num,times);
}
break;
case 5:
if (times<26)
{
times++;Key_Input(num,times);
}
break;
case 6:
if (times<26)
{
times++;Key_Input(num,times);
}
break;
case 7:
if (times<26)
{
times++;Key_Input(num,times);
}
break;
case 8:
if (times<26)
{
times++;Key_Input(num,times);
}
break;
case 9:
if (times<26)
{
times++;Key_Input(num,times);
}
break;
case 0:
if (times<26)
{
times++;Key_Input(num,times);
}
break;
case 11: //功能键*:复位
ISP_CONTR = 0X20;
break;
case 12: //功能键#:翻页
if (flag_page == 0)
{
Disp_Input_B();
times = times + 13;
flag_page = 1;
}
else if(flag_page == 1)
{
Disp_Input_A();
times = times - 13;
flag_page = 0;
}
break;
case 13: //功能键A:左右移
switch (key_l_r)
{
case 0:
if (0<=times<4)
{
Lcd_Writecom(0x94);
key_l_r = 1;
times = 3;
}
else if (13<=times<17)
{
Lcd_Writecom(0x94);
key_l_r = 1;
times = 16;
}
else if (7<=times<10)
{
Lcd_Writecom(0x9c);
key_l_r = 1;
times = 9;
}
else if (20<=times<23)
{
Lcd_Writecom(0x9c);
key_l_r = 1;
times = 22;
}
break;
case 1:
if (3
{
Lcd_Writecom(0x96);
key_l_r = 2;
times = 5;
}
else if (16
{
Lcd_Writecom(0x96);
key_l_r = 2;
times = 18;
}
else if (9
{
Lcd_Writecom(0x9c);
key_l_r = 2;
times = 11;
}
else if (22
{
Lcd_Writecom(0x9c);
key_l_r = 2;
times = 24;
}
break;
case 2:
if (5
{
Lcd_Writecom(0x92);
key_l_r = 0;
times = 0;
}
else if (18
{
Lcd_Writecom(0x92);
key_l_r = 0;
times = 13;
}
else if (11
{
Lcd_Writecom(0x99);
key_l_r = 0;
times = 7;
}
else if (24
{
Lcd_Writecom(0x99);
key_l_r = 0;
times = 20;
}
break;
default:
break;
}
break;
case 14: //功能键B:
break;
case 15: //功能键C:返回
Lcd_Init();
Delay(10);
Disp_Input_A();
times=0;flag_page=0;
LonA_D = 0;LonA_F = 0;LonA_M = 0;LatA_D = 0;LatA_F = 0;LatA_M = 0;
LonB_D = 0;LonB_F = 0;LonB_M = 0;LatB_D = 0;LatB_F = 0;LatB_M = 0;
break;
case 16: //功能键D:确定
if (times == 26)
{
LonA_D = max(AJD_1,AJD_2,AJD_3);
LonA_F = max(AJF_1,AJF_2,temp_val);
LonA_M = max(AJM_1,AJM_2,temp_val);
LatA_D = max(AWD_1,AWD_2,AWD_3);
LatA_F = max(AWF_1,AWF_2,temp_val);
LatA_M = max(AWM_1,AWM_2,temp_val);
LonB_D = max(BJD_1,BJD_2,BJD_3);
LonB_F = max(BJF_1,BJF_2,temp_val);
LonB_M = max(BJM_1,BJM_2,temp_val);
LatB_D = max(BWD_1,BWD_2,BWD_3);
LatB_F = max(BWF_1,BWF_2,temp_val);
LatB_M = max(BWM_1,BWM_2,temp_val);
JA = (float)LonA_D+(float)LonA_F/60+(float)LonA_M/3600; //
WA = (float)LatA_D+(float)LatA_F/60+(float)LatA_M/3600; // 35.06666>0.818484
JB = (float)LonB_D+(float)LonB_F/60+(float)LonB_M/3600; //118.93333-118.83333>0.999998
WB = (float)LatB_D+(float)LatB_F/60+(float)LatB_M/3600; // 35.03333>0.818818
Angle_AB = cos(WA*Rad)*cos(WB*Rad)*cos((JB-JA)*Rad)+sin(WA*Rad)*sin(WB*Rad);
Distance = R*acos(Angle_AB);
D = Distance*1000;
M_AC = R*Rad*cos(WA*Rad)*0.1;
M = acos(M_AC/Distance)*3000/3.1415926;
if (WA > WB) //如果A点纬度高,结果要加1500
{
M_AB = 1500 + M;
M_BA = 4500 + M;
}
else if(WA < WB) //如果A点纬度低,结果要用1500减
{
M_AB = 1500 - M;
M_BA = 4500 - M;
}
Disp_Output(D,M_AB,M_BA);
times = 30;flag_page = 5;
}
break;
default: break;
}
}
} |