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

          新聞中心

          EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 單片機(jī)驅(qū)動(dòng)DS1302時(shí)間DS18B20溫度12864液晶顯示完整程序設(shè)計(jì)

          單片機(jī)驅(qū)動(dòng)DS1302時(shí)間DS18B20溫度12864液晶顯示完整程序設(shè)計(jì)

          作者: 時(shí)間:2012-12-11 來源:網(wǎng)絡(luò) 收藏

          程序說明:這是一個(gè)用51驅(qū)動(dòng)時(shí)間模塊+溫度傳感器模塊+完整程序設(shè)計(jì)實(shí)例,有四個(gè)鍵盤KEY0 到KEY3,key0是修改時(shí)間的 首先是秒到分到時(shí)到年到月到日到星期 key1是加1 key2是減一 在修改時(shí)間狀態(tài)再按一下key3的時(shí)候就出去并修改時(shí)間日期,在平時(shí)狀態(tài)按著key3再按著key2 就會(huì)打開lcd 的燈 單單是只按key3那就是把燈關(guān)了。

          文件一:驅(qū)動(dòng).c

          #includereg52.h>

          //ds1302
          sbit sclk=P0^3;
          sbit io=P0^4;
          sbit rst=P0^5;
          sbit acc0=ACC^0;
          sbit acc1=ACC^1;
          sbit acc2=ACC^2;
          sbit acc3=ACC^3;
          sbit acc4=ACC^4;
          sbit acc5=ACC^5;
          sbit acc6=ACC^6;
          sbit acc7=ACC^7;

          delay()
          {
          unsigned char i;
          i=10;
          i=10;
          i=10;
          i=10;
          i=10;
          i=10;
          i=10;}
          w_1302(unsigned char dat,unsigned char shu){//寫一個(gè)八位的數(shù)去 //上升效 ;;;選寫地址再寫數(shù)據(jù)

          ACC=dat;//地址
          sclk=0;
          rst=1;//
          io=acc0;///
          sclk=0;
          delay();
          sclk=1;
          io=acc1;
          sclk=0;
          delay();
          sclk=1;
          io=acc2;
          sclk=0;
          delay();
          sclk=1;
          io=acc3;
          sclk=0;
          delay();
          sclk=1;
          io=acc4;
          sclk=0;
          delay();
          sclk=1;
          io=acc5;
          sclk=0;
          delay();
          sclk=1;
          io=acc6;
          sclk=0;
          delay();
          sclk=1;
          io=acc7;
          sclk=0;
          delay();
          sclk=1;///


          //sclk=0;
          ACC=shu; //數(shù)據(jù)
          io=acc0;///
          sclk=0;
          delay();
          sclk=1;
          io=acc1;
          sclk=0;
          delay();
          sclk=1;
          io=acc2;
          sclk=0;
          delay();
          sclk=1;
          io=acc3;
          sclk=0;
          delay();
          sclk=1;
          io=acc4;
          sclk=0;
          delay();
          sclk=1;
          io=acc5;
          sclk=0;
          delay();
          sclk=1;
          io=acc6;
          sclk=0;
          delay();
          sclk=1;
          io=acc7;
          sclk=0;
          delay();
          sclk=1;///

          rst=0;
          sclk=0;
          } ///寫完畢
          unsigned char r_1302(unsigned char ADD){

          sclk=0;
          rst=1;
          ACC=ADD; //地址
          io=acc0;///
          sclk=0;
          delay();
          sclk=1;
          io=acc1;
          sclk=0;
          delay();
          sclk=1;
          io=acc2;
          sclk=0;
          delay();
          sclk=1;
          io=acc3;
          sclk=0;
          delay();
          sclk=1;
          io=acc4;
          sclk=0;
          delay();
          sclk=1;
          io=acc5;
          sclk=0;
          delay();
          sclk=1;
          io=acc6;
          sclk=0;
          delay();
          sclk=1;
          io=acc7;
          sclk=0;/////
          delay();
          sclk=1;
          delay();
          sclk=0;
          acc0=io;
          delay();
          sclk=1;
          delay();
          sclk=0;
          acc1=io;
          delay();
          sclk=1;
          delay();
          sclk=0;
          acc2=io;
          delay();
          sclk=1;
          delay();
          sclk=0;
          acc3=io;
          delay();
          sclk=1;
          delay();
          sclk=0;
          acc4=io;
          delay();
          sclk=1;
          delay();
          sclk=0;
          acc5=io;
          delay();
          sclk=1;
          delay();
          sclk=0;
          acc6=io;
          delay();
          sclk=1;
          delay();
          sclk=0;
          acc7=io;
          delay();

          rst=0;
          sclk=0;
          return(ACC);
          }
          ds1302_c()
          {
          w_1302(0x80,0x80);
          w_1302(0x8e,0x00);

          w_1302(0x80,0x50); //;秒
          w_1302(0x82,0x06); // 分=0
          w_1302(0x84,0x01); //時(shí) =0
          w_1302(0x86,0x22); //
          w_1302(0x88,0x11);//
          w_1302(0x8a,0x04);//
          w_1302(0x8b,0x07);//

          w_1302(0x8e,0x80);
          w_1302(0x90,0xa6);
          w_1302(0x80,0x00);
          }
          main(){
          rst=0;
          ds1302_c();

          for(;;){
          P2=r_1302(0x81);
          }
          }

          ---------------------------------------------------------------------------------------------------------------
          文件2:完全版 有關(guān)燈鍵.c

          #includereg52.h>
          sbit di = P2^7; ////////定義引腳
          sbit rw = P2^6;
          sbit e = P2^5;
          sbit cs1 = P2^4;
          sbit cs2 = P2^1;
          sbit lcd_d = P2^0;
          sbit key0 = P2^3;
          sbit key1 = P2^2;
          sbit key2 = P1^0;
          sbit key3 = P1^1;
          sbit P07 = P0^7;
          sbit P06 = P0^6;
          sbit P05 = P0^5;
          sbit P04 = P0^4;
          sbit P03 = P0^3;
          //ds1302
          sbit sclk=P1^4;
          sbit io=P1^3;
          sbit rst=P1^2;
          sbit acc0=ACC^0;
          sbit acc1=ACC^1;
          sbit acc2=ACC^2;
          sbit acc3=ACC^3;
          sbit acc4=ACC^4;
          sbit acc5=ACC^5;
          sbit acc6=ACC^6;
          sbit acc7=ACC^7;
          typedef unsigned char byte;
          typedef unsigned int word;
          sbit KEY=P3^7;//根據(jù)實(shí)際情況定義端口ds1820
          unsigned char key_time=0; //全局變量


          //////////////////////////////////溫度
          //ds18b20數(shù)字溫度傳感器模塊程序

          void delay1(word useconds)
          {
          for(;useconds>0;useconds--);
          }

          //復(fù)位
          byte ow_reset(void)
          {
          byte presence;
          KEY = 0; //pull DQ line low
          delay1(29); // leave it low for 480us
          KEY = 1; // allow line to return high
          delay1(3); // wait for presence
          presence = KEY; // get presence signal
          delay1(25); // wait for end of timeslot
          return(presence); // presence signal returned
          } // 0=presence, 1 = no part

          51單片機(jī)相關(guān)文章:51單片機(jī)教程


          單片機(jī)相關(guān)文章:單片機(jī)教程


          單片機(jī)相關(guān)文章:單片機(jī)視頻教程


          單片機(jī)相關(guān)文章:單片機(jī)工作原理



          上一頁(yè) 1 2 3 下一頁(yè)

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