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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 1602LCD液晶如何編寫數(shù)字電子鐘

          1602LCD液晶如何編寫數(shù)字電子鐘

          作者: 時間:2016-11-18 來源:網(wǎng)絡(luò) 收藏
          以前,學(xué)習(xí)單片機(jī),都沒有開發(fā)板,因此感覺編寫數(shù)字電子鐘的程序,是非常難的,簡直就是不知道如何著手。 現(xiàn)在已經(jīng)對單片機(jī)各種操作都逐漸熟悉了,因此剛剛就已經(jīng)實(shí)現(xiàn)了自己關(guān)于數(shù)字電子鐘的一點(diǎn)小小的設(shè)計思想
          由于時間關(guān)系,現(xiàn)在已經(jīng)比較晚了,所以就暫時不編寫按鍵功能,但是已經(jīng)實(shí)現(xiàn)了動態(tài)計時功能了,明天再繼續(xù)添加按鍵功能。
          #include
          #include"MyFuntion.h" //自定義頭文件
          unsigned char year1=20; // 年1
          unsigned char year2=12; // 年2
          unsigned char month=1; // 月
          unsigned char day=22; // 日
          unsigned char hour=23; // 時
          unsigned char minute=12; // 分
          unsigned char second=56; // 秒
          unsigned char table1[10];
          unsigned char table2[8];
          unsigned char t; //定時器T0 發(fā)生中斷次數(shù)
          //unsigned char t1; //定時器T1 發(fā)生中斷次數(shù)
          /*
          //獨(dú)立按鍵P1口
          sbit Key1=P3^0; //Key1 取消調(diào)時 恢復(fù)單片機(jī)調(diào)時之前的實(shí)際時間
          sbit Key2=P3^1; //Key2 進(jìn)入調(diào)整時間狀態(tài): 停止定時器T0,啟動定時器T1.
          sbit Key3=P3^2; //Key3 退出調(diào)整時間狀態(tài): 啟動定時器T0,停止定時器T1.
          sbit Key4=P3^3; //Key4 選擇調(diào)整時間: 秒, 分, 時, 日, 月, 年
          sbit Key5=P3^4; //Key5 調(diào)時: 遞增 同時啟動蜂鳴器
          sbit Key6=P3^5; //Key6 Key6 調(diào)時: 遞減 同時啟動蜂鳴器
          */
          void Init_Table_YMD() //年月日
          //進(jìn)行對 時間的轉(zhuǎn)換 以致于可以把時間發(fā)送到1602LCD顯示
          {
          //把 year, month, day 轉(zhuǎn)換為一個字符存儲在數(shù)組table1
          table1[0]=year1/10;
          table1[1]=year1%10;
          table1[2]=year2/10;
          table1[3]=year2%10;
          table1[4]=-;
          table1[5]=month/10;
          table1[6]=month%10;
          table1[7]=-;
          table1[8]=day/10;
          table1[9]=day%10;
          }
          void Init_Table_HMS() // 時分秒
          {
          //把 hour, minute, second 轉(zhuǎn)換為一個字符存儲在數(shù)組table2
          table2[0]=hour/10;
          table2[1]=hour%10;
          table2[2]=:;
          table2[3]=minute/10;
          table2[4]=minute%10;
          table2[5]=:;
          table2[6]=second/10;
          table2[7]=second%10;
          }
          void IncreaseTime() // 秒鐘 遞增
          {
          second++;
          if(second==60)
          {
          second=0;
          minute++;
          if(minute==60)
          {
          minute=0;
          hour++;
          if(hour==24)
          {
          hour=0;
          }
          }
          }
          Init_Table_HMS(); //時分秒
          DisplayLCD_HMS(table2, 8); //LCD顯示時間 時分秒
          }
          void main()
          {
          TMOD=0X01;
          EA=1;
          ET0=1;
          // ET1=1;
          TR0=1; //啟動定時器T0
          // TR1=0; //停止定時器T1 即還沒有啟動定時器T1
          TH0=(65536-50000)/256;
          TL0=(65536-50000)%256;
          InitLCD(); //初始化LCD
          Init_Table_YMD(); // LCD 時間表 年月日
          Init_Table_HMS(); // LCD 時間表 時分秒
          DisplayLCD_YMD(table1, 10); //LCD顯示時間 年月日
          DisplayLCD_HMS(table2, 8); //LCD顯示時間 時分秒
          while(1)
          {
          if(t==20)
          {
          t=0;
          IncreaseTime();
          }
          }
          // while(1);
          }
          void LCD_Timer0() interrupt 1 using 0
          {
          TH0=(65536-50000)/256;
          TL0=(65536-50000)%256;
          t++;
          }



          關(guān)鍵詞: 1602LCD液晶數(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); })();