前言:
今天各位老铁们对“计算器怎么求mod”可能比较关切,兄弟们都需要了解一些“计算器怎么求mod”的相关内容。那么小编在网上搜集了一些有关“计算器怎么求mod””的相关文章,希望朋友们能喜欢,姐妹们一起来学习一下吧!一,用矩阵键盘操作原理图(仿真)
2.主程序(源代码)
#include<reg51.H>//#include<stdio.h>#define LEDS 8/***°´¼ü³ÌÐò***/char keyscan();/***ÏÔʾ³ÌÐò***/ void display();char dsp[9]={0,0,12,12,12,12,12,12,12}; //³õʼ»¯ÏÔʾÊý×é/***¼ÆËã³ÌÐò***/ void calculate(char k,char c1[8],char c2[8]); /***Ƭѡ***/unsigned char code Select[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};/***ÂëÑ¡***/ unsigned char code LED_CODES[]= {0xC0,0xF9,0xA4,0xB0,0x99, //0-40x92,0x82,0xF8,0x80,0x90, //5-90x86,0xAF,0xFF,0x7F,0xBF,}; //E,r,¿Õ¸ñ,.,-/***mainº¯Êý***/void main(void){char i,j,k,c;char a[8],b[8];/***¶¨Ê±1ms***/TMOD=0;TL0=-(1000/256);TH0=-(1000%256);EA = 1; //×ÜÖжϿª¹ØET0 = 1; //¿ªÖжÏTR0 = 1; //ÆôÓüÆÊýÆ÷0KSC:do { for(i=1;i<9;i++) //Êý×Ö¼ÈëÑ»· { dsp[0]=keyscan(); if(c==2&&dsp[0]<10) //´Ë¶Î´úÂëÑéÖ¤ÊÇ·ñÓоɵļÆËã½á¹ûÔÚÏÔʾ£¬ÇÒ²»ÔÙ²ÎÓëмÆËã { dsp[1]=dsp[0]; for(j=2;j<9;j++) dsp[j]=12; c=0; } else if(c==2&&dsp[0]>9) //¾ÉµÄ¼ÆËã½á¹û½«²ÎÓëеļÆË㣬×÷ΪµÚÒ»¸öÊý { c=0; } if(dsp[0]==0&&dsp[1]==0&&dsp[2]==12) //¸öλΪ0ÇÒʮλΪ¿Õʱ°´ÏÂ0,°´¼üÎÞЧ£¬Ìø»ØKSCµÈ´ýÕýÈ·ÊäÈë { /***gotoÌøת±êÖ¾***/ goto KSC; } else if(dsp[0]>9) break; //ÓвÙ×÷·û°´Ï£¬Ìø³öÊý×Ö¼ÈëÑ»· else {for(j=i;j>0;j--) dsp[j]=dsp[j-1]; //ÒÆ룬ÒÔÕýÈ·ÏÔʾÊý×Ö } } if(i==9) //ÅжÏÊÇ·ñÊäÈë8¸öÓÐЧÊý×Ö£¬ÊÇÔòµÈ´ý²Ù×÷·û£¬·ñÔòÖ±½ÓÅжϲÙ×÷·û { do //ʹÓÃdo whileÎÞÂÛÊÇ·ñµÚÒ»¸öÊý¶¼È¡Ò»´Î²Ù×÷·û { dsp[0]=keyscan(); //»ñÈ¡²Ù×÷·ûºÅ if(dsp[0]==14||dsp[0]<10) //°´ÏÂC»òÕßµÚ9λÊý×ÖÇåÁã { dsp[1]=0; for(i=2;i<9;i++) dsp[i]=12; c=0; } }while((dsp[0]==15)&&(c==0)); //µÈºÅ±»°´Ï£¬µÈ´ýеIJÙ×÷·û£¨½ö¶ÔµÚÒ»¸öÊý×ÖÓÐЧ£© } else if(dsp[0]==14) //°´ÏÂCÇåÁã { dsp[1]=0; for(i=2;i<9;i++) dsp[i]=12; c=0; } while(dsp[0]==15&&c==0) //δÊäÂú8λÇÒÊǵÚÒ»¸öÊý×Ö¼´°´ÏµȺţ¬µÈ´ý·ÇµÈºÅ²Ù×÷·û { dsp[0]=keyscan(); //»ñÈ¡²Ù×÷·ûºÅ if(dsp[0]==14||dsp[0]<10) //°´ÏÂC»òÕßÊý×Ö¶¼½øÐÐÇåÁã,ÖØÐÂÊäÈëa { dsp[0]=14; //½«dsp[0]ÖÃΪ14£¬·ÀÖ¹ÒòÊý×ÖÇåÁãδÄÜÀ¹½Ø dsp[1]=0; for(i=2;i<9;i++) dsp[i]=12; c=0; } } }while(dsp[0]==14); //Êý×ÖÊäÈëδÍê³É¼´°´ÏÂC£¬ÖØеȴýÊäÈë do { if(c==0) //ûÓÐÊý×ÖÊäÈë { k=dsp[0]; //´æ¼ÆËã·û£¨Ñ»·ÄÚÒÑÅųýC¡¢£½¡¢Êý×Ö£© for(i=0;i<8;i++) //½«µÚÒ»¸öÊý´æÈëa[8] { a[i]=dsp[i+1]; } dsp[1]=0; //ÇåÁã for(i=2;i<9;i++) dsp[i]=12; c=1; //ÒÑÊäÈëa /***gotoÌøת±êÖ¾***/ goto KSC; } else if(c==1) { for(i=0;i<8;i++) //½«µÚ¶þ¸öÊý´æÈëb[8] { b[i]=dsp[i+1]; } c=2; //ÒÑÊäÈëb if(dsp[0]!=15) //bÊäÍêºó²Ù×÷·û²»ÊǵȺŠ{ calculate(k,a,b); for(i=0;i<8;i++) //½«¼ÆËã½á¹û´æÈëa[8]£¬aÖµ¸üР{ a[i]=dsp[i+1]; } k=dsp[0]; //¸üмÆËã·û c=1; /***gotoÌøת±êÖ¾***/ goto KSC; } } }while((dsp[0]==15)&&(c<2)); //Ö±µ½abÊäÈëÍê³ÉÇÒ°´ÏµȺÅcalculate(k,a,b); //½øÐÐ×îºó¼ÆËã/***gotoÌøת±êÖ¾***/goto KSC; //Ìø»ØKSC£¬µÈ´ýÐÂÒ»ÂÖ¼ÆËãwhile(1); //·ÀÖ¹³ÌÐòÅÜ·É}char keyscan(){char KeyL;char KeyR;char j;do { do { P3=0xF0; P3=P3|0xF0;//ÐÐɨÃè11110000 if(P3!=0xF0) { KeyL=P3; P3=0x0F; P3=P3|0x0F;//ÁÐɨÃè00001111 KeyR=P3; } }while(KeyL==0xF0||KeyR==0x0F); for(j=0;j<12;j++) //ÑÓʱ0.001s=1ms {;} }while(P3!=0x0F); switch(KeyL&KeyR) { case 0x28:{return 0;break;} case 0x11:{return 1;break;} case 0x21:{return 2;break;} case 0x41:{return 3;break;} case 0x12:{return 4;break;} case 0x22:{return 5;break;} case 0x42:{return 6;break;} case 0x14:{return 7;break;} case 0x24:{return 8;break;} case 0x44:{return 9;break;} case 0x81:{return 10;break;}//¼Ó·¨(µÚÒ»ÐУ¬µÚËÄÁÐ) case 0x82:{return 11;break;}//¼õ·¨£¨µÚ¶þÐУ¬µÚËÄÁУ© case 0x84:{return 12;break;}//³Ë·¨£¨µÚÈýÐУ¬µÚËÄÁУ© case 0x88:{return 13;break;}//³ý·¨£¨µÚËÄÐУ¬µÚËÄÁУ© case 0x18:{return 14;break;}//ÇåÁ㣨µÚËÄÐУ¬µÚÒ»ÁУ© case 0x48:{return 15;break;}//¼ÆËã½á¹û£¨µÚËÄÐУ¬µÚÈýÁУ© }}void display() interrupt 1 using 1 //ÀûÓö¨Ê±Æ÷ÖжÏʵÏÖ¼äʱÏÔʾ {char i,j,h;ET0=0;for(j=8;j>0;j--) //ɨÃè8´Î { for(i=7;i>=0;i--) //´Ó¸ßλµ½µÍλɨÃèÏÔʾ { P2=0; P1=LED_CODES[dsp[8-i]]; P2=Select[i]; for(h=0;h<8;h++) {;} } }TL0=-(1000/256);TH0=-(1000%256);ET0=1; }void calculate(char k,char a[8],char b[8]){char r[8];long i,x,y;i=0;x=0;y=0;for(i=7;i>0;i--) //Êýֵת»¯£¬½«´ú±í¿Õ¸ñµÄ12ת»¯ÎªÊý×Ö0£¬ÒòΪ¸öλ²»ÏÔʾ¿Õ¸ñ£¬Ä¬ÈÏΪ0£¬ËùÒÔ²»×ª»¯ { while(a[i]==12)a[i]=0; while(b[i]==12)b[i]=0; }x=a[4];x=10000*x;x=x+a[0]+a[1]*10+a[2]*100+a[3]*1000+a[5]*100000+a[6]*1000000+a[7]*10000000;y=b[4];y=10000*y;y=y+b[0]+b[1]*10+b[2]*100+b[3]*1000+b[5]*100000+b[6]*1000000+b[7]*10000000;if(k==10)//¼Ó·¨ÔËËã { x=x+y; if(x>99999999) //´óÓÚ8룬ÏÔʾ¡°Err¡± { r[0]=11; //r r[1]=11; //r r[2]=10; //E r[3]=12; //¿Õ¸ñ r[4]=12; r[5]=12; r[6]=12; r[7]=12; } else { r[0]=x%10; r[1]=(x%100)/10; r[2]=(x%1000)/100; r[3]=(x%10000)/1000; r[4]=(x%100000)/10000; r[5]=(x%1000000)/100000; r[6]=(x%10000000)/1000000; r[7]=x/10000000; } }if(k==11)//¼õ·¨ÔËËã { if(x<y) { x=y-x; if(x>9999999) { r[0]=11; //r r[1]=11; //r r[2]=10; //E r[3]=12; //¿Õ¸ñ r[4]=12; r[5]=12; r[6]=12; r[7]=12; } else { r[0]=x%10; r[1]=(x%100)/10; r[2]=(x%1000)/100; r[3]=(x%10000)/1000; r[4]=(x%100000)/10000; r[5]=(x%1000000)/100000; r[6]=(x%10000000)/1000000; r[7]=x/10000000; for(i=7;i>0;i--) //½«ÓÐЧÊý×ֵĸßһλת»¯Îª£ºÅ { if(r[i]==0&&r[i-1]!=0) { r[i]=14; break; } } } } else { x=x-y; r[0]=x%10; r[1]=(x%100)/10; r[2]=(x%1000)/100; r[3]=(x%10000)/1000; r[4]=(x%100000)/10000; r[5]=(x%1000000)/100000; r[6]=(x%10000000)/1000000; r[7]=x/10000000; } }if(k==12)//³Ë·¨ÔËËã { i=x; x=x*y; if(y==0) { x=0; } else if(x>99999999||x<i) //»ý´óÓÚ99999999»òÕßСÓÚ³ËÊý¶¼ÈÏΪÊÇÒì³£,´æÔÚÆäËû¿ÉÄܵÄÒç³ö£¬Ðë×ÔÐбæ±ð { r[0]=11; //r r[1]=11; //r r[2]=10; //E r[3]=12; //¿Õ¸ñ r[4]=12; r[5]=12; r[6]=12; r[7]=12; } else { r[0]=x%10; r[1]=(x%100)/10; r[2]=(x%1000)/100; r[3]=(x%10000)/1000; r[4]=(x%100000)/10000; r[5]=(x%1000000)/100000; r[6]=(x%10000000)/1000000; r[7]=x/10000000; } }if(k==13)//³ý·¨ÔËËã { if(y==0) //±»³ýÊý²»ÄÜΪ0 { r[0]=11; //r r[1]=11; //r r[2]=10; //E r[3]=12; //¿Õ¸ñ r[4]=12; r[5]=12; r[6]=12; r[7]=12; } else { x=x/y; r[0]=x%10; r[1]=(x%100)/10; r[2]=(x%1000)/100; r[3]=(x%10000)/1000; r[4]=(x%100000)/10000; r[5]=(x%1000000)/100000; r[6]=(x%10000000)/1000000; r[7]=x/10000000; } }for(i=7;i>0;i--) //Êýֵת»¯,½«¸ßλµÄÎÞЧÊý×Ö0ת»¯Îª¿Õ¸ñ·û12 { if(r[i]==0) r[i]=12; else break; }for(i=0;i<8;i++) //½«¼ÆËã½á¹û´æÈëdsp[9]£¬ÏÔʾÊý¸üР{ dsp[i+1]=r[i]; }}3.计算结果展示
输入2+3
版权声明:
本站文章均来自互联网搜集,如有侵犯您的权益,请联系我们删除,谢谢。
标签: #计算器怎么求mod