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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > AVR 數(shù)碼管顯示設(shè)計 按鍵加減數(shù)

          AVR 數(shù)碼管顯示設(shè)計 按鍵加減數(shù)

          作者: 時間:2016-11-11 來源:網(wǎng)絡(luò) 收藏
          //******************************FileName: Counter.C**************************//

          //******************************ICCAVR 編譯*****************************//

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

          #include
          #define uchar unsigned char
          #define uint unsigned int

          //數(shù)碼管字型表,對應(yīng)0,1,2,3,4,5,6,7,8,9//
          uchar Table[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
          uchar Data[4]={0,0,0,0}; //顯示初始值:0 0 0 0
          uint CNT=0; //初始計數(shù)值:0
          uchar Key_Up; //加計數(shù)按鍵標(biāo)志
          uchar Key_Down; //減計數(shù)按鍵標(biāo)志

          void DelayMs(uint i) //Ms級延時,參數(shù)i為延時時間
          {uint j;
          for(;i!=0;i--)
          {for(j=8000;j!=0;j--) {;}}
          }

          void Display(uchar *p) //動態(tài)顯示函數(shù),參數(shù)p為待顯示的數(shù)組名
          {uchar i,sel=0x01;
          for(i=0;i<4;i++)
          {PORTC=sel; //選通最右邊的數(shù)碼管
          PORTA=Table[p[i]]; //送字型碼
          DelayMs(2); //顯示延時
          sel=sel<<1; //移位以顯示前一位
          }
          }

          //******************************計數(shù)值處理函數(shù)******************************//
          //功能:此函數(shù)用于將計數(shù)值拆分為BCD碼的千,百,十,一數(shù)據(jù),用于查表顯示//
          //參數(shù)說明:參數(shù)i:計數(shù)值;參數(shù)p:處理數(shù)據(jù)存放的數(shù)組名//
          void Process(uint i,uchar *p)
          {p[0]=i/1000;
          i=i%1000;
          p[1]=i/100;
          i=i%100;
          p[2]=i/10;
          i=i%10;
          p[3]=i;
          }

          void Init_IO(void) //初始化I/O口
          {DDRA=0xff; //設(shè)置A口為推挽1輸出
          PORTA=0xff;
          DDRB=0x00; //設(shè)置B口為不帶上拉電阻輸入
          PORTB=0x00;
          DDRC=0xff; //設(shè)置C口為推挽1輸出;
          PORTC=0xff;
          }

          void Get_Key(void) //按鍵掃描函數(shù)
          {while((PINB&0x01)==0) //若S1按下,置位加計數(shù)標(biāo)志;
          {Key_Up=1;
          Display(Data);}
          while((PINB&0x02)==0) //若S2按下,置位減計數(shù)標(biāo)志;
          {Key_Down=1;
          Display(Data);}
          }

          void main(void)
          {uchar I;
          Init_IO(); //初始化I/O口
          PORTA=0xff; //點(diǎn)亮測試所有的數(shù)碼管
          PORTC=0x00;
          DelayMs(3000); //延時
          PORTC=0xff; //數(shù)碼管熄滅,進(jìn)入計數(shù)狀態(tài)
          while(1)
          {Get_Key(); //按鍵掃描
          if(Key_Up==1) //加計數(shù)處理
          {if(CNT!=9999) //條件判斷是否計數(shù)到9999
          {CNT=CNT+1; //計數(shù)值加1
          Key_Up=0;} //加計數(shù)標(biāo)志復(fù)位
          }
          if(Key_Down==1) //減計數(shù)處理
          {if(CNT!=0) //條件判斷是否計數(shù)到0000
          {CNT=CNT-1; //計數(shù)值減一
          Key_Down=0;} //減計數(shù)標(biāo)志復(fù)位
          }
          Process(CNT,Data); //計數(shù)值處理
          Display(Data); //動態(tài)掃描顯示
          }
          }



          關(guān)鍵詞: AVR數(shù)碼管按鍵加減

          評論


          技術(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); })();