⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sht11.lst

📁 关于瑞士SHT11程序
💻 LST
📖 第 1 页 / 共 2 页
字号:
 219   1              for(j=100;j>0;j--);
 220   1      
 221   1      
 222   1      }
 223          
 224          
 225          bit Check_Busy()  //check the 1602 state ,if busing return 1, else return 0
 226          {
 227   1              bit Busy;
 228   1              RS =0;
 229   1              RW =1;
 230   1              E=1;
 231   1              DelayUs();
 232   1              Busy =(bit)(LCD_DATA&0X80);
 233   1              E=0;
 234   1              return Busy;
 235   1      
 236   1      }
 237          
 238          
 239          void Wait(void)  //wait the 1602 idle;
C51 COMPILER V8.08   SHT11                                                                 04/07/2009 22:03:19 PAGE 5   

 240          {
 241   1              while(Check_Busy());
 242   1      
 243   1      
 244   1      }
 245          
 246          
 247          
 248          void Write_Command(uchar Command) //write the command
 249          {
 250   1              Wait();
 251   1              RS =0;
 252   1              RW =0;
 253   1              E =0;
 254   1              DelayUs();
 255   1              LCD_DATA =Command;
 256   1              DelayUs();
 257   1              E =1;
 258   1              DelayUs();
 259   1              E =0;
 260   1      
 261   1      }
 262          
 263          
 264          void Write_Command_NO(uchar Command) //write the command   but uncheck the busy
 265          {
 266   1              
 267   1              RS =0;
 268   1              RW =0;
 269   1              E =0;
 270   1              DelayUs();
 271   1              LCD_DATA =Command;
 272   1              DelayUs();
 273   1              E =1;
 274   1              DelayUs();
 275   1              E =0;
 276   1      
 277   1      }
 278          
 279          
 280          
 281          void Write_Data(uchar Data)      //write data
 282          {
 283   1              Wait();
 284   1              RS =1;
 285   1              E =0;
 286   1              RW =0;
 287   1              DelayUs();
 288   1              LCD_DATA =Data;
 289   1              DelayUs();
 290   1              E =1;
 291   1              DelayUs();
 292   1              E =0;
 293   1      
 294   1      }
 295          
 296          
 297           void Write_Data_NO(uchar Data)  //write data  but uncheck the busy 
 298          {
 299   1              
 300   1              RS =1;
 301   1              E =0;
C51 COMPILER V8.08   SHT11                                                                 04/07/2009 22:03:19 PAGE 6   

 302   1              RW =0;
 303   1              DelayUs();
 304   1              LCD_DATA =Data;
 305   1              DelayUs();
 306   1              E =1;
 307   1              DelayUs();
 308   1              E =0;
 309   1      
 310   1      }
 311          
 312          
 313          
 314          
 315          void Init_Lcd(void)        //init the 1602
 316          {
 317   1              DelayMs(15);
 318   1              Write_Command_NO(0X38);
 319   1              DelayMs(5);
 320   1              Write_Command_NO(0X38);
 321   1              DelayMs(5);
 322   1              Write_Command_NO(0X38);
 323   1      
 324   1              Write_Command(0x38);
 325   1              Write_Command(0x08);  //display the  cursor      and the cursor flash
 326   1              Write_Command(0x01);
 327   1              Write_Command(0x06);
 328   1              Write_Command(0x0c);
 329   1      
 330   1      }
 331          
 332          void Select_Position(uchar x, uchar y)   //display on the 1602 x line  ,y position
 333          {
 334   1              uchar P;
 335   1              switch(x)
 336   1              {
 337   2                      case 1: P=0X80;break;
 338   2                      case 2: P=0xc0;break;
 339   2      
 340   2              }
 341   1              P +=y;
 342   1              Write_Command(P);
 343   1      }
 344          
 345          
 346          
 347          void Date_To_String(Systemtime *Time,float DATA,float DATA1)
 348          {
 349   1              uint i;
 350   1          i=(int)DATA;
 351   1              Time->shiwei=i/10;
 352   1              Time->gewei =i%10;
 353   1          Time->DATAstrins1[0] = Time->shiwei + '0';
 354   1              Time->DATAstrins1[1] = Time->gewei + '0';
 355   1              i=(int)((DATA-i)*10); 
 356   1              Time->DATAstrins1[2] ='.';
 357   1              Time->DATAstrins1[3] = i + '0';
 358   1              Time->DATAstrins1[4] = '\0';
 359   1      
 360   1          i=(int)DATA1;
 361   1              Time->shiwei=i/10;
 362   1              Time->gewei =i%10;
 363   1          Time->DATAstrins2[0] = Time->shiwei + '0';
C51 COMPILER V8.08   SHT11                                                                 04/07/2009 22:03:19 PAGE 7   

 364   1              Time->DATAstrins2[1] = Time->gewei + '0';   
 365   1              i=(int)((DATA1-i)*10); 
 366   1              Time->DATAstrins2[2] ='.';
 367   1              Time->DATAstrins2[3] = i + '0';
 368   1              Time->DATAstrins2[4] = '%';
 369   1              Time->DATAstrins2[5] = '\0';
 370   1      }
 371          
 372          
 373          
 374          void Write_String(uchar *String)
 375          {
 376   1              unsigned char i;
 377   1              while(String[i]!='0')
 378   1              {
 379   2                      Write_Data(String[i++]);
 380   2              
 381   2              
 382   2              
 383   2              }
 384   1      }
 385          
 386          /***************************************************************************************/
 387          void main(void)
 388          {
 389   1              Systemtime S;
 390   1              uchar time_str1[]={"Temp"};     
 391   1              uchar time_str2[]={"Humi"};
 392   1              Value Temp_Value ,Humi_Value;
 393   1              uchar error ,checksum;
 394   1              uint i;
 395   1              Connection_Reset();
 396   1              Init_Lcd();
 397   1              Select_Position(1, 0);
 398   1              Write_String(time_str1);
 399   1              Select_Position(2, 0);
 400   1              Write_String(time_str2);
 401   1              while(1)
 402   1              {
 403   2                      error =0;
 404   2                      error+=Measure_Mode((unsigned char*) &Humi_Value.i,&checksum,1);   /*measure humidity*/
 405   2              error+=Measure_Mode((unsigned char*) &Temp_Value.i,&checksum,0);   /*measure temperature*/
 406   2                      if(error!=0) 
 407   2                  Connection_Reset();                               /*in case of an error:connection reset*/
 408   2              else
 409   2              { 
 410   3               Humi_Value.f=(float)Humi_Value.i;                     /*converts integer to float*/
 411   3               Temp_Value.f=(float)Temp_Value.i;                     /*converts integer to float*/
 412   3               Calculate_SHT11(&Humi_Value.f,&Temp_Value.f);              /*calculate humidity,temperature*/
 413   3               Date_To_String(&S,Temp_Value.f,Humi_Value.f);                            
 414   3               Select_Position(1,5);
 415   3               Write_String(S.DATAstrins1);         
 416   3               Select_Position(2,5);
 417   3               Write_String(S.DATAstrins2);
 418   3              }
 419   2           /*----------wait approx. 0.8s to avoid heating up SHT10------------------------------ */      
 420   2              for (i=0;i<10000;i++);     //(be sure that the compiler doesn't eliminate this line!)
 421   2           /*----------------------------------------------------------------------------------- */             
             -       
 422   2         }
 423   1              
 424   1              
C51 COMPILER V8.08   SHT11                                                                 04/07/2009 22:03:19 PAGE 8   

 425   1      }
 426           
 427          
 428          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1463    ----
   CONSTANT SIZE    =     10    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----     106
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----       1
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -