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

📄 text1.lst

📁 这是一个温度采集试验
💻 LST
字号:
C51 COMPILER V7.02a   TEXT1                                                                08/21/2007 15:06:16 PAGE 1   


C51 COMPILER V7.02a, COMPILATION OF MODULE TEXT1
OBJECT MODULE PLACED IN Text1.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE Text1.c BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          #include"reg51.h"
   2          
   3          //*******************LCD模块
   4          
   5          #define LCD_DATA P1        //LCD的数据口
   6          
   7          sbit LCD_BUSY=LCD_DATA^7;  //LCD忙信号位
   8          
   9          sbit LCD_RS=P0^0;          //LCD寄存器选择
  10          sbit LCD_RW=P0^1;          //LCD读写控制
  11          sbit LCD_EN=P0^2;          //LCD使能信号
  12          
  13          
  14          void LCD_check_busy(void)   //检测LCD状态,看它是不是还在忙呢
  15          {
  16   1       while(1)
  17   1        {
  18   2         LCD_EN=0;
  19   2         LCD_RS=0; //指令寄存器通信
  20   2         LCD_RW=1;  //read data
  21   2         LCD_DATA=0xff;
  22   2         LCD_EN=1;
  23   2         if(!LCD_BUSY)break;
  24   2        }
  25   1       LCD_EN=0;
  26   1      }
  27          
  28          void LCD_cls(void)          //LCD清屏
  29          {
  30   1       
  31   1       LCD_check_busy();
  32   1       LCD_RS=0;
  33   1       LCD_RW=0;
  34   1       LCD_DATA=1;
  35   1       LCD_EN=1;
  36   1       LCD_EN=0;
  37   1       
  38   1      }
  39          
  40          void LCD_write_instruction(unsigned char LCD_instruction)   //写指令到LCD
  41          {
  42   1       LCD_check_busy();
  43   1       LCD_RS=0;
  44   1       LCD_RW=0;      //写数据
  45   1       
  46   1       LCD_DATA=LCD_instruction;
  47   1       LCD_EN=1;
  48   1       LCD_EN=0;
  49   1       }
  50          
  51          void LCD_write_data(unsigned char LCD_data)      //输出一个字节数据到LCD
  52          {
  53   1       LCD_check_busy();
  54   1       LCD_RS=1;
  55   1       LCD_RW=0;
C51 COMPILER V7.02a   TEXT1                                                                08/21/2007 15:06:16 PAGE 2   

  56   1       
  57   1       LCD_DATA=LCD_data;
  58   1       LCD_EN=1;
  59   1       LCD_EN=0;
  60   1       }
  61           
  62          void LCD_set_position(unsigned char x)            //LCD光标定位到x处
  63          {
  64   1      LCD_write_instruction(0x80+x);
  65   1      }
  66          
  67          
  68          
  69          
  70          
  71          void LCD_printc(unsigned char lcd_data)          //输出一个字符到LCD
  72          {
  73   1       LCD_write_data(lcd_data);
  74   1      }
  75          
  76          void LCD_prints(unsigned char *lcd_string)       //输出一个字符串到LCD
  77          {
  78   1       unsigned char i=0;
  79   1       while(lcd_string[i]!=0x00)
  80   1        {
  81   2         LCD_write_data(lcd_string[i]);
  82   2         i++;
  83   2        } 
  84   1      }
  85          
  86          void LCD_initial(void)                        //初始化LCD
  87          {
  88   1       LCD_write_instruction(0x3c);
  89   1       LCD_write_instruction(0x0c);
  90   1       LCD_write_instruction(0x06);//显示屏一定要不移动。
  91   1       LCD_cls();
  92   1      }
  93          //*************************LCD模块结束
  94          
  95           //*******************************ds18b20
  96          unsigned char ds18b20_num1[8]={0x8e,0x00,0x00,0x00,0xb8,0xc5,0x30,0x28};
  97          unsigned char ds18b20_num2[8]={0xb9,0X00,0X00,0x00,0xb8,0Xc5,0X31,0X28};
  98          unsigned char ds18b20_num3[8]={0xe0,0x00,0x00,0x00,0xb8,0xc5,0x32,0x28};
  99          sbit DQ =P3^6;   //定义通信端口
 100          
 101          //延时函数
 102          
 103          void delay(unsigned int i)
 104          {
 105   1       while(i--);
 106   1      }
 107          
 108          //初始化函数
 109           unsigned char Init_DS18B20(void)
 110          {
 111   1       unsigned char x=0;
 112   1       DQ = 1;    //DQ复位
 113   1       delay(8);  //稍做延时
 114   1       DQ = 0;    //单片机将DQ拉低
 115   1       delay(80); //精确延时 大于 480us
 116   1       DQ = 1;    //拉高总线
 117   1       delay(14);
C51 COMPILER V7.02a   TEXT1                                                                08/21/2007 15:06:16 PAGE 3   

 118   1       x=DQ;      //稍做延时后 如果x=0则初始化成功 x=1则初始化失败
 119   1       delay(20);
 120   1       return (x);
 121   1      }
 122          
 123          //读一个字节
 124          ReadOneChar(void)
 125          {
 126   1      unsigned char i=0;
 127   1      unsigned char dat = 0;
 128   1      for (i=8;i>0;i--)
 129   1       {
 130   2        DQ = 0; // 给脉冲信号
 131   2        dat>>=1;
 132   2        DQ = 1; // 给脉冲信号
 133   2        if(DQ)
 134   2         dat|=0x80;
 135   2        delay(4);
 136   2       }
 137   1       return(dat);
 138   1      }
 139          
 140          //写一个字节
 141          WriteOneChar(unsigned char dat)
 142          {
 143   1       unsigned char i=0;
 144   1       for (i=8; i>0; i--)
 145   1       {
 146   2        DQ = 0;
 147   2        DQ = dat&0x01;
 148   2        delay(5);
 149   2        DQ = 1;
 150   2        dat>>=1;
 151   2       }
 152   1      //delay(4);
 153   1      }
 154          unsigned char * read_rom(void)
 155          {
 156   1              unsigned char rom[8],i;
 157   1              Init_DS18B20();
 158   1              WriteOneChar(0x33);
 159   1              for(i=8;i>0;i--)
 160   1              {
 161   2                      rom[i-1]=ReadOneChar();
 162   2              }
 163   1              return &rom[0];
 164   1      }
 165          bit match_rom(unsigned char *rom)
 166          {
 167   1              unsigned char i;
 168   1              //Init_DS18B20();
 169   1              WriteOneChar(0x55);
 170   1              for(i=8;i>0;i--)
 171   1              {
 172   2                      WriteOneChar(*(rom+i-1));
 173   2              //      rom++;
 174   2              }
 175   1              return 1;
 176   1      }               
 177          
 178          //读取温度
 179          ReadTemperature(unsigned char n)
