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

📄 ds18b20(lcd).lst

📁 单片机型号为STC89C52
💻 LST
字号:
C51 COMPILER V8.08   DS18B20_LCD_                                                          10/05/2008 16:26:09 PAGE 1   


C51 COMPILER V8.08, COMPILATION OF MODULE DS18B20_LCD_
OBJECT MODULE PLACED IN DS18B20(LCD).OBJ
COMPILER INVOKED BY: D:\keil\C51\BIN\C51.EXE DS18B20(LCD).C BROWSE DEBUG OBJECTEXTEND

line level    source

   1          #include <reg52.h>
   2          #define uchar unsigned char
   3          #define uint unsigned int
   4          sbit DS=P2^2;           //define interface
   5          sbit lcden=P3^4;
   6          sbit lcdrs=P3^5;
   7          sbit dula=P2^6;
   8          sbit wela=P2^7;
   9          sbit beep=P2^3;
  10          sbit dscs=P1^4;
  11          sbit dsas=P1^5;
  12          sbit dsrw=P1^6;
  13          sbit dsds=P1^7;
  14          sbit s1=P3^0;
  15          sbit s2=P3^1;
  16          sbit s3=P3^2;
  17          sbit ss=P3^6;
  18          sbit rd=P3^7;
  19          uchar code tab[] ={ 0x18,0x18,0x07,0x08,0x08,0x08,0x07,0x00,    //℃,代码 0x00
  20                                              0x00,0x00,0x00,0x00,0x0C,0x0C,0x00,0x00,};  //.
  21          uint temp,bai,shi,ge;             // 温度值的变量
  22          uchar flag1;           // 结果为负和正的标志位
  23          void readrom();
  24          void tmp();
  25          void write_date(uchar) ;
  26          void write_com(uchar );
  27          void tmpwritebyte(uchar );
  28          
  29          void delay(uint count)      //delay
  30          {
  31   1        uint i;
  32   1        while(count)
  33   1        {
  34   2          i=20;
  35   2          while(i>0)
  36   2          i--;
  37   2          count--;
  38   2        }
  39   1      }
  40          void dsreset(void)       //发送复位和初始化
  41          {
  42   1        uint i;
  43   1        DS=0;
  44   1        i=103;
  45   1        while(i>0)i--;  //延时
  46   1        DS=1;
  47   1        i=4;
  48   1        while(i>0)i--;
  49   1      }
  50          
  51          bit tmpreadbit(void)       //读取数据的一位
  52          {
  53   1         uint i;
  54   1         bit dat;
  55   1         DS=0;i++;          //i++ for delay
C51 COMPILER V8.08   DS18B20_LCD_                                                          10/05/2008 16:26:09 PAGE 2   

  56   1         DS=1;i++;i++;
  57   1         dat=DS;
  58   1         i=8;while(i>0)i--;
  59   1         return (dat);
  60   1      }
  61          
  62          uchar tmpread(void)   //读一个字节
  63          {
  64   1        uchar i,j,dat;
  65   1        dat=0;
  66   1        for(i=1;i<=8;i++)
  67   1        {
  68   2          j=tmpreadbit();
  69   2          dat=(j<<7)|(dat>>1);   //读出的数据最低位在最前面,这样刚好一个字节在DAT里
  70   2        }
  71   1        return(dat);
  72   1      }
  73          
  74          void tmpwritebyte(uchar dat)   //write a byte to ds18b20
  75          {
  76   1              uint i;
  77   1              uchar j;
  78   1              bit testb;
  79   1              for(j=1;j<=8;j++)
  80   1              {
  81   2                  testb=dat&0x01;
  82   2                  dat=dat>>1;
  83   2                  if(testb)     //write 1
  84   2                  {
  85   3                              DS=0;
  86   3                              i++;i++;
  87   3                              DS=1;
  88   3                              i=8;while(i>0)i--;
  89   3                      }
  90   2                  else
  91   2                  {
  92   3                              DS=0;       //write 0
  93   3                              i=8;while(i>0)i--;
  94   3                              DS=1;
  95   3                              i++;i++;
  96   3                  }
  97   2              }
  98   1      }
  99          
 100          void tmpchange(void)  //DS18B20 begin change
 101          {
 102   1              dsreset();
 103   1              delay(1);
 104   1              tmpwritebyte(0xcc);  // address all drivers on bus
 105   1              tmpwritebyte(0x44);  //  initiates a single temperature conversion
 106   1      }
 107          
 108          void tmp()               //读取温度
 109          {
 110   1              float tt;
 111   1              uchar a,b;
 112   1              dsreset(); //复位
 113   1              delay(1);
 114   1              tmpwritebyte(0xcc);       //跳过序列号命令
 115   1              tmpwritebyte(0xbe);       //发转换命令
 116   1              a=tmpread();  //读取低位温度
 117   1              b=tmpread();  //读取高位温度
C51 COMPILER V8.08   DS18B20_LCD_                                                          10/05/2008 16:26:09 PAGE 3   

 118   1              temp=b;
 119   1              temp<<=8;             //two byte  compose a int variable
 120   1              temp=temp|a;
 121   1              tt=temp*0.0625;
 122   1              temp=tt*10+0.5;
 123   1      //      return temp;
 124   1      }
 125          
 126          /************************
 127          1602
 128          **************************/
 129          void write_com(uchar com) //写命令 
 130          {
 131   1          lcdrs=0;
 132   1          lcden=0;
 133   1          P0=com;
 134   1          delay(5);
 135   1          lcden=1;
 136   1          delay(5);
 137   1          lcden=0;    
 138   1      }
 139          
 140          void write_date(uchar dat) //写数据 
 141          {
 142   1          lcdrs=1;
 143   1          lcden=0;
 144   1          P0=dat;
 145   1          delay(5);
 146   1          lcden=1;
 147   1          delay(5);
 148   1          lcden=0;    
 149   1      }
 150          
 151          void init()  //初始化 
 152          {
 153   1          EA=1;
 154   1          EX0=1;//开外部0中断 
 155   1          IT0=1;//外部中断0的触发方式为边沿触发方式( 下降沿有效) 
 156   1      
 157   1          dula=0;
 158   1          wela=0;
 159   1          lcden=0;
 160   1          write_com(0x38);
 161   1          write_com(0x0c);
 162   1          write_com(0x06);
 163   1          write_com(0x01);
 164   1          write_com(0x80);
 165   1          write_com(0x80+0x40);
 166   1      }
 167          
 168          void write_tmp(uchar add2, uchar date1)  //写温度
 169          {
 170   1          uchar bai,shi,ser;
 171   1              ser=temp/10;
 172   1              SBUF=ser;
 173   1              bai=temp/100;
 174   1          shi=temp%100/10;
 175   1          write_com(0x80+0x40+add2);
 176   1              write_date(0x30+bai);
 177   1          write_date(0x30+shi);
 178   1      }
