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

📄 read-ds18b20-lcd1602-c51.lst

📁 读取ds18b20的序列号的程序
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.06   READ_DS18B20_LCD1602_C51                                              05/02/2009 22:07:12 PAGE 1   


C51 COMPILER V7.06, COMPILATION OF MODULE READ_DS18B20_LCD1602_C51
OBJECT MODULE PLACED IN READ-DS18B20-LCD1602-C51.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE READ-DS18B20-LCD1602-C51.C BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          /******************************************************************
   2          /*                                                                *
   3          /* OK300C单片机开发系统演示程序                                                               *
   4          /*                                                                *
   5          /* 版本: V2.0 (2008/6/20)                                       *
   6          /* 作者: 高山流水 (Email: aoke999@sohu.com)                      *
   7          /* 网站: www.aokemcu.cn(奥科电子)                                *
   8          /*                                                                *
   9          /*                                                                *
  10          /******************************************************************/
  11          
  12          #include <reg52.h>
  13          #include <intrins.h>
  14          
  15          #define uchar unsigned char
  16          #define uint  unsigned int
  17          
  18          sbit DQ = P2^2;  //定义DS18B20端口DQ  
  19          sbit BEEP=P2^3 ; //蜂鸣器驱动线
  20          
  21          bit  presence ;
  22          
  23          sbit LCD_RS = P3^5;             
  24          sbit LCD_RW = P3^6;
  25          sbit LCD_EN = P3^4;
  26          
  27          uchar code  cdis1[ ] = {"   DS18B20 OK   "};
  28          uchar code  cdis2[ ] = {"                "};
  29          uchar code  cdis3[ ] = {" DS18B20  ERR0R "};
  30          uchar code  cdis4[ ] = {"  PLEASE CHECK  "};
  31          
  32          unsigned char data  display[2] = {0x00,0x00};
  33                                              
  34          unsigned char data  RomCode[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
  35          
  36          unsigned char Temp;
  37          unsigned char  crc;
  38          
  39          void beep();
  40          
  41          #define delayNOP(); {_nop_();_nop_();_nop_();_nop_();};
  42          
  43          /*******************************************************************/
  44          void delay1(int ms)
  45          {
  46   1       unsigned char y;
  47   1        while(ms--)
  48   1       {
  49   2        for(y = 0; y<250; y++)
  50   2        {
  51   3         _nop_();
  52   3         _nop_();
  53   3         _nop_();
  54   3         _nop_();
  55   3        }
C51 COMPILER V7.06   READ_DS18B20_LCD1602_C51                                              05/02/2009 22:07:12 PAGE 2   

  56   2       }
  57   1      }
  58          
  59          /******************************************************************/
  60          /*                                                                */
  61          /*检查LCD忙状态                                                   */
  62          /*lcd_busy为1时,忙,等待。lcd-busy为0时,闲,可写指令与数据。     */
  63          /*                                                                */
  64          /******************************************************************/ 
  65          
  66          bit lcd_busy()
  67           {                          
  68   1          bit result;
  69   1          LCD_RS = 0;
  70   1          LCD_RW = 1;
  71   1          LCD_EN = 1;
  72   1          delayNOP();
  73   1          result = (bit)(P0&0x80);
  74   1          LCD_EN = 0;
  75   1          return(result); 
  76   1       }
  77          
  78          /*******************************************************************/
  79          /*                                                                 */
  80          /*写指令数据到LCD                                                  */
  81          /*RS=L,RW=L,E=高脉冲,D0-D7=指令码。                             */
  82          /*                                                                 */
  83          /*******************************************************************/
  84          
  85          void lcd_wcmd(uchar cmd)
  86          
  87          {                          
  88   1         while(lcd_busy());
  89   1          LCD_RS = 0;
  90   1          LCD_RW = 0;
  91   1          LCD_EN = 0;
  92   1          _nop_();
  93   1          _nop_(); 
  94   1          P0 = cmd;
  95   1          delayNOP();
  96   1          LCD_EN = 1;
  97   1          delayNOP();
  98   1          LCD_EN = 0;  
  99   1      }
 100          
 101          /*******************************************************************/
 102          /*                                                                 */
 103          /*写显示数据到LCD                                                  */
 104          /*RS=H,RW=L,E=高脉冲,D0-D7=数据。                               */
 105          /*                                                                 */
 106          /*******************************************************************/
 107          
 108          void lcd_wdat(uchar dat)
 109          {                          
 110   1         while(lcd_busy());
 111   1          LCD_RS = 1;
 112   1          LCD_RW = 0;
 113   1          LCD_EN = 0;
 114   1          P0 = dat;
 115   1          delayNOP();
 116   1          LCD_EN = 1;
 117   1          delayNOP();
C51 COMPILER V7.06   READ_DS18B20_LCD1602_C51                                              05/02/2009 22:07:12 PAGE 3   

 118   1          LCD_EN = 0; 
 119   1      }
 120          
 121          /*******************************************************************/
 122          /*                                                                 */
 123          /*  LCD初始化设定                                                  */
 124          /*                                                                 */
 125          /*******************************************************************/
 126          
 127          void lcd_init()
 128          { 
 129   1          delay1(15);   
 130   1          lcd_wcmd(0x01);      //清除LCD的显示内容
 131   1                  
 132   1          lcd_wcmd(0x38);      //16*2显示,5*7点阵,8位数据
 133   1          delay1(5);
 134   1          lcd_wcmd(0x38);         
 135   1          delay1(5);
 136   1          lcd_wcmd(0x38);         
 137   1          delay1(5);
 138   1      
 139   1          lcd_wcmd(0x0c);      //显示开,关光标
 140   1          delay1(5);
 141   1          lcd_wcmd(0x06);      //移动光标
 142   1          delay1(5);
 143   1          lcd_wcmd(0x01);      //清除LCD的显示内容
 144   1          delay1(5);
 145   1      }
 146          
 147          /*******************************************************************/
 148          /*                                                                 */
 149          /*  设定显示位置                                                   */
 150          /*                                                                 */
 151          /*******************************************************************/
 152          
 153          void lcd_pos(uchar pos)
 154          {                          
 155   1        lcd_wcmd(pos | 0x80);  //数据指针=80+地址变量
 156   1      }
 157          
 158          /*******************************************************************/
 159          /*                                                                 */
 160          /*us级延时函数                                                     */
 161          /*                                                                 */
 162          /*******************************************************************/
 163          
 164          void Delay(unsigned int num)
 165          {
 166   1        while( --num );
 167   1      }
 168          
 169          /*******************************************************************/
 170          /*                                                                 */
 171          /*初始化ds1820                                                     */
 172          /*                                                                 */
 173          /*******************************************************************/
 174          Init_DS18B20(void)
 175          {  
 176   1           DQ = 1;      //DQ复位
 177   1           Delay(8);    //稍做延时
 178   1      
 179   1           DQ = 0;      //将DQ拉低
C51 COMPILER V7.06   READ_DS18B20_LCD1602_C51                                              05/02/2009 22:07:12 PAGE 4   

 180   1           Delay(90);   //精确延时 大于 480us
 181   1      
 182   1           DQ = 1;       //拉高总线
 183   1           Delay(8);
 184   1      
 185   1           presence = DQ;    //读取存在信号
 186   1           Delay(100);
 187   1           DQ = 1; 
 188   1           
 189   1           return(presence); //返回信号,0=presence,1= no presence
 190   1      }
 191          
 192          /*******************************************************************/
 193          /*                                                                 */
 194          /* 读一位(bit)                                                   */
 195          /*                                                                 */
 196          /*******************************************************************/
 197          uchar read_bit(void) 
 198          {
 199   1      unsigned char i;
 200   1      DQ = 0;                  //将DQ 拉低开始读时间隙
 201   1      DQ = 1;                         // then return high
 202   1      for (i=0; i<3; i++);    // 延时15μs
 203   1      return(DQ);                     // 返回 DQ 线上的电平值
 204   1      }
 205          
 206          /*******************************************************************/
 207          /*                                                                 */
 208          /* 读一个字节                                                      */
 209          /*                                                                 */
 210          /*******************************************************************/
 211           ReadOneChar(void)
 212          {
 213   1      unsigned char i = 0;
 214   1      unsigned char dat = 0;
 215   1      
 216   1      //for (i = 8; i > 0; i--)
 217   1      //  {
 218   1      //       read_bit();
 219   1      //    DQ = 0; // 给脉冲信号
 220   1      //     dat >>= 1;
 221   1      //    DQ = 1; // 给脉冲信号
 222   1      for (i=0;i<8;i++) 
 223   1      {                               // 读取字节,每次读取一个字节
 224   2      if(read_bit()) 
 225   2      dat|=0x01<<i;           // 然后将其左移
 226   2      
 227   2      //    if(DQ)
 228   2      //     dat |= 0x80;
 229   2          Delay(4);
 230   2        }
 231   1      
 232   1          return (dat);
 233   1      }
 234          
 235          /*******************************************************************/

⌨️ 快捷键说明

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