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

📄 hk.lst

📁 此程序下位机采集18部0温度
💻 LST
字号:
C51 COMPILER V7.50   HK                                                                    03/19/2008 21:52:47 PAGE 1   


C51 COMPILER V7.50, COMPILATION OF MODULE HK
OBJECT MODULE PLACED IN hk.OBJ
COMPILER INVOKED BY: D:\keil\C51\BIN\C51.EXE hk.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          #include<reg52.h>
   2          #include <intrins.h>
   3          #define uchar unsigned char
   4          #define uint  unsigned int
   5          uchar Rl,Rh;//温度低位,温度高位
   6          uchar a,c;//中间变量
   7          sbit DQ=P3^7;//数据通信线
   8          uchar ge, shi, bai, shifen,baifen,qianfen,wanfen;//数组表示温度的每位 个 十 百 小数位
   9          code unsigned char table[]={0x03,0x9f,0x25,0x0d,0x99,0x49,0x41,0x1f,0x01,0x19};
  10                                    //0   1   2    3    4    5     6    7    8   9 共阳编码
  11          uchar flag;
  12          //延时t毫秒
  13          void delay(uint t)
  14          {   uint i,j;
  15   1              for(i=t;i>0;i--)
  16   1                for(j=130;j>0;j--);
  17   1      }
  18          //产生复位脉冲初始化DS18B20
  19          void Treset(void)
  20          {  uint i;
  21   1         DQ=0;
  22   1         //拉低562us
  23   1         for(i=70;i>0;i--);
  24   1         //产生上升沿
  25   1         DQ=1;
  26   1         //拉高15--60us
  27   1         for(i=4;i>0;i--);//是34us
  28   1      }
  29          //等待应答脉冲
  30          void Twait(void)
  31          {
  32   1       // uint i;
  33   1        while(DQ);
  34   1        while(~DQ);//检测是否有单器件在线
  35   1        _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
  36   1        _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();//等待20us是26us
  37   1      }
  38          //读取数据的一位,满足时间隙要求
  39          bit Rdbit(void)
  40          {
  41   1        uint i;
  42   1        bit b;
  43   1        DQ=0;
  44   1        _nop_();_nop_();//保持至少1us是2us
  45   1        DQ=1;
  46   1        _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
  47   1        _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();//延时15us以上是20us
  48   1        b=DQ;
  49   1        for(i=9;i>0;i--);//读时间隙不低于60us是74us
  50   1        return(b);
  51   1      }
  52          //读取数据的一个字节
  53          uchar Rdbyte(void)
  54          {
  55   1        uchar i,j,b;
C51 COMPILER V7.50   HK                                                                    03/19/2008 21:52:47 PAGE 2   

  56   1        b=0;
  57   1        for(i=1;i<=8;i++)
  58   1        {
  59   2           j=Rdbit();
  60   2               b=(j<<7)|(b>>1);
  61   2        }
  62   1        return(b);
  63   1      }
  64          //写数据的一个字节,满足写1和写0的要求
  65          void  Wrbyte(uchar b)
  66          {
  67   1        uint i;
  68   1        uchar j;
  69   1        bit btmp;
  70   1        for(j=1;j<=8;j++)
  71   1        {
  72   2          btmp=b&0x01;
  73   2              b=b>>1;
  74   2              if(btmp)
  75   2              {
  76   3                //写1
  77   3                DQ=0;
  78   3                _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();//延时,使得15US以内拉

⌨️ 快捷键说明

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