<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 單片機(jī)做的8位計(jì)算器

          單片機(jī)做的8位計(jì)算器

          作者: 時(shí)間:2016-12-01 來(lái)源:網(wǎng)絡(luò) 收藏

          CODE:

          本文引用地址:http://www.ex-cimer.com/article/201612/324178.htm

          #include
          #define uint unsigned int
          #define uchar unsigned char
          sbit dula=P2^6;
          sbit wela=P2^7;
          uchar LA[8];
          uchar code wetable[]={
          0x7f,0xbf,0xdf,0xef,
          0xf7,0xfb,0xfd,0xfe};
          uchar code dutable[]={
          0x3f,0x06,0x5b,0x4f,
          0x66,0x6d,0x7d,0x07,
          0x7f,0x6f};//段選0~9
          longint num1,num2,num;
          uchar temp;//按鍵需要的中間變量
          uchar flag;//標(biāo)記是否為數(shù)字鍵
          uchar ch;//保存當(dāng)前按下的符號(hào)標(biāo)記按鍵的次數(shù),按下“+-*/”
          uchar date,count;//date保存按鍵得到的數(shù)字,count標(biāo)記是第幾個(gè)數(shù)字
          uchar p;//p為指針,為了消除數(shù)字之前多余的0
          uchar mark;
          void delay(uint z)
          {
          uint x,y;
          for(x=z;x>0;x--)
          {
          for(y=0;y<=112;y++)
          {
          }
          }
          }
          void init()
          {
          count=0;
          flag=0;
          mark=0;
          num1=0;
          num2=0;
          num=0;
          }
          uchar keyscan()//判斷按下那個(gè)鍵
          {
          P1=0xfe;
          temp=P1;
          temp=temp&0xf0;
          if(temp!=0xf0)
          {
          delay(5);//消除抖動(dòng)
          temp=P1;
          temp=temp&0xf0;
          while(temp!=0xf0)//證明有鍵按下,while語(yǔ)句是為了讓鍵盤(pán)松開(kāi)
          {
          temp=P1;
          switch(temp)
          {
          case 0xee:flag=1;date=7;
          break;
          case 0xde:flag=1;date=8;
          break;
          case 0xbe:flag=1;date=9;
          break;
          case 0x7e:flag=2;ch=/;
          break;
          }
          if(temp!=0xf0)
          {
          delay(5);
          temp=P1;
          temp=temp&0xf0;
          while(temp!=0xf0)//等待按鍵松開(kāi)
          {
          temp=P1;
          temp=temp&0xf0;
          }
          }
          }
          }
          P1=0xfd;
          temp=P1;
          temp=temp&0xf0;
          if(temp!=0xf0)
          {
          delay(5);//消除抖動(dòng)
          temp=P1;
          temp=temp&0xf0;
          while(temp!=0xf0)//證明有鍵按下,while語(yǔ)句是為了讓鍵盤(pán)松開(kāi)
          {
          temp=P1;
          switch(temp)
          {
          case 0xed:flag=1;date=4;
          break;
          case 0xdd:flag=1;date=5;
          break;
          case 0xbd:flag=1;date=6;
          break;
          case 0x7d:flag=2;ch=*;
          break;
          }
          if(temp!=0xf0)
          {
          delay(5);
          temp=P1;
          temp=temp&0xf0;
          while(temp!=0xf0)//等待按鍵松開(kāi)
          {
          temp=P1;
          temp=temp&0xf0;
          }
          }
          }
          }
          P1=0xfb;
          temp=P1;
          temp=temp&0xf0;
          if(temp!=0xf0)
          {
          delay(5);//消除抖動(dòng)
          temp=P1;
          temp=temp&0xf0;
          while(temp!=0xf0)//證明有鍵按下,while語(yǔ)句是為了讓鍵盤(pán)松開(kāi)
          {
          temp=P1;
          switch(temp)
          {
          case 0xeb:flag=1;date=1;
          break;
          case 0xdb:flag=1;date=2;
          break;
          case 0xbb:flag=1;date=3;
          break;
          case 0x7b:flag=2;ch=-;
          break;
          }
          if(temp!=0xf0)
          {
          delay(5);
          temp=P1;
          temp=temp&0xf0;
          while(temp!=0xf0)//等待按鍵松開(kāi)
          {
          temp=P1;
          temp=temp&0xf0;
          }
          }
          }
          }

          P1=0xf7;
          temp=P1;
          temp=temp&0xf0;
          if(temp!=0xf0)
          {
          delay(5);//消除抖動(dòng)
          temp=P1;
          temp=temp&0xf0;
          while(temp!=0xf0)//證明有鍵按下,while語(yǔ)句是為了讓鍵盤(pán)松開(kāi)
          {
          temp=P1;
          switch(temp)
          {
          case 0xe7:flag=4;ch=C;
          break;
          case 0xd7:flag=1;date=0;
          break;
          case 0xb7:flag=3;//ch==;
          break;
          case 0x77:flag=2;ch=+;
          break;
          }
          if(temp!=0xf0)
          {
          delay(5);
          temp=P1;
          temp=temp&0xf0;
          while(temp!=0xf0)//等待按鍵松開(kāi)
          {
          temp=P1;
          temp=temp&0xf0;
          }
          }
          }
          }



          關(guān)鍵詞: 單片機(jī)8位計(jì)算

          評(píng)論


          技術(shù)專(zhuān)區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();