<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í)器應(yīng)用于數(shù)碼管

          ATmega16L-定時(shí)器應(yīng)用于數(shù)碼管

          作者: 時(shí)間:2012-08-18 來(lái)源:網(wǎng)絡(luò) 收藏
          /****************************************掃描,數(shù)據(jù)口接PA段碼接PC7 位碼接PC6穩(wěn)定顯示01234567****************************************/#include iom16v.h>#include macros.h>unsigned int i;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};/****************************************display****************************************/void display(unsigned int i){PORTA=0X00;PORTC|=BIT(7);PORTC=~BIT(7);PORTA=weima[i];PORTC|=BIT(6); PORTC=~BIT(6);PORTA=duanma[i];PORTC|=BIT(7);PORTC=~BIT(7);}/****************************************IO端口初始化****************************************/void init_port(void){PORTA=0XFF;DDRA=0XFF;PORTC=0XFF;DDRC=0XFF;}/****************************************初始化****************************************/void init_timer(void){TCNT0=0X83; //1ms的初值TCCR0=0X03; //0的計(jì)數(shù)預(yù)分頻取64 TIMSK=0X01; //使能T/C0中斷SREG =0X80; //使能總中斷}/***************************************主函數(shù)***************************************/void main(void){init_port();  //調(diào)用IO端口初始化函數(shù)init_timer(); //定時(shí)器初始化while(1){//添加自己需要的程序代碼}}#pragma interrupt_handler timer0_ovf_isr:10 void timer0_ovf_isr(void){TCNT0=0X83; //重裝1ms定時(shí)器初值if(++i>7) i=0;display(i); }TCNT0=0X83; //1ms的定時(shí)器初值TCCR0=0X03; //定時(shí)器0的計(jì)數(shù)預(yù)分頻取64 8位定時(shí)器/計(jì)數(shù)器。 0x83=131。131-255 之間一共數(shù)了125.另外,外部晶振8M,經(jīng)過(guò)64分頻,周期成為1/(8000000/64)=8us 125個(gè)8us 就是1ms OK 


          評(píng)論


          相關(guān)推薦

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