你们一群绝对蛋疼的人啊
楼主给你发一个我上个月做课程设计写的,乱的不得了的计算器把。不过精度好像不高!。。。
/*计算器,在菜单界面按3进入*/
void Calculator () _task_ 6
{
uchar step=0,step0=0,n=0,m;
char step2=-1;
char calculate[10]={0};
long int calculate2[10]={0};
Check_Busy();Disp_HZ(0x80,calculator_word1,16);Check_Busy();Disp_HZ(0x90,calculator_word2,16);Delay(200);
while(1){
if((key == 0)|(key == 1)|(key == 2)|(key == 3)|(key == 4)|(key == 5)|(key == 6)|(key == 7)|(key == 8)|(key == 9))
{
Check_Busy();Disp_ZF(0x90+step,key+48);calculate[step]=key;step++;Delay(200);
}
else if((key =='B')| (key =='O')|(key =='S')|(key =='R'))
{
switch(key)
{
case 'B':Check_Busy();Disp_ZF(0x90+step,'+');calculate[step]=key;step++;Delay(200);break;
case 'O':Check_Busy();Disp_ZF(0x90+step,'-');calculate[step]=key;step++;Delay(200);break;
case 'S':Check_Busy();Disp_ZF(0x90+step,'*');calculate[step]=key;step++;Delay(200);break;
case 'R':Check_Busy();Disp_ZF(0x90+step,'/');calculate[step]=key;step++;Delay(200);break;
}
step0 = step;
for(;(step0-step2-2)>0;step0--)
{
calculate2[n] = calculate2[n] + calculate[step0-2]*pow(10,step-step0);
}
step2=step-1;
n++;
calculate2[n]=calculate[step-1];
n++;
}
else if((key == 'X'))
{
Check_Busy();Disp_ZF(0x88,'=');Delay(200);
step0 = step;
for(;(step0-step2-1)>0;step0--)
{
calculate2[n] = calculate2[n] + calculate[step0-1]*pow(10,step-step0);
}
for(m=0;m<(n/2);m++)
{
switch(calculate2[m*2+1])
{
case 'B':calculate2[m*2+2]=calculate2[m*2]+calculate2[m*2+2];break;
case 'O':calculate2[m*2+2]=calculate2[m*2]-calculate2[m*2+2];break;
case 'S':calculate2[m*2+2]=calculate2[m*2]*calculate2[m*2+2];break;
case 'R':calculate2[m*2+2]=calculate2[m*2]/calculate2[m*2+2];break;
}
}
Check_Busy;Disp_ZF(0x89,48+calculate2[(m+1)*2-2]%10000000/1000000);
Check_Busy;Disp_ZF(0x8a,48+calculate2[(m+1)*2-2]%1000000/100000);
Check_Busy;Disp_ZF(0x8b,48+calculate2[(m+1)*2-2]%100000/10000);
Check_Busy;Disp_ZF(0x8c,48+calculate2[(m+1)*2-2]%10000/1000);
Check_Busy;Disp_ZF(0x8d,48+calculate2[(m+1)*2-2]%1000/100);
Check_Busy;Disp_ZF(0x8e,48+calculate2[(m+1)*2-2]%100/10);
Check_Busy;Disp_ZF(0x8f,48+calculate2[(m+1)*2-2]%10); Delay(200);
}
else if(key=='Y')
{
if(step!=0)
{
step=0;step0=0;step2=-1;n=0;
calculate[0]=0;calculate[1]=0;calculate[2]=0;calculate[3]=0;calculate[4]=0;
calculate[5]=0;calculate[6]=0;calculate[7]=0;calculate[8]=0;calculate[9]=0;
calculate2[0]=0;calculate2[1]=0;calculate2[2]=0;calculate2[3]=0;calculate2[4]=0;
calculate2[5]=0;calculate2[6]=0;calculate2[7]=0;calculate2[8]=0;calculate2[9]=0;
Check_Busy();Disp_HZ(0x80,calculator_word1,16);Check_Busy();Disp_HZ(0x90,calculator_word2,16);Delay(200);
}
else {os_create_task(1);os_delete_task(6);}
}
}
}
能不能看得懂就看楼主造化了哈,因为我现在也看不懂了哈 |