C51 COMPILER V7.02a   TEXT1                                                                08/21/2007 15:06:16 PAGE 4   

 180          {
 181   1      unsigned char a=0;
 182   1      unsigned char b=0;
 183   1      unsigned int t=0;
 184   1      float tt=0;
 185   1      Init_DS18B20();
 186   1      WriteOneChar(0xCC); // 跳过读序号列号的操作
 187   1      WriteOneChar(0x44); // 启动温度转换
 188   1      Init_DS18B20();
 189   1      //WriteOneChar(0xCC); //跳过读序号列号的操作
 190   1      //if (n==1)  match_rom(ds18b20_num1);
 191   1      //else if (n==2)  match_rom(ds18b20_num2);
 192   1      //else if (n==3)  match_rom(ds18b20_num3);
 193   1      //.......................
 194   1      //else if (n==0) 
 195   1      WriteOneChar(0xCC); //跳过读序号列号的操作 
 196   1      WriteOneChar(0xBE); //读取温度寄存器等(共可读9个寄存器) 前两个就是温度
 197   1      a=ReadOneChar();
 198   1      b=ReadOneChar();
 199   1      t=b;
 200   1      t<<=8;
 201   1      t=t|a;
 202   1      tt=t*0.0625;
 203   1      t= tt*10+0.5; //放大10倍输出并四舍五入---此行没用
 204   1      return(t);
 205   1      }
