<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ī)學(xué)習(xí)——獨(dú)立按鍵之三

          單片機(jī)學(xué)習(xí)——獨(dú)立按鍵之三

          作者: 時(shí)間:2016-11-23 來(lái)源:網(wǎng)絡(luò) 收藏
          題目:按下16個(gè)矩陣鍵盤依次在數(shù)碼管上顯示1-16的平方。如按下第一個(gè)顯示1,第二個(gè)顯示4...
          解決方案:(C語(yǔ)言編程)
          #include
          #include
          #define uint unsigned int
          #define uchar unsigned char
          uchar bai,shi,ge,num,temp;
          uint shu;
          sbit le=P3^6;
          void delay(uint a);
          void dis();
          void display(uchar ba,uchar sh,uchar g);
          uchar code tabledu[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,
          0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0x89,0x86,0xc7,0xc7,0xc0,0xff};
          uchar code tablewe[]={0xff,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
          void main()
          {
          while(1){
          P1=0xfe;
          temp=P1;
          temp=temp&0xf0;
          while(temp!=0xf0)
          {
          delay(5);
          temp=P1;
          temp=temp&0xf0;
          while(temp!=0xf0)
          {
          temp=P1;
          switch(temp)
          {
          case 0x7e:shu=16 ;break;
          case 0xbe:shu=15 ;break;
          case 0xde:shu=14 ;break;
          case 0xee:shu=13 ;break;
          }
          while(temp!=0xf0)
          {
          temp=P1;
          temp=temp&0xf0;
          }
          shu=shu*shu;
          }
          }
          bai=shu/100;
          shi=shu%100/10;
          ge=shu%10;
          display(bai,shi,ge);
          P1=0xfd;
          temp=P1;
          temp=temp&0xf0;
          while(temp!=0xf0)
          {
          delay(5);
          temp=P1;
          temp=temp&0xf0;
          while(temp!=0xf0)
          {
          temp=P1;
          switch(temp)
          {
          case 0x7d:shu=12 ;break;
          case 0xbd:shu=11 ;break;
          case 0xdd:shu=10 ;break;
          case 0xed:shu=9 ;break;
          }
          while(temp!=0xf0)
          {
          temp=P1;
          temp=temp&0xf0;
          }
          shu=shu*shu;
          }
          }
          bai=shu/100;
          shi=shu%100/10;
          ge=shu%10;
          display(bai,shi,ge);
          P1=0xfb;
          temp=P1;
          temp=temp&0xf0;
          while(temp!=0xf0)
          {
          delay(5);
          temp=P1;
          temp=temp&0xf0;
          while(temp!=0xf0)
          {
          temp=P1;
          switch(temp)
          {
          case 0x7b:shu=8 ;break;
          case 0xbb:shu=7 ;break;
          case 0xdb:shu=6 ;break;
          case 0xeb:shu=5 ;break;
          }
          while(temp!=0xf0)
          {
          temp=P1;
          temp=temp&0xf0;
          }
          shu=shu*shu;
          }
          }
          bai=shu/100;
          shi=shu%100/10;
          ge=shu%10;
          display(bai,shi,ge);
          P1=0xf7;
          temp=P1;
          temp=temp&0xf0;
          while(temp!=0xf0)
          {
          delay(5);
          temp=P1;
          temp=temp&0xf0;
          while(temp!=0xf0)
          {
          temp=P1;
          switch(temp)
          {
          case 0x77:shu=4 ;break;
          case 0xb7:shu=3 ;break;
          case 0xd7:shu=2 ;break;
          case 0xe7:shu=1 ;break;
          }
          while(temp!=0xf0)
          {
          temp=P1;
          temp=temp&0xf0;
          }
          shu=shu*shu;
          }
          }
          bai=shu/100;
          shi=shu%100/10;
          ge=shu%10;
          display(bai,shi,ge);
          }
          }
          void display(uchar ba,uchar sh,uchar g)
          {
          le=1;
          P2=tablewe[1];
          le=0;
          le=1;
          P0=tabledu[ba];
          le=0;
          delay(5);
          le=1;
          P2=tablewe[2];
          le=0;
          le=1;
          P0=tabledu[sh];
          le=0;
          delay(5);
          le=1;
          P2=tablewe[3];
          le=0;
          le=1;
          P0=tabledu[g];
          le=0;
          delay(5);
          }
          void delay(uint a) {
          uint i,j;
          for(j=a;j>0;j--)
          for(i=250;i>0;i--);
          }


          關(guān)鍵詞: 單片機(jī)獨(dú)立按

          評(píng)論


          技術(shù)專區(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); })();