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

          新聞中心

          EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 用AVR純軟件模擬電子時(shí)鐘

          用AVR純軟件模擬電子時(shí)鐘

          作者: 時(shí)間:2016-11-20 來(lái)源:網(wǎng)絡(luò) 收藏
          * 目 的:電子時(shí)鐘的純軟件模擬*

          * 功 能:實(shí)現(xiàn)時(shí)鐘的功能
          * 時(shí)鐘頻率:內(nèi)部4M *
          * 編譯環(huán)境:ICC-AVR7 *

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

          *圖見(jiàn)上一篇日志*

          #include
          #include

          #define uint unsigned int
          #define uchar unsigned char
          #define on_138 PORTC|=BIT(PC7) //on or off 138
          #define off_138 PORTC&=~BIT(PC7)
          #pragma data:code

          uchar flash table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; //the data for display
          uchar flash site[]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07};
          uchar time[3];
          uchar temp[6];

          void delay(uint ms) //延時(shí)1ms
          {
          uint i,j;
          for(i=0;i for(j=0;j<564;j++);
          }

          void display(uchar i, uchar j) //數(shù)碼管顯示時(shí)間
          {
          if(i==1||i==3)
          {
          PORTA=site[i];
          PORTB=table[j];
          PORTB|=0X80;
          }
          else
          {
          PORTA=site[i];
          PORTB=table[j];
          }
          delay(1);
          }

          void time_to_temp() //顯示的時(shí)間數(shù)據(jù)送到temp數(shù)組保存
          {
          uchar i,j=0;
          for(i=0;i<3;i++)
          {
          temp[j++]=time[i];
          temp[j++]=time[i]/10;
          }
          }


          void inti() //初始化io口
          {
          DDRA=0X07;
          DDRB=0XFF;
          DDRC=0X80;
          }

          void main()
          {
          uchar i,time_count=0;
          time[0]=0;
          time[1]=26;
          time[2]=19;
          time_to_temp();
          inti();
          while(1)
          {
          for(i=0;i<6;i++)
          {
          on_138;
          display(i,temp[5-i]);
          off_138;
          }

          if(++time_count>=166)
          {
          time_count=0;
          if(++time[0]>=60)
          {
          time[0]=0;
          if(++time[1]>=60)
          {
          time[1]=0;
          if(++time[2]>=24)
          {
          time[2]=0;
          }
          }
          }
          time_to_temp();
          }
          }
          }


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