简单计算机程序 20页

  • 55.27 KB
  • 2022-08-30 发布

简单计算机程序

  • 20页
  • 当前文档由用户上传发布,收益归属用户
  1. 1、本文档由用户上传,淘文库整理发布,可阅读全部内容。
  2. 2、本文档内容版权归属内容提供方,所产生的收益全部归内容提供方所有。如果您对本文有版权争议,请立即联系网站客服。
  3. 3、本文档由用户上传,本站不保证质量和数量令人满意,可能有诸多瑕疵,付费之前,请仔细阅读内容确认后进行付费下载。
  4. 网站客服QQ:403074932
#include#include#include//#definej2h(x)(3.1415926*(x)/180)sbitP32=P3A2;sbitP23=P2A3;sbitP22=P2A2;sbitP21=P2A1;sbitP20=P2A0;//unsignedchartimerO_count1=0;codeunsignedcharTab[10]={0x81,0xed,0x43,0x49,0x2d,0x19,0x11,0xcd,0x01,0x09};codeunsignedcharTab1[16]={0x81,0xed,0x43,0x49,0x2d,0x19,0x11,0xcd,0x01,0x09,0x05,0x00,0x93,0x80,0x13,Ox仃};unsignedintKeynumber;unsignedintnumber;unsignedchart=1;unsignedcharp=99;unsignedcharq=0;voidmDelay(unsignedintdelay)\nunsignedchari;for(;delay>0;delay-){for(i=0;i<124;i++){_nop_();_nop_();_nop_();}}}广键盘扫描程序*/voidKeyscan(){unsignedintkey1;Keynumber=20;if((P2&0x0f)!=0x0f)〃有键按下\nmDelay(5);if(!P23){P1&=0x7f;P1|=0x70;if(!P23)Keynumber=0;else{P1&=0xbf;P1|=0xb0;if(!P23)Keynumber=1;else{P1&=0xdf;P1|=0xd0;if(!P23)Keynumber=2;else{P1&=0xef;P1|=0xe0;if(!P23)Keynumber=3;elseKeynumber=20;\n}}}elseif(!P22){P1&=0x7f;P1|=0x70;if(!P22)Keynumber=4;else{P1&=0xbf;P1|=0xb0;if(!P22)Keynumber=5;else{P1&=0xdf;P1|=0xd0;if(!P22)Keynumber=6;else{elseKeynumber=20;\n}}}}elseif(!P21){P1&=0x7f;P1|=0x70;if(!P21)Keynumber=&else{P1&=0xbf;P1|=0xb0;if(!P21)Keynumber=9;else{P1&=0xdf;P1|=0xd0;if(!P21)Keynumber=10;elseP1&=0xef;P1|=0xe0;if(!P21)Keynumber=11;elseKeynumber=20;\n}}}}elseif(!P20){P1&=0x7f;P1|=0x70;if(!P20)Keynumber=12;else{P1&=0xbf;P1|=0xb0;if(!P20)Keynumber=13;else{\nelseP1&=0xef;P1|=OxeO;if(!P20){Keynumber=15;}elseKeynumber=20;}}}}elseKeynumber=20;}elseKeynumber=20;//无键按下}广主程序*/voidmain()\nunsignedinta=0;unsignedintb=0;unsignedintnum;unsignedintkey=O;//Keynumber寄存unsignedintkey1;//数据寄存unsignedintplay;//算法判断while(1)Keyscan();if(Keynumber<10)//数字输入key=Keynumber;if(Keynumber==20)if(key<10)a=key;b=10*b+a;key=20;\nif(Keynumber>11&Keynumbervi6)//算法判断{key=Keynumber;}if(Keynumber==20){if(key>11&key<16)key1=number;b=0;play=key;key=20;}}if(Keynumber==11)//加法运算(可以连加)if(Keynumber==20)\nif(key==11){if(play==12){number=key1+number;key=20;}}if(Keynumber==11)//减法运算(可以连减){key=Keynumber;}if(Keynumber==20){if(key==11){if(play==13)\n(二”父雯)七(0审」①qcunuA①匸①qlunuAeyHA①上(鬃熾公冋)M凹瑕鬃V(LLX」①qEnu亦y=_O2HA①上\nO址雯L7①qlunF>.①盂」①qEnu)(寸LH=Ae_d)H=\n}if(Keynumber==20){if(key==11){if(play==15){number=key1/number;key=20;}}}if(Keynumber==10)//切换进制{key=Keynumber;}if(Keynumber==20){if(key==10)\nP++;if(p>100)p=99;P32!=P32;}elset++;if(t>2)t=1;key=20;}}}if(p==99)if(number<100000000&number>9999)if(t==1)\nmDelay(5);P0=Tab[(number/10000)%1000/100];P2=P2|0x40;P2=P2&0x4f;mDelay(5);P0=Tab[(number/10000)%100/10];P2=P2|0x20;P2=P2&0x2f;mDelay(5);P0=Tab[(number/10000)%10];P2=P2|0x10;P2=P2&0x1f;mDelay(5);}if(t==2){P0=Tab[(number%10000)/1000];P2=P2|0x80;P2=P2&0x8f;mDelay(5);P0=Tab[(number%10000)%1000/100];P2=P2|0x40;P2=P2&0x4f;mDelay(5);P0=Tab[(number%10000)%100/10];P2=P2|0x20;P2=P2&0x2f;mDelay(5);P2=P2|0x10;P2=P2&0x1f;\nmDelay(5);}}if(number<10000&number>999){P0=Tab[number/1000];P2=P2|0x80;P2=P2&0x8f;mDelay(5);P0=Tab[number%1000/100];P2=P2|0x40;P2=P2&0x4f;mDelay(5);P0=Tab[number%100/10];P2=P2|0x20;P2=P2&0x2f;mDelay(5);P0=Tab[number%10];P2=P2|0x10;P2=P2&0x1f;mDelay(5);}\nP2=P2|0x40;P2=P2&0x4f;mDelay(5);P0=Tab[number%100/10];P2=P2|0x20;P2=P2&0x2f;mDelay(5);P0=Tab[number%10];P2=P2|0x10;P2=P2&0x1f;mDelay(5);}if(number<100&number>9){P0=Tab[number/10];P2=P2|0x20;P2=P2&0x2f;mDelay(5);P0=Tab[number%10];P2=P2|0x10;P2=P2&0x1f;mDelay(5);}PO=Tab[number%10];\nP2=P2|0x10;P2=P2&0x1f;mDelay(5);}}if(p>99){if(number<65536&number>4095){P0=Tab1[number/4096];P2=P2|0x80;P2=P2&0x8f;mDelay(5);P0=Tab1[number%4096/256];P2=P2|0x40;P2=P2&0x4f;mDelay(5);P0=Tab1[number%256/16];P2=P2|0x20;P2=P2&0x2f;mDelay(5);P0=Tab1[number%16];P2=P2|0x10;P2=P2&0x1f;mDelay(5);if(number<4096&number>255)\nP0=Tab1[number/256];P2=P2|0x40;P2=P2&0x4f;mDelay(5);P0=Tab1[number%256/16];P2=P2|0x20;P2=P2&0x2f;mDelay(5);P0=Tab1[number%16];P2=P2|0x10;P2=P2&0x1f;mDelay(5);}if(number<256&number>15){P0=Tab1[number/16];P2=P2|0x20;P2=P2&0x2f;mDelay(5);P0=Tab1[number%16];P2=P2|0x10;P2=P2&0x1f;mDelay(5);}if(number<16|number==0)\nP2=P2|0x10;P2=P2&0x1f;mDelay(5);}}

相关文档