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

📄 text2.lst

📁 个人单片机入门程序集合 。很适合刚学单片机的人。用的是keil proteus
💻 LST
📖 第 1 页 / 共 2 页
字号:
 212          void xianshi(unsigned long a)
 213          {          unsigned long c,p=0;
 214   1                                      if (a!=0) 
 215   1                              {       c=a/100000000;
 216   2                                      if(c!=0)
 217   2                      {lcd1602_wrdata(c+0x30);
 218   3                                   p=1;
 219   3                                       }
 220   2                      delay(100);
 221   2                                      c=(a%100000000)/10000000;
 222   2                                      if(c!=0 || p==1 )
 223   2                      {lcd1602_wrdata(c+0x30);
 224   3                                   p=1;
 225   3                                       }
 226   2                      delay(100);
 227   2                                      c=(a%10000000)/1000000;
 228   2                                      if(c!=0 || p==1 )
 229   2                      {lcd1602_wrdata(c+0x30);
 230   3                                   p=1;
 231   3                                       }
 232   2                      delay(100);
 233   2                                      c=(a%1000000)/100000;
 234   2                                      if(c!=0 || p==1 )
 235   2                      {lcd1602_wrdata(c+0x30);
 236   3                                   p=1;
 237   3                                       }
 238   2                      delay(100);
 239   2                                      c=(a%100000)/10000;
 240   2                                      if(c!=0 || p==1 )
 241   2                      {lcd1602_wrdata(c+0x30);
C51 COMPILER V7.20   TEXT2                                                                 07/21/2007 13:47:15 PAGE 5   

 242   3                                    p=1;
 243   3                                       }
 244   2                      delay(100);
 245   2                      c=(a%10000)/1000;
 246   2                      if(c!=0 || p==1)
 247   2                       {lcd1602_wrdata(c+0x30);
 248   3                                    }
 249   2                      delay(100);
 250   2                                      c=(a%1000)/100;
 251   2                      if(c!=0 || p==1)
 252   2                       {lcd1602_wrdata(c+0x30);
 253   3                                    }
 254   2                      delay(100);
 255   2                                      c=(a%100)/10;
 256   2                      if(c!=0 || p==1)
 257   2                       {lcd1602_wrdata(c+0x30);
 258   3                                    }
 259   2                      delay(100);
 260   2                          c=a%10+0x30;
 261   2                          lcd1602_wrdata(c);   
 262   2                                      delay(100);
 263   2                                      
 264   2                  }
 265   1      }
 266          
 267          
 268          
 269          
 270          
 271          void delay1820(unsigned int i) 
 272          { 
 273   1      while(i--); 
 274   1      } 
 275          
 276          //初始化函数 
 277          Init_DS18B20(void) 
 278          { 
 279   1      wtdg=!wtdg; 
 280   1      DQ = 1; //DQ复位 
 281   1      delay1820(8); //稍做延时 
 282   1      DQ = 0; //单片机将DQ拉低 
 283   1      delay1820(80); //精确延时 大于 480us 
 284   1      DQ = 1; //拉高总线 
 285   1      delay1820(14); 
 286   1      xbz=DQ; //稍做延时后 如果x=0则初始化成功 x=1则初始化失败 
 287   1      delay1820(20); 
 288   1      DQ=1; 
 289   1      } 
 290          
 291          //读一个字节 
 292          ReadOneChar(void) 
 293          { 
 294   1      unsigned char i=0; 
 295   1      unsigned char dat = 0; 
 296   1      wtdg=!wtdg; 
 297   1      for (i=8;i>0;i--) 
 298   1      { 
 299   2      DQ = 0; // 给脉冲信号 
 300   2      dat>>=1; 
 301   2      DQ = 1; // 给脉冲信号 
 302   2      if(DQ) 
 303   2      dat|=0x80; 
C51 COMPILER V7.20   TEXT2                                                                 07/21/2007 13:47:15 PAGE 6   

 304   2      delay1820(4); 
 305   2      } 
 306   1      return(dat); 
 307   1      } 
 308          
 309          //写一个字节 
 310          WriteOneChar(unsigned char dat) 
 311          { 
 312   1      unsigned char i=0; 
 313   1      wtdg=!wtdg; 
 314   1      for (i=8; i>0; i--) 
 315   1      { 
 316   2      DQ = 0; 
 317   2      DQ = dat&0x01; 
 318   2      delay1820(5); 
 319   2      DQ = 1; 
 320   2      dat>>=1; 
 321   2      } 
 322   1      delay(4); 
 323   1      } 
 324          
 325          void Config18b20() 
 326          { 
 327   1      Init_DS18B20(); 
 328   1      WriteOneChar(0xcc); //skip rom 
 329   1      WriteOneChar(0x4e); //write scratchpad 
 330   1      WriteOneChar(0x55); //上限 
 331   1      WriteOneChar(0x00); //下限 
 332   1      WriteOneChar(0x7f); //set 11 bit (0.125) 
 333   1      Init_DS18B20(); 
 334   1      WriteOneChar(0xcc); //skip rom 
 335   1      WriteOneChar(0x48); //保存设定值 
 336   1      Init_DS18B20(); 
 337   1      WriteOneChar(0xcc); //skip rom 
 338   1      WriteOneChar(0xb8); //回调设定值 
 339   1      } 
 340          
 341          uint ReadTemperature() 
 342          { 
 343   1      unsigned char a=0; 
 344   1      unsigned char b=0; 
 345   1      unsigned char t=0; 
 346   1      unsigned int g; 
 347   1      Config18b20(); 
 348   1      Init_DS18B20(); 
 349   1      WriteOneChar(0xCC); // 跳过读序号列号的操作 
 350   1      WriteOneChar(0x44); // 启动温度转换 
 351   1      delay(500); 
 352   1      Init_DS18B20(); 
 353   1      WriteOneChar(0xCC); //跳过读序号列号的操作 
 354   1      WriteOneChar(0xBE); //读取温度寄存器等(共可读9个寄存器) 前两个就是温度 
 355   1      a=ReadOneChar(); //读取温度值低位 
 356   1      b=ReadOneChar(); //读取温度值高位 
 357   1      DQ=1; 
 358   1      g=b<<8; //最终数据在a和b中,怎么处理你自己用吧 呵呵 
 359   1      g=g|a; 
 360   1      g=g*0.625; //这是转换成具体温度值,1点代表0.625°C 
 361   1      return(g);
 362   1      }
 363          
 364          void main()                                                                                                                                                      
 365          {       
C51 COMPILER V7.20   TEXT2                                                                 07/21/2007 13:47:15 PAGE 7   

 366   1         
 367   1          uchar i;
 368   1      //      uint t;
 369   1              uchar s1[]="tempretrue:";
 370   1      
 371   1          uchar str0='7';
 372   1              uchar str1='4';
 373   1              uchar str2='1';
 374   1          uchar str3=' ';
 375   1              uchar str4='8';
 376   1              uchar str5='5';
 377   1          uchar str6='2';
 378   1              uchar str7='0';
 379   1              uchar str8='9';
 380   1          uchar str9='6';
 381   1              uchar str10='3';
 382   1              uchar str11='=';
 383   1              uchar str12='/';
 384   1              uchar str13='*';
 385   1          uchar str14='-';
 386   1              uchar str15='+';
 387   1              unsigned long c,a=0,b,t;
 388   1              uchar j; //标记加减乘除 
 389   1              
 390   1              
 391   1      
 392   1              unsigned char offset=0x80;   //定义一个偏移地址变量,lcd1602 写入控制字时用到
 393   1              unsigned char key;
 394   1      //      unsigned int count1=10;
 395   1      //      unsigned int count2=297;
 396   1          
 397   1              delay(2);
 398   1              lcd1602_bus=0xff;
 399   1              lcd1602_init();
 400   1          lcd1602_wrcmd(offset+0x00);
 401   1              for(i=0;i<10;i++)   lcd1602_wrdata(s1[i]); 
 402   1              t=ReadTemperature();
 403   1          xianshi(t);
 404   1       //   for(i=0;i<2;i++)    lcd1602_wrdata(s2[i]+0x30);
 405   1          //  lcd1602_wrcmd(offset+0x40);
 406   1          //  for(i=0;i<11;i++)   lcd1602_wrdata(str02[i]);
 407   1      
 408   1      //      lcd1602_clear();
 409   1         
 410   1      
 411   1      }
*** WARNING C280 IN LINE 387 OF TEXT2.C: 'c': unreferenced local variable
*** WARNING C280 IN LINE 387 OF TEXT2.C: 'b': unreferenced local variable
*** WARNING C280 IN LINE 388 OF TEXT2.C: 'j': unreferenced local variable
*** WARNING C280 IN LINE 393 OF TEXT2.C: 'key': unreferenced local variable


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1409    ----
   CONSTANT SIZE    =    136    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =      2      55
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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