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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > 按鍵控制字符串在數(shù)碼管上移動顯示

          按鍵控制字符串在數(shù)碼管上移動顯示

          作者: 時間:2016-11-18 來源:網(wǎng)絡 收藏
          //---------------------------------

          //按鍵控制字符串數(shù)碼管移動顯示
          //1、P30控制移動方向
          //2、P31加速度
          //3、P32減速度
          //4、每移動完整一次蜂鳴器響一下;
          //
          //

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

          #include
          #define uint unsigned int
          #define uchar unsigned char
          uchar code dula[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
          0x07,0x7f,0x6f,0x00,0x40};
          uchar wula[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0,0,0};
          uchar table[6]={1,2,0,0,4,8};//要顯示的字符串
          uchar temp[6]={10,10,10,10,10,10};//顯示緩沖區(qū)
          sbit arrow=P3^0;//30控制移動方向
          sbit jia=P3^1;//P31加速度
          sbit jian=P3^2;//P32減速度
          sbit beep=P1^5;//每移動完整一次蜂鳴器響一下;
          uchar num1,num2,miao,flag5ms,flag100ms,flag1s,i,N,flagbeep;
          bit flagarrow;
          void delay(uint z);
          void display();
          void tinic();
          void main()
          { N=5;
          tinic();
          while(1)
          {
          if(arrow==0)
          delay(100);
          if(arrow==0)
          {while(arrow==0);
          flagarrow=~flagarrow; miao=0;
          for(i=0;i<6;i++)//按一次變動方向,要對顯示緩沖區(qū)清空
          temp[i]=10;//不顯示
          }
          if(jia==0)
          delay(100);
          if(jia==0)
          {while(jia==0);if(N<2) N=1;else N--;}
          if(jian==0)
          delay(100);
          if(jian==0)
          {while(jian==0);N++;if(N>10) N=10;}
          display();
          if(flagbeep=1)
          {flagbeep=0;
          if(miao<1)
          beep=0;
          else beep=1;}

          }

          }

          //-------------------
          void timer0() interrupt 1
          {
          TH0=(65536-5000)/256;
          TL0=(65536-5000)%256;
          num1++;
          flag5ms=1;
          if(num1==20)
          {
          num1=0;
          num2++;
          flag100ms=1;
          if(num2==N)
          {num2=0;
          miao++;

          if(miao>5)
          {miao=0;flagbeep=1;
          for(i=0;i<6;i++)//移動完一次要對顯示緩沖區(qū)清空
          temp[i]=10;}//不顯示
          flag1s=1;}
          }
          }

          //----------------------
          void tinic()
          {
          TMOD=0x01;
          ET0=1;
          EA=1;
          TH0=(65536-5000)/256;
          TL0=(65536-5000)%256;
          TR0=1;
          }

          void delay(uint z)
          {
          uint x,y;
          for(x=0;xfor(y=0;y<112;y++);

          }
          //=
          void display()
          {
          uchar j;
          if(flagarrow==1)
          switch(miao)
          {
          case 0:temp[0]=table[5];break;
          case 1:temp[0]=table[4];
          temp[1]=table[5];break;
          case 2:temp[0]=table[3];
          temp[1]=table[4];
          temp[2]=table[5];break;
          case 3:temp[0]=table[2];
          temp[1]=table[3];
          temp[2]=table[4];
          temp[3]=table[5];break;
          case 4:temp[0]=table[1];
          temp[1]=table[2];
          temp[2]=table[3];
          temp[3]=table[4];
          temp[4]=table[5];break;
          case 5:temp[0]=table[0];
          temp[1]=table[1];
          temp[2]=table[2];
          temp[3]=table[3];
          temp[4]=table[4];
          temp[5]=table[5];break;
          }

          if(flagarrow==0)

          switch(miao)
          {
          case 0:temp[5]=table[0];break;
          case 1:temp[4]=table[0];
          temp[5]=table[1];break;
          case 2:temp[3]=table[0];
          temp[4]=table[1];
          temp[5]=table[2];break;
          case 3:temp[2]=table[0];
          temp[3]=table[1];
          temp[4]=table[2];
          temp[5]=table[3];break;
          case 4:temp[1]=table[0];
          temp[2]=table[1];
          temp[3]=table[2];
          temp[4]=table[3];
          temp[5]=table[4];break;
          case 5:temp[0]=table[0];
          temp[1]=table[1];
          temp[2]=table[2];
          temp[3]=table[3];
          temp[4]=table[4];
          temp[5]=table[5];break;
          }
          for(j=0;j<6;j++)
          {P0=dula[temp[j]];
          P2=wula[j];
          delay(5);
          }
          }



          評論


          技術專區(qū)

          關閉
          看屁屁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); })();