您好,欢迎访问三七文档
#includereg52.h#includestdio.h#includestring.h#includestdlib.h#defineuintunsignedint#defineucharunsignedcharuintidatanum=0;//ʽ×Ó³¤¶Èbitflag=0,cal_ov_fl=0;//±êÖ¾floatidatanumbers[5]='\0';//ʽ×ÓÖÐÊý×Ö¸öÊýucharidataqvfu_geshu=0;//²»Ë㸺ºÅºÍСÊýµãµÄ·ûºÅ¸öÊýucharidataqvkuo_geshu=0;//²»Ë㸺ºÅ¡¢Ð¡Êýµã¡¢À¨ºÅ¡¢µÈºÅµÄ·ûºÅ¸öÊýucharidataqvfu_signs[8]='\0';//²»Ë㸺ºÅ¡¢Ð¡Êýµã¡¢À¨ºÅ¡¢µÈºÅµÄ·ûºÅucharidataqvfu_weizhi[8]='\0';//²»Ë㸺ºÅ¡¢Ð¡Êýµã¡¢À¨ºÅ¡¢µÈºÅµÄ·ûºÅλÖÃucharidatastate[20]=\0;//ʽ×Óucharidatares_str[10]='\0';//×Ö·û´®Êä³öucharidatai=0;sbitBEE=P1^5;sbitLED=P0;//·ÖÀëÌáÈ¡Êý×Övoidapart(char*state){intj=0,m=0;intfloat_sign=0;//¸¡µãÐÍÊý×Ö±êÖ¾intfloat_weizhi=0;//СÊýµãÔÚ¸¡µãÊýµÄλÖÃchartemp[5]=\0\0;//ÌáÈ¡Êý×ÖÒªÓõ½µÄÖмäÊý×éintnum_num=0;//Êý×Ö¸öÊýintweizhi[8]='\0';//·ûºÅ£¨²»°üÀ¨Ð¡Êýµã£©Î»ÖÃintgeshu=0;//·ûºÅ¸öÊý£¨²»°üÀ¨Ð¡Êýµã£©charsigns[10]='\0';//·ûºÅ£¨²»°üÀ¨Ð¡Êýµã£©num=strlen(state);//ʽ×Ó×Ö·û´®³¤¶Èfor(i=0;inum;i++)//È¡³ö·ÇÊý×Ö·ûºÅ{if((state[i]48||state[i]57)&&state[i]!='.'){weizhi[geshu]=i;signs[geshu]=state[i];geshu++;}}for(i=0;igeshu;i++)//È¥³ý¸ººÅ{if(signs[i]!='-'){qvfu_signs[qvfu_geshu]=signs[i];//ÕÒ³ö·Ç'-'±êÖ¾qvfu_weizhi[qvfu_geshu]=weizhi[i];qvfu_geshu++;}else{if((weizhi[i]!=(weizhi[i-1]+1))||(weizhi[i]==(weizhi[i-1]+1))&&signs[i-1]==')')//ÊÇ-£¬µ«²»ÊǸººÅ{qvfu_signs[qvfu_geshu]=signs[i];//ÕÒ³ö·Ç¸ººÅqvfu_weizhi[qvfu_geshu]=weizhi[i];qvfu_geshu++;}}}for(i=0;iqvfu_geshu;i++)//È¥³ýÀ¨ºÅ,µÈºÅ{if(qvfu_signs[i]!='('&&qvfu_signs[i]!=')'&&qvfu_signs[i]!='='){qvkuo_geshu++;}}//È¡Êý×Önumbers[0]=0;if(state[0]!='(')//µÚÒ»¸öλÖÃÉÏÊÇ¡°£¨¡±{for(i=0;inum;i++){if(state[i]=48&&state[i]=57||state[i]=='.'){if(temp[0]=='-')//¸ºÊý{temp[m]=state[i];if(state[i]=='.')//¸¡µãÊý{float_sign=1;float_weizhi=m;}else{numbers[num_num]=(temp[m]+numbers[num_num]-48)*10;m++;}}else//·Ç¸ºÊý{temp[m]=state[i];if(state[i]=='.')//СÊý{float_sign=1;float_weizhi=m;}else{numbers[num_num]=(temp[m]+numbers[num_num]-48)*10;m++;}}}else{if(((state[i-1]==')'||(state[i-1]=48&&state[i-1]=57))&&state[i]=='-')||state[i]=='+'||state[i]=='*'||state[i]=='/'||state[i]=='=')//Êý×Ö½áÊø{numbers[num_num]=numbers[num_num]/10;if(float_sign!=0)//ÊǸ¡µãÊý{for(j=0;j(m-float_weizhi);j++){numbers[num_num]=numbers[num_num]/10.0;}float_sign=0;}if(temp[0]=='-')//¸ºÊý{numbers[num_num]=-numbers[num_num];}else//ÕýÊý{if(float_sign!=0)//ÊÇСÊý{for(j=0;j(m-float_weizhi);j++){numbers[num_num]=numbers[num_num]/10.0;}float_sign=0;}}num_num++;numbers[num_num]=0;m=0;}else//·ûºÅºóÃ滹ÊÇ·ûºÅ{if(state[i]=='-'&&(state[i-1]=='('||i==0))//ÊǸººÅ{temp[0]='-';m=1;}}}}}else//²»ÊÇÒÔÀ¨ºÅ¿ªÊ¼µÄ{for(i=1;inum;i++){if(state[i]=48&&state[i]=57||state[i]=='.'){if(temp[0]=='-')//¸ºÊý{temp[m]=state[i];if(state[i]=='.')//¸ºµÄ¸¡µãÊý{float_sign=1;float_weizhi=m;}else{numbers[num_num]=(temp[m]+numbers[num_num]-48)*10;m++;}}else//·Ç¸ºÊý{temp[m]=state[i];if(state[i]=='.')//·Ç¸ºµÄ¸¡µãÊý{float_sign=1;float_weizhi=m;}else{numbers[num_num]=(temp[m]+numbers[num_num]-48)*10;m++;}}}else{if(((state[i-1]==')'||(state[i-1]=48&&state[i-1]=57))&&state[i]=='-')||state[i]=='+'||state[i]=='*'||state[i]=='/'||state[i]=='=')//Êý×Ö½áÊø{numbers[num_num]=numbers[num_num]/10;if(float_sign!=0)//ÊǸ¡µãÊý{for(j=0;j(m-float_weizhi);j++){numbers[num_num]=numbers[num_num]/10.0;}float_sign=0;}if(temp[0]=='-')//¸ºÊý{numbers[num_num]=-numbers[num_num];}else//ÕýÊý{if(float_sign!=0)//ÊÇСÊý{for(j=0;j(m-float_weizhi);j++){numbers[num_num]=numbers[num_num]/10.0;}float_sign=0;}}num_num++;numbers[num_num]=0;m=0;}else//·ûºÅºóÃ滹ÊÇ·ûºÅ{if(state[i]=='-'&&(state[i-1]=='('||i==0))//ÊǸººÅ{temp[0]='-';m=1;}}}}}}//¼ÆËãfloatCALCULATE(char*state)//,floatnumbers[],intnum,intqvfu_geshu,intqvfu_weizhi[]){ucharidataj=0;ucharidatak=0;ucharidatasign_num=0;ucharidatanums_num=0;ucharidataorder=1;ucharidatanum_order[15]='\0';ucharidatanumorder=0;ucharidatasign_order[15]='\0';ucharidatasignorder=0;ucharidatanum_zuo=0;ucharidatanum_you=0;floatidatanum1_temp=0;floatidatanum2_temp=0;ucharidatachengchu_weizhi=0;ucharidatajiajian_weizhi=0;ucharidataweizhi_zuo=0;ucharidataweizhi_you=0;ucharidatachengchu=0;ucharidatajiajian=0;if(state[0]=='(')//´ÓÀ¨ºÅ¿ªÊ¼{sign_order[0]=0;num_order[0]=1;for(k=1;kqvfu_geshu;k++)//·ûºÅ¿ªÊ¼{if(qvfu_weizhi[k]-qvfu_weizhi[k-1]1)//Êý×Ö·ûºÅ°´ÕÕʽ×ÓµÄ˳ÐòÅÅÐò{num_order[numorder]=order;numorder++;order++;}signorder++;sign_order[signorder]=order;order++;}for(i=0;iqvfu_geshu;i++)//È¥³ýÀ¨ºÅ,µÈºÅ{if(qvfu_signs[i]!='('&&qvfu_signs[i]!=')'&&qvfu_signs[i]!='='){qvkuo_geshu++;}}order=1;//¸´Î»for(i=0;iqvfu_geshu-1;i++){if(qvfu_signs[i]=='(')//À¨ºÅÄÚµÄÔËËã{weizhi_zuo=qvfu_weizhi[i];//×óÀ¨ºÅÔÚʽ×ÓÖеÄλÖÃnum_zuo=i;//×óÀ¨ºÅÔÚ·ûºÅÐòÁÐÖеÄλÖÃ}if(qvfu_signs[i]==')'){num_you=i;//ÓÒÀ¨ºÅÔÚ·ûºÅÐòÁÐÖеÄλÖÃweizhi_you=qvfu_weizhi[i];//ÓÒÀ¨ºÅÔÚʽ×ÓÖеÄλÖÃfor(j=num_zuo+1;jnum_you;j++)//À¨ºÅÖеķûºÅ{for(k=0;knumorder;k++){if(num_order[k]==sign_order[j]-1){num1_temp=numbers[k];//·ûºÅ×ó±ßµÄÊý×Ö}if(num_order[k]==(sign_order[j]+1)){num2_temp=numbers[k];//·ûºÅÓұߵÄÊý×Ö}}switch(qvfu_signs[j])//À¨ºÅÄÚÔËËã{case'+':num1_temp=num1_temp+num2_temp;break;case
本文标题:51串口计算器
链接地址:https://www.777doc.com/doc-4850472 .html