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

📄 cewen.lst

📁 基于18b20和单片机控制的温度采集及显示系统
💻 LST
字号:
C51 COMPILER V7.10   CEWEN                                                                 08/20/2007 16:43:26 PAGE 1   


C51 COMPILER V7.10, COMPILATION OF MODULE CEWEN
OBJECT MODULE PLACED IN cewen.OBJ
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE cewen.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1            #include<reg52.h>
   2          #include<math.h>
   3          unsigned char code  SEG[12]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf,0xff}; 
   4          unsigned int i=0,fuhao=11,baiwei=0,shiwei=0,gewei=0,xiaoshu=0;
   5          
   6          sbit DQ=P3^5;//定义通信端口
   7           
   8          //延时函数
   9          void delay(unsigned int j)
  10          {
  11   1       while(j--);
  12   1      }
  13          
  14          //初始化函数
  15          Init_DS18B20(void)
  16          {
  17   1      unsigned char x=0;
  18   1      DQ=1;//DQ复位
  19   1      delay(8);//稍作延时
  20   1      DQ=0;//单片机将DQ拉低
  21   1      delay(80);//精确延时 大于 480 us
  22   1      DQ=1;
  23   1      delay(14);
  24   1      x=DQ;//稍作延时后 如果x=0则初始化成功 x=1则初始化失败
  25   1      delay(20);
  26   1      //P1=0x00;
  27   1      }
  28          
  29          //读一个字节
  30          ReadOneChar(void)
  31          {
  32   1      unsigned char k=0;
  33   1      unsigned char dat=0;
  34   1      for(k=8;k>0;k--)
  35   1      {
  36   2      DQ=0;//给脉冲信号
  37   2      dat>>=1;
  38   2      DQ=1;//给脉冲信号
  39   2      if(DQ)
  40   2      dat|=0x80;
  41   2      delay(4);
  42   2      }
  43   1      return(dat);                                                    
  44   1      }
  45          
  46          //写一个字节
  47          WriteOneChar(unsigned char dat)
  48          {
  49   1      unsigned char j=0;
  50   1      for(j=8;j>0;j--)
  51   1      {
  52   2      DQ=0;
  53   2      DQ=dat&0x01;
  54   2      delay(5);
  55   2      DQ=1;
C51 COMPILER V7.10   CEWEN                                                                 08/20/2007 16:43:26 PAGE 2   

  56   2      dat>>=1;
  57   2      }
  58   1      //delay(4);
  59   1      }
  60          
  61          //读取温度
  62          ReadTemperature(void)
  63          {
  64   1      unsigned char a=0;
  65   1      unsigned char b=0;
  66   1      unsigned int t=0;
  67   1      float tt=0;
  68   1      Init_DS18B20();
  69   1      WriteOneChar(0xCC);//跳过读序号列号的操作
  70   1      WriteOneChar(0x44);//启动温度转换
  71   1      Init_DS18B20();
  72   1      WriteOneChar(0xCC);//跳过度序号列号的操作
  73   1      WriteOneChar(0xBE);//读取温度寄存器等(共可读9个寄存器)前两个就是温度
  74   1      a=ReadOneChar();
  75   1      b=ReadOneChar();
  76   1      t=b;
  77   1      t<<=8;
  78   1      t=t|a;
  79   1      if(b&0xf8)
  80   1      {
  81   2      t=(~t)+1;
  82   2      tt=0-t*0.0625;
  83   2      }
  84   1      else
  85   1      tt=t*0.0625;
  86   1      tt=tt*10+0.5;//放大10倍输出并四舍五入- 此行没用 
  87   1      return(tt);
  88   1      }
  89          
  90          
  91          
  92          void SHOWTEMP( int t)
  93          {
  94   1      if(t<0)
  95   1      fuhao=10;
  96   1      else fuhao=11;
  97   1      
  98   1      t=abs(t);
  99   1      shiwei=t/100;
 100   1      gewei=(t-shiwei*100)/10;
 101   1      xiaoshu=t-shiwei*100-gewei*10;
 102   1      
 103   1      i++; 
 104   1      if(i>4) i=1;
 105   1      if(i==1)
 106   1      { P0=0xfe; P2=SEG[fuhao];  }
 107   1      if(i==2)
 108   1      {
 109   2       P0=0xfd; P2=SEG[shiwei]; }
 110   1      if(i==3)
 111   1      { P0=0xfb; P2=SEG[gewei]-0x80;}
 112   1      if(i==4)
 113   1      { P0=0xf7; P2=SEG[xiaoshu]; }
 114   1      
 115   1      }
 116          
 117          
C51 COMPILER V7.10   CEWEN                                                                 08/20/2007 16:43:26 PAGE 3   

 118          
 119          SHOW(void) interrupt 1
 120          {
 121   1        TH0=0xfc;     
 122   1        TL0=0x17;      
 123   1        TR0=1; 
 124   1       } 
 125          
 126          
 127          
 128          
 129          int main()
 130          {
 131   1              int temp=0;
 132   1              TH0=0xfc;   
 133   1              TL0=0x17;      
 134   1               TR0=1; IE=0x82;         TMOD=0x01;
 135   1              while(1)
 136   1              {
 137   2              temp=ReadTemperature();//读温度
 138   2              SHOWTEMP(temp);
 139   2              }
 140   1              return 0;
 141   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    525    ----
   CONSTANT SIZE    =     12    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     12       8
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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