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

          新聞中心

          EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 用51寫(xiě)的帶鍵控帶溫度的萬(wàn)年歷在LCD12864上顯示

          用51寫(xiě)的帶鍵控帶溫度的萬(wàn)年歷在LCD12864上顯示

          作者: 時(shí)間:2016-11-29 來(lái)源:網(wǎng)絡(luò) 收藏
          1,溫度只顯示整數(shù)部份,簡(jiǎn)單了許多;
          2,之前星期不可調(diào),問(wèn)題出在讀DS1302后數(shù)值沒(méi)轉(zhuǎn)換成十進(jìn)制數(shù);
          3,因?yàn)橹骱瘮?shù)始終要更新LCD的座標(biāo),所以光標(biāo)會(huì)隨之更新;這個(gè)對(duì)自已不做要求,有興趣的可以試一下;
          4,網(wǎng)站代碼下載:http://www.51hei.com/f/124wnl.rar

          #include

          #define uchar unsigned char
          #define uint unsigned int
          #define LCMdata P0
          #define Busy 0x80
          //--------Lcd_part ----------------
          sbit RS = P2^0;
          sbit RW = P2^1;
          sbit E = P2^2;
          sbit REST = P2^5;
          sbit PSB = P2^3;
          //---------Key_part----------------
          sbit Key_1 = P1^4;
          sbit Key_2 = P1^5;
          sbit Key_3 = P1^6;
          sbit Key_4 = P1^7;
          //----------Ds1302_part----------------
          sbit Sclk = P1^0;
          sbit IO = P1^1;
          sbit Rst = P1^2;
          sbit Buz = P3^7;
          sbit DQ = P3^6;
          uchar Key_Select,Key_Flag,Key_Count,Set1,Temp;
          uchar Time_Flag,TimeCount,Week_Count=0;
          uchar Sec=0;uchar Min=30;uchar Hour=7;
          uchar Date=8;uchar Mouth=4;uchar Year=12;uchar Week=5;
          uchar Display_number[14] = {"0123456789: -"};

          uchar Rd_addr[] = {0x8d,0x8b,0x89,0x87,0x85,0x83,0x81};
          uchar Wr_addr[] = {0x8c,0x8a,0x88,0x86,0x84,0x82,0x80};
          uchar Display[] = {"2012年04月06日//"};
          uchar Display_1[]={"19時(shí)36分00秒////"};
          uchar Display_T[]={"室溫25℃"};
          uchar Display_2[]={"星期"};
          uchar code string_2[] = {" ----時(shí)鐘---- "};
          uchar code string_3[] = {" ----日歷---- "};

          void Wr_Data(uchar wrdata);
          void Wr_Word(uchar *s);
          void Wr_Command(uchar wrcommand,busyc);
          void Display_String(uchar line,uchar Y,uchar *string);
          void Delay5Ms(void) //延時(shí) 5ms
          {
          unsigned int TempCyc=5552;
          while(TempCyc--);
          }
          //-------------------------------------------------------
          void Delay_Ms(uint Mtime)
          {
          uint i,j;
          for(i=Mtime;i>0;i--)
          for(j=122;j>0;j--)
          {;}
          }
          //--------------------------------------------------------
          void Delay_Us(uchar Utime)//*2us
          {
          while(--Utime);
          }
          void Delay(uint utime) //9Us
          {
          while(utime--);
          }
          /////////////////////////////////////////////////////////
          void Inint_ds18b20(void)
          {
          uchar DQZT=0;
          DQ=1;
          Delay(8);
          DQ=0;
          Delay(50);
          DQ=1;
          Delay(5);
          DQZT=DQ;
          Delay(10);
          }
          uchar Read_ds18b(void)
          {
          uchar i,dat=0;
          for(i=0;i<8;i++)
          {
          DQ=0;
          dat>>=1;
          DQ=1;
          if(DQ)
          dat=dat|0x80;
          Delay(5);
          }
          return dat;
          }
          void Write_ds18b20(uchar dat)
          {
          uchar i;
          for(i=0;i<8;i++)
          {
          DQ=0;
          DQ=dat&0x01;
          Delay(5);
          DQ=1;
          dat>>=1;
          }
          }
          void Read_Temp(void)
          {
          uchar a,b;
          Inint_ds18b20();
          Write_ds18b20(0xcc);
          Write_ds18b20(0x44);
          Delay_Ms(100);
          Inint_ds18b20();
          Write_ds18b20(0xcc);
          Write_ds18b20(0xbe);
          Delay_Ms(50);
          a=Read_ds18b();
          b=Read_ds18b();
          a&=0xf0;
          a>>=4;
          b<<=4;
          Temp=a|b;
          Display_T[4]=Display_number[Temp/10];
          Display_T[5]=Display_number[Temp%10];
          Delay_Us(100);
          }
          /////////////////////////////////////////////////////////
          void Wr_ds1302_byte(uchar data_13)
          {
          uchar i;
          for(i=0;i<8;i++)
          {
          Sclk = 0;
          IO = data_13 &0x01;
          data_13=data_13>>1;
          Sclk = 1;
          }
          }
          ///////////////////////////////////////////////////
          uchar Rd_ds1302_byte()
          {
          uchar i,value;
          for(i=0;i<8;i++)
          {
          value=value>>1;
          Sclk = 1;
          Sclk = 0;
          if(IO)
          value=value|0x80;
          }
          return value;
          }
          ///////////////////////////////////////////////////////
          void Wr_1302(uchar addr,uchar dat)
          {
          Rst = 0;
          Sclk = 0;
          Rst = 1;
          Wr_ds1302_byte(addr);
          Wr_ds1302_byte(dat);
          Rst = 0;
          Sclk = 1;
          IO = 1;
          }
          ////////////////////////////////////////////////////
          Rd_1302(uchar addr)
          {
          uchar value;
          Rst = 0;
          Sclk = 0;
          Rst = 1;
          Wr_ds1302_byte(addr);
          value=Rd_ds1302_byte();
          Rst = 0;
          IO = 1;
          Sclk = 1;
          return value;
          }
          ////////////////////////////////////////////////////////////////////
          void Set_RTC(void)
          {
          Wr_1302(0x8e,0x00);
          Wr_1302(0x80,0x80);
          Wr_1302(Wr_addr[6],(Sec/10)<<4|Sec%10); //Sec
          Wr_1302(Wr_addr[5],(Min/10)<<4|Min%10); //Min
          Wr_1302(Wr_addr[4],(Hour/10)<<4|Hour%10); //Hour
          Wr_1302(Wr_addr[3],(Date/10)<<4|Date%10); //Date
          Wr_1302(Wr_addr[2],(Mouth/10)<<4|Mouth%10); //Mouth
          Wr_1302(Wr_addr[1],(Week/10)<<4|Week%10); //Weak
          Wr_1302(Wr_addr[0],(Year/10)<<4|Year%10); //Year
          Wr_1302(0x8e,0x80);
          }
          /////////////////////////////////////////////////////////////////
          void Rd_RTC(void)
          {
          Sec = Rd_1302(0x81); //Sec
          Min = Rd_1302(0x83); //Min
          Hour = Rd_1302(0x85); //Hour
          Date = Rd_1302(0x87); //Date
          Mouth = Rd_1302(0x89); //Mouth
          Year = Rd_1302(0x8d); //Year
          Week = Rd_1302(0x8b); //Week
          }
          ////////////////////////////////////////////////////////////
          void change(void)
          {
          //Year
          Display[2] = Display_number[Year/16];
          Display[3] = Display_number[Year%16];
          //Mouth
          Display[6] = Display_number[Mouth/16];
          Display[7] = Display_number[Mouth%16];
          //Date
          Display[10] = Display_number[Date/16];
          Display[11] = Display_number[Date%16];
          //Hour
          Display_1[0] = Display_number[Hour/16];
          Display_1[1] = Display_number[Hour%16];
          //Min
          Display_1[4] = Display_number[Min/16];
          Display_1[5] = Display_number[Min%16];
          //Sec
          Display_1[8] = Display_number[Sec/16];
          Display_1[9] = Display_number[Sec%16];

          Week = Week%16;
          switch(Week)
          {
          case 1: Display_String(4,2,"一"); break;
          case 2: Display_String(4,2,"二"); break;
          //case 3: Display_String(4,2,"三"); break;
          case 3 :Wr_Command(0x9a,1);Wr_Data(0xc8);Wr_Data(0xfd);break;
          case 4: Display_String(4,2,"四");break;
          case 5: Display_String(4,2,"五"); break;
          case 6: Display_String(4,2,"六"); break;
          case 7: Display_String(4,2,"日"); break;
          default:
          break;
          }
          }

          //--------------------------------------------------------
          void RDbf(void) //讀忙狀態(tài)
          {
          while(1)
          {
          RS=0;
          RW=1;
          E=0;
          LCMdata=0xFF;
          E=1;
          if((LCMdata&Busy)==0)
          break;
          }
          }
          //--------------------------------------------------------
          void Wr_Data(uchar wrdata) //寫(xiě)數(shù)據(jù)
          {
          RDbf();
          RS=1;
          RW=0;
          E=1;
          LCMdata=wrdata;
          E=0;
          }

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

          評(píng)論


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