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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > 51單片機時鐘12C887+溫度18b20C程序

          51單片機時鐘12C887+溫度18b20C程序

          作者: 時間:2016-11-24 來源:網(wǎng)絡 收藏

          uint Readtemp()
          {
          uchar a=0;
          uchar b=0;
          uint t=0;
          float tt=0;
          Init_DS18B20();
          WriteOneChar(0xCC); //跳過讀序號列號的操作
          WriteOneChar(0x44); //啟動溫度轉換
          Init_DS18B20();
          WriteOneChar(0xCC); //跳過讀序號列號的操作
          WriteOneChar(0xBE); //讀取溫度寄存器
          a=ReadOneChar(); //讀低8位
          b=ReadOneChar(); //讀高8位
          t=b;
          t<<=8;
          t=t|a;
          tt=t*0.0625;
          t= tt*10+0.5; //放大10倍輸出并四舍五入
          return(t);
          }

          void display(uint temp)
          {
          uchar A1,A2,A3;
          A1=temp/100;
          A2=temp%100/10;
          A3=temp%10;
          write_com(0x80+0x40+10);
          write_date(0x30+A1);//十位
          write_date(0x30+A2);//個位
          write_date(0x2e);//小數(shù)點
          write_date(0x30+A3);//小數(shù)點后一位
          write_date(0xdf);//
          write_date(0x43);//C

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

          }



          void didi()
          {
          beep=0;
          delay(100);
          beep=1;
          }

          void write_nyrx(uchar add,uchar date)
          {
          uchar shi,ge;
          shi=date/10;
          ge=date%10;
          write_com(0x80+add);
          write_date(0x30+shi);
          write_date(0x30+ge);
          }


          void write_sfm(uchar add,uchar date)//
          {
          uchar shi,ge;
          shi=date/10;
          ge=date%10;
          write_com(0x80+0x40+add);
          write_date(0x30+shi);
          write_date(0x30+ge);
          }

          void keyscan()
          {

          //rd=0;
          if(flag1==1)//按s1 s4鍵消除報警
          {
          if((s1==0)||(s4==0))
          {
          delay(5);
          if((s1==0)||(s4==0))
          while(!(s1&&s4));
          didi();
          flag1=0;//消除報警標志
          }
          }

          if(s1==0)//調(diào)時功能鍵
          {
          delay(5);
          if(s1==0)
          {
          s1num++;
          flag=1;//flag功能鍵標志位 0為顯示,1為不顯示
          while(!s1);
          didi();
          if(s1num==1)
          {
          TR1=0;
          write_com(0x80+0x40+8);
          write_com(0x0f);
          }

          if(s1num==2)
          {
          write_com(0x80+0x40+5);
          }
          if(s1num==3)
          {
          write_com(0x80+0x40+2);
          }
          if(s1num==4)
          {
          write_com(0x80+9);
          }
          if(s1num==5)
          {
          write_com(0x80+6);
          }
          if(s1num==6)
          {
          write_com(0x80+3);
          }
          if(s1num==7)
          {
          write_com(0x80+0);
          }
          if(s1num==8)
          {
          s1num=0;
          write_com(0x0c);
          flag=0;
          write_ds(0,miao);
          write_ds(2,fen);
          write_ds(4,shi);
          write_ds(6,week);
          write_ds(7,ri);
          write_ds(8,yue);
          write_ds(9,nian);
          }
          }

          }
          if(s1num!=0)
          {
          if(s2==0)//功能鍵加1
          {
          delay(5);
          if(s2==0)
          {
          delay(5);
          while(!s2);
          didi();
          if(s1num==1)
          {
          miao++;
          if(miao==60)
          miao=0;
          write_sfm(7,miao);
          write_com(0x80+0x40+8);
          }
          if(s1num==2)
          {
          fen++;
          if(fen==60)
          fen=0;
          write_sfm(4,fen);
          write_com(0x80+0x40+5);
          }
          if(s1num==3)
          {
          shi++;
          if(shi==24)
          shi=0;
          write_sfm(1,shi);
          write_com(0x80+0x40+2);
          }
          if(s1num==4)
          {
          week++;
          if(week==8)
          week=0;
          write_com(0x80+9);
          write_date(table3[week]);
          write_date(table4[week]);
          write_date(table5[week]);
          }
          if(s1num==5)
          {
          ri++;
          if(ri==32)
          ri=1;
          write_nyrx(6,ri);
          write_com(0x80+6);
          }
          if(s1num==6)
          {
          yue++;
          if(yue==13)
          yue=1;
          write_nyrx(3,yue);
          write_com(0x80+3);
          }
          if(s1num==7)
          {
          nian++;
          if(nian==99)
          nian=0;
          write_nyrx(0,nian);
          write_com(0x80+0);
          }
          }
          }
          if(s3==0)//功能鍵減1
          {
          delay(5);
          if(s3==0)
          {
          delay(5);
          while(!s3);
          didi();
          if(s1num==1)
          {
          miao--;
          if(miao==-1)
          miao=59;
          write_sfm(7,miao);
          write_com(0x80+0x40+8);
          }
          if(s1num==2)
          {
          fen--;
          if(fen==-1)
          fen=59;
          write_sfm(4,fen);
          write_com(0x80+0x40+5);
          }
          if(s1num==3)
          {
          shi--;
          if(shi==-1)
          shi=23;
          write_sfm(1,shi);
          write_com(0x80+0x40+2);
          }
          if(s1num==4)
          {
          week--;
          if(week==0)
          week=7;
          write_com(0x80+9);
          write_date(table3[week]);
          write_date(table4[week]);
          write_date(table5[week]);
          }
          if(s1num==5)
          {
          ri--;
          if(ri==0)
          ri=31;
          write_nyrx(6,ri);
          write_com(0x80+6);
          }
          if(s1num==6)
          {
          yue--;
          if(yue==0)
          yue=12;
          write_nyrx(3,yue);
          write_com(0x80+3);
          }
          if(s1num==7)
          {
          nian--;
          if(nian==-1)
          nian=99;
          write_nyrx(0,nian);
          write_com(0x80+0);
          }
          }
          }
          }



          評論


          技術專區(qū)

          關閉
          看屁屁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); })();