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

          新聞中心

          EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > ATmega16L-定時(shí)器數(shù)碼管掃描

          ATmega16L-定時(shí)器數(shù)碼管掃描

          作者: 時(shí)間:2012-08-22 來(lái)源:網(wǎng)絡(luò) 收藏
          /****************************************用維持?jǐn)?shù)碼管顯示現(xiàn)在是數(shù)碼管示數(shù)不斷增加。****************************************/#include iom16v.h>unsigned int cnt;unsigned char shu[8];unsigned char aa;const unsigned char duanma[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};const unsigned char weima[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};/***************************************數(shù)據(jù)轉(zhuǎn)換子函數(shù)***************************************/void change(unsigned int i){shu[0]=duanma[i/1000];shu[1]=duanma[i/100%10];shu[2]=duanma[i%100/10];shu[3]=duanma[i%10];}/****************************************延時(shí)函數(shù)****************************************/void delay(unsigned int t){unsigned int x,y;for(x=t;x>0;x--)for(y=100;y>0;y--);}/****************************************顯示函數(shù)****************************************/void display(unsigned char i){PORTB =0X00;PORTA|=0X01;PORTA=0XFE;PORTB =weima[i];PORTA|=0x02;PORTA=0XFD;PORTB=shu[i];PORTA|=0X01;PORTA=0XFE;}/***************************************端口初始化***************************************/void init_port(void){PORTA=0XFF;DDRA=0XFF;PORTB=0XFF;DDRB=0XFF;}/***************************************0初始化***************************************/void timer0_init(void){TCNT0=0X83; //1MS的定時(shí)初值TCCR0=0X03; //的計(jì)數(shù)預(yù)分頻取64}/***************************************定時(shí)器0服務(wù)函數(shù)***************************************/#pragma interrupt_handler timer0_ovf_isr:10void timer0_ovf_isr(void){TCNT0=0X83; //重裝1ms的定時(shí)初值if(++aa>3) aa=0;switch(aa){case 0: display(0);break;case 1: display(1);break;case 2: display(2);break;case 3: display(3);break;default:break;}}void main(void){init_port();   //IO端口初始化timer0_init(); //定時(shí)器1初始化 TIMSK=0X01;    //使能T0中斷 SREG=0X80;     //使能總中斷while(1){cnt++;delay(1000);change(cnt);}}


          評(píng)論


          相關(guān)推薦

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