*** WARNING C280 IN LINE 168 OF DS18B20(LCD).C: 'date1': unreferenced local variable
C51 COMPILER V8.08   DS18B20_LCD_                                                          10/05/2008 16:26:09 PAGE 4   

 179          void write_tmp1(uchar add3, uchar date2)  //写温度小数点后一位
 180          {
 181   1          uchar ge,ser;
 182   1              ser=temp/10;
 183   1              SBUF=ser;
 184   1          ge=temp%10;
 185   1          write_com(0x80+0x40+add3);
 186   1          write_date(0x30+ge);
 187   1      }
*** WARNING C280 IN LINE 179 OF DS18B20(LCD).C: 'date2': unreferenced local variable
 188          //写地址函数
 189          void LCD_set_rc( uchar r, uchar c )
 190          {
 191   1          uchar address;    
 192   1          if (r == 1)
 193   1          address = 0x80 + c;
 194   1          else if(r == 2)
 195   1          address = 0xc0 + c;    
 196   1          write_com( address );
 197   1      }
 198          
 199          
 200          //写一个字符
 201          void LCD_write_char(uchar r, uchar c, uchar date)
 202          {
 203   1        LCD_set_rc( r, c );                 //写地址
 204   1        write_date( date );
 205   1      }
 206          
 207          //向CGRAM写入字模数据
 208          void write_CGRAM( uchar TAB[], uchar n )     //定义输入CGRAM的字模代码,字模的个数
 209          {
 210   1          uchar tmp;
 211   1          uchar i;
 212   1          uchar j;
 213   1          uchar k;
 214   1          tmp = 0x40;                       //设置CGRAM地址的格式字
 215   1          k = 0;
 216   1          for( j = 0; j < n; j++)
 217   1          {
 218   2              for(i = 0; i < 8; i++)
 219   2              {
 220   3                  write_com(tmp + i); // 设置自定义字符的 CGRAM 地址
 221   3                  write_date(TAB[k]);   // 向CGRAM写入自定义字符表的数据
 222   3                  k++;
 223   3               }
 224   2               tmp = tmp + 0x08;
 225   2           }
 226   1      }
 227          void main()
 228          {
 229   1              init();
 230   1              do
 231   1              {       
 232   2                      write_CGRAM(tab, 2);
 233   2                      tmp();
 234   2                      tmpchange();
 235   2                      write_tmp(10,bai); 
 236   2                      LCD_write_char(2, 12, 1); 
 237   2                      write_tmp1(13,ge);              
 238   2                      LCD_write_char(2, 14, 0); //显示℃
 239   2                      
C51 COMPILER V8.08   DS18B20_LCD_                                                          10/05/2008 16:26:09 PAGE 5   

 240   2              
 241   2              }
 242   1              while(1);
 243   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    664    ----
   CONSTANT SIZE    =     16    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =      9      15
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----       2
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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