1820.lst

来自「无线红外传感报警系统」· LST 代码 · 共 163 行

LST
163
字号
C51 COMPILER V7.06   1820                                                                  06/10/2005 23:25:33 PAGE 1   


C51 COMPILER V7.06, COMPILATION OF MODULE 1820
OBJECT MODULE PLACED IN 1820.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE 1820.c DEBUG OBJECTEXTEND

stmt level    source

   1          #include<reg52.h>
   2          #include<intrins.h>
   3          
   4          #define uchar unsigned char
   5          #define uint  unsigned int
   6          sbit dq    = P2^6;
   7          bit  flag;
   8          uint temp;
   9          void init_18b20 (void);
  10          uint  read_word (void);
  11          //uchar read_byte (void);
  12          void write (uchar wr);
  13          //void config (void);
  14          unsigned int  get_temp (void);
  15          void delay1820 (uchar us);
  16          uint one=0;
  17          uint two=0;
  18          uint three=0;
  19          //
  20          
  21          void init_18b20 (void)
  22          {
  23   1        dq=1;
  24   1        _nop_();
  25   1        dq=0;
  26   1        delay1820(90);            //delay 530 uS
  27   1        dq=1;
  28   1        delay1820(6);            //delay 100 uS
  29   1        if(dq==0)
  30   1           flag=1;            //detect 1820 success!
  31   1        else
  32   1           flag=0;             //detect 1820 fail!
  33   1        delay1820(20);
  34   1        dq=1;      
  35   1      }
  36          //
  37          void write (uchar wr)
  38          {
  39   1        uchar i;
  40   1        for (i=0;i<8;i++)
  41   1         {
  42   2           dq=0;
  43   2           _nop_();
  44   2           dq=wr&0x01;
  45   2           delay1820(5);            //delay 45 uS
  46   2           dq=1;
  47   2           wr>>=1;
  48   2         }  
  49   1      }
  50          //
  51          uint read_word (void)
  52          { 
  53   1        uchar i;
  54   1        uint u=0;
  55   1        for(i=0;i<16;i++)
C51 COMPILER V7.06   1820                                                                  06/10/2005 23:25:33 PAGE 2   

  56   1         {
  57   2           dq=0;
  58   2           u>>=1;
  59   2           dq=1;
  60   2           if(dq==1)
  61   2              u|=0x8000;        
  62   2           delay1820 (4);   
  63   2         }  
  64   1        return(u); 
  65   1      }
  66          /*
  67          uchar read_byte (void)
  68          {
  69            uchar i,u=0;
  70            for(i=0;i<8;i++)
  71             {
  72               dq=0;
  73               u>>=1;
  74               dq=1;
  75               if(dq==1)
  76                  u|=0x80;        
  77               delay (4); 
  78             }
  79            return(u);     
  80          }
  81          //
  82          void config (void)
  83          {
  84            if(flag)
  85             {
  86               write (0xcc);        //skip rom
  87               write (0x4e);        //write scratchpad
  88               write (0x19);        //th=00
  89               write (0x1a);        //tl=00
  90               write (0x5f);           //set 11 bit (0.125)
  91               init_18b20();
  92               write (0xcc);        //skip rom
  93               write (0x48);        //copy
  94               init_18b20();
  95               write (0xcc);        //skip rom
  96               write (0xb8);        //recall
  97               delay (254);
  98               delay (250);
  99               init_18b20();
 100               write (0xcc);
 101               write (0xbe);
 102               one=read_word();
 103               two=read_word();
 104               three=read_word();
 105             }
 106          }
 107          */
 108          unsigned int get_temp (void)
 109          { 
 110   1        uint bdata tem;
 111   1        EA=0;
 112   1        init_18b20();
 113   1        if (flag)
 114   1         {
 115   2           write (0xcc);            //skip rom
 116   2           write (0x44);            //temp convert
 117   2           init_18b20 ();            
C51 COMPILER V7.06   1820                                                                  06/10/2005 23:25:33 PAGE 3   

 118   2           write (0xcc);            //skip rom
 119   2           write (0xbe);            //read temp
 120   2           tem=read_word();            //read
 121   2           if(tem<0x8000)
 122   2             temp=tem*0.602;            //temperature>=0
 123   2           else
 124   2             temp=tem*(-0.625);          //temperature< 0
 125   2           //write (0xec);               //search alarm
 126   2         
 127   2              }
 128   1         EA=1;
 129   1      return temp;
 130   1      }
 131          //
 132          void delay1820(uchar us)
 133          {
 134   1        while (us--);
 135   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    214    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     10       5
   IDATA SIZE       =   ----    ----
   BIT SIZE         =      1    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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