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

📄 16021602.lst

📁 用1602液晶显示温度 温度由18B20采集 控制器是AT89C52
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.20   16021602                                                              06/12/2008 13:37:14 PAGE 1   


C51 COMPILER V7.20, COMPILATION OF MODULE 16021602
OBJECT MODULE PLACED IN D:\仿真器\16021602.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE D:\仿真器\16021602.C DB SB OE

line level    source

   1          
   2          
   3          #include < reg51.h >
   4          #include < intrins.h >
   5          
   6          #define uchar unsigned char
   7          #define uint  unsigned int
   8          
   9          sbit DQ = P1^2 ;  //定义DS18B20端口DQ
  10          sbit BEEP=P2^1  ; //蜂鸣器驱动线
  11          
  12          bit presence  ;
  13          
  14          sbit LCD_RS = P3^0 ;
  15          sbit LCD_RW = P3^1 ;
  16          sbit LCD_EN = P3^2 ;
  17          
  18          uchar code  cdis1[ ] = {" welcome to JLDZ "} ;
  19          uchar code  cdis2[ ] = {" WENDU:    .  C "} ;
  20          uchar code  cdis3[ ] = {" DS18B20  ERR0R "} ;
  21          uchar code  cdis4[ ] = {"  PLEASE CHECK  "} ;
  22          
  23          unsigned char data  temp_data[2] = {0x00,0x00} ;
  24          unsigned char data  display[5] =   {0x00,0x00,0x00,0x00,0x00} ;
  25          unsigned char code  ditab[16] =    {0x00,0x01,0x01,0x02,0x03,0x03,0x04,0x04,
  26                                                                  0x05,0x06,0x06,0x07,0x08,0x08,0x09,0x09} ;
  27          void beep() ;
  28          unsigned char code  mytab[8] = {0x0C,0x12,0x12,0x0C,0x00,0x00,0x00,0x00} ;
  29          
  30          #define delayNOP() ; {_nop_() ;_nop_() ;_nop_() ;_nop_() ;} ;
  31          
  32          /*******************************************************************/
  33          void delay1(int ms)
  34          {
  35   1       unsigned char y ;
  36   1        while(ms--)
  37   1       {
  38   2        for(y = 0 ; y<250 ; y++)
  39   2        {
  40   3         _nop_() ;
  41   3         _nop_() ;
  42   3         _nop_() ;
  43   3         _nop_() ;
  44   3        }
  45   2       }
  46   1      }
  47          
  48          /******************************************************************/
  49          /*检查LCD忙状态                                                   */
  50          /*lcd_busy为1时,忙,等待。lcd-busy为0时,闲,可写指令与数据。   */
  51          /******************************************************************/
  52          bit lcd_busy()
  53           {
  54   1          bit result ;
  55   1          LCD_RS = 0 ;
C51 COMPILER V7.20   16021602                                                              06/12/2008 13:37:14 PAGE 2   

  56   1          LCD_RW = 1 ;
  57   1          LCD_EN = 1 ;
  58   1          delayNOP() ;
  59   1          result = (bit)(P0&0x80) ;
  60   1          LCD_EN = 0 ;
  61   1          return(result) ;
  62   1       }
  63          
  64          /*写指令数据到LCD                                                  */
  65          /*RS=L,RW=L,E=高脉冲,D0-D7=指令码。          */
  66          /*******************************************************************/
  67          void lcd_wcmd(uchar cmd)
  68          {
  69   1         while(lcd_busy()) ;
  70   1          LCD_RS = 0 ;
  71   1          LCD_RW = 0 ;
  72   1          LCD_EN = 0 ;
  73   1          _nop_() ;
  74   1          _nop_() ;
  75   1          P0 = cmd ;
  76   1          delayNOP() ;
  77   1          LCD_EN = 1 ;
  78   1          delayNOP() ;
  79   1          LCD_EN = 0 ;
  80   1      }
  81          
  82          /*******************************************************************/
  83          /*写显示数据到LCD                            */
  84          /*RS=H,RW=L,E=高脉冲,D0-D7=数据。       */
  85          /*******************************************************************/
  86          void lcd_wdat(uchar dat)
  87          {
  88   1         while(lcd_busy()) ;
  89   1          LCD_RS = 1 ;
  90   1          LCD_RW = 0 ;
  91   1          LCD_EN = 0 ;
  92   1          P0 = dat ;
  93   1          delayNOP() ;
  94   1          LCD_EN = 1 ;
  95   1          delayNOP() ;
  96   1          LCD_EN = 0 ;
  97   1      }
  98          
  99          
 100          /*  LCD初始化设定                                                  */
 101          /*******************************************************************/
 102          void lcd_init()
 103          {
 104   1          delay1(15) ;
 105   1          lcd_wcmd(0x01) ;      //清除LCD的显示内容
 106   1          lcd_wcmd(0x38) ;      //16*2显示,5*7点阵,8位数据
 107   1          delay1(5) ;
 108   1          lcd_wcmd(0x38) ;
 109   1          delay1(5) ;
 110   1          lcd_wcmd(0x38) ;
 111   1          delay1(5) ;
 112   1      
 113   1          lcd_wcmd(0x0c) ;      //显示开,关光标
 114   1          delay1(5) ;
 115   1          lcd_wcmd(0x06) ;      //移动光标
 116   1          delay1(5) ;
 117   1          lcd_wcmd(0x01) ;      //清除LCD的显示内容
C51 COMPILER V7.20   16021602                                                              06/12/2008 13:37:14 PAGE 3   

 118   1          delay1(5) ;
 119   1      }
 120          
 121          /*  设定显示位置                                    */
 122          /*******************************************************************/
 123          void lcd_pos(uchar pos)
 124          {
 125   1        lcd_wcmd(pos | 0x80) ;  //数据指针=80+地址变量
 126   1      }
 127          
 128          /*自定义字符写入CGRAM                                   */
 129          /*******************************************************************/
 130          void  writetab()
 131          {
 132   1          unsigned char i ;
 133   1          lcd_wcmd(0x40) ;            //写CGRAM
 134   1          for (i = 0 ; i< 8 ; i++)
 135   1          lcd_wdat(mytab[ i ]) ;
 136   1      }
 137          
 138          /*us级延时函数                                        */
 139          /*******************************************************************/
 140          
 141          void Delay(unsigned int num)
 142          {
 143   1        while( --num ) ;
 144   1      }
 145          
 146          /*初始化ds1820                                      */
 147          /*******************************************************************/
 148          Init_DS18B20(void)
 149          {
 150   1           DQ = 1 ;      //DQ复位
 151   1           Delay(8) ;    //稍做延时
 152   1      
 153   1           DQ = 0 ;      //单片机将DQ拉低
 154   1           Delay(90) ;   //精确延时 大于 480us
 155   1      
 156   1           DQ = 1 ;       //拉高总线
 157   1           Delay(8) ;
 158   1      
 159   1           presence = DQ ;    //如果=0则初始化成功 =1则初始化失败
 160   1           Delay(100) ;
 161   1           DQ = 1 ;
 162   1      
 163   1           return(presence) ; //返回信号,0=presence,1= no presence
 164   1      }
 165          
 166          
 167          /* 读一个字节                     */
 168          /*******************************************************************/
 169           ReadOneChar(void)
 170          {
 171   1      unsigned char i = 0 ;
 172   1      unsigned char dat = 0 ;
 173   1      
 174   1      for (i = 8 ; i > 0 ; i--)
 175   1        {
 176   2          DQ = 0 ; // 给脉冲信号
 177   2          dat >>= 1 ;
 178   2          DQ = 1 ; // 给脉冲信号
 179   2      
C51 COMPILER V7.20   16021602                                                              06/12/2008 13:37:14 PAGE 4   

 180   2          if(DQ)
 181   2           dat |= 0x80 ;
 182   2          Delay(4) ;
 183   2        }
 184   1      
 185   1          return (dat) ;
 186   1      }
 187          
 188          /* 写一个字节                                         */
 189          /*******************************************************************/
 190           WriteOneChar(unsigned char dat)
 191          {
 192   1        unsigned char i = 0 ;
 193   1        for (i = 8 ; i > 0 ; i--)
 194   1        {
 195   2          DQ = 0 ;
 196   2          DQ = dat&0x01 ;
 197   2          Delay(5) ;
 198   2      
 199   2          DQ = 1 ;
 200   2          dat>>=1 ;
 201   2        }
 202   1      }
 203          

⌨️ 快捷键说明

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