*** WARNING C280 IN LINE 179 OF TEXT1.C: 'n': unreferenced local variable
 206           //****************************************ds18b20结束
 207           unsigned char TempBuffer[5];
 208          void IntToStr(unsigned int t, unsigned char *str, unsigned char n) 
 209          {
 210   1              unsigned char a[5]; char i, j;    //取得整数值到数组                                    
 211   1              a[0]=t/100;   //百位            
 212   1              a[1]=(t/10)%10;//十位                                           
 213   1              a[2]=t%10;    //个位                            
 214   1                                                      
 215   1                                                            
 216   1              for(i=0; i<3; i++)         //转成ASCII码                
 217   1                      a[i]=a[i]+'0';                                          
 218   1              for(i=0; a[i]=='0' && i<=3; i++);                       
 219   1              for(j=3-n; j<i; j++)       //填充空格                   
 220   1                      { *str=' ';  str++; }                                   
 221   1              for(; i<3; i++)                                         
 222   1                      { *str=a[i]; str++; }  //加入有效的数字                 
 223   1              *str='\0'; 
 224   1      } 
 225          
 226          
 227          
 228          
 229          main()
 230          { 
 231   1      //==读取序列号操作。在1602上显示。
 232   1       /*unsigned char i; 
 233   1      unsigned char *ds1820rom;
 234   1        ds1820rom=read_rom();
 235   1        LCD_initial();
 236   1        LCD_set_position(0);
 237   1        for(i=0;i<8;i++)
 238   1        {unsigned char a;
 239   1         a=(*ds1820rom)/16;
 240   1        if(a>=0&&a<=9) a=a+'0';
C51 COMPILER V7.02a   TEXT1                                                                08/21/2007 15:06:16 PAGE 5   

 241   1        else if(a>=0x0a &&a<= 0x0f) a=a-10+'a';
 242   1        LCD_printc(a);
 243   1        a=(*ds1820rom)%16;
 244   1        if(a>=0&&a<=9) a=a+'0';
 245   1        else if(a>=0x0a &&a<= 0x0f) a=a-10+'a';
 246   1        LCD_printc(a);
 247   1        ds1820rom++;
 248   1        }
 249   1        while(1);*/
 250   1      
 251   1      
 252   1      unsigned int i,a;
 253   1          i=ReadTemperature(3); //读温度
 254   1      
 255   1          a=i;
 256   1          IntToStr(i,&TempBuffer[0],3);
 257   1          LCD_initial();
 258   1          LCD_set_position(0);
 259   1          LCD_prints("temperature :");
 260   1          LCD_set_position(0x40);
 261   1          LCD_printc(TempBuffer[0]); 
 262   1              LCD_printc(TempBuffer[1]);
 263   1              LCD_printc('.');
 264   1              LCD_printc(TempBuffer[2]);
 265   1              LCD_printc(' ');
 266   1              LCD_printc(0xDF);
 267   1              LCD_printc('C');
 268   1      while(1)
 269   1       {      i=ReadTemperature(3); 
 270   2          if (i!=a )    //如果有变化
 271   2               {       a=i;
 272   3              IntToStr(i,&TempBuffer[0],3);
 273   3          LCD_initial();
 274   3          LCD_set_position(0);
 275   3          LCD_prints("temperature :");
 276   3          LCD_set_position(0x40);
 277   3          LCD_printc(TempBuffer[0]); 
 278   3              LCD_printc(TempBuffer[1]);
 279   3              LCD_printc('.');
 280   3              LCD_printc(TempBuffer[2]);
 281   3              LCD_printc(' ');
 282   3              LCD_printc(0xDF);
 283   3              LCD_printc('C');
 284   3      
 285   3      
 286   3               }
 287   2      }       
 288   1      
 289   1      }
 290            


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    707    ----
   CONSTANT SIZE    =     14    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     29      35
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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