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

📄 ds18b20-lcd1602-c51.lst

📁 ds18b20温度显示程序 C语言编写的程序 1602 液晶显示
💻 LST
📖 第 1 页 / 共 3 页
字号:
C51 COMPILER V8.08   DS18B20_LCD1602_C51                                                   03/21/2009 19:07:17 PAGE 1   


C51 COMPILER V8.08, COMPILATION OF MODULE DS18B20_LCD1602_C51
OBJECT MODULE PLACED IN DS18B20-LCD1602-C51.OBJ
COMPILER INVOKED BY: D:\DPJanzhuang\KeilC51V8.08破解版\C51\BIN\C51.EXE DS18B20-LCD1602-C51.C BROWSE DEBUG OBJECTEXTEND

line 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,flag;
  22          bit compare_th,compare_tl,alarm_on_off=0,temp_th,temp_tl;
  23          
  24          sbit LCD_RS = P3^5;             
  25          sbit LCD_RW = P3^6;
  26          sbit LCD_EN = P3^4;
  27          
  28          
  29          
  30          uchar code  cdis1[ ] = {"  READ_ROMCORD  "};
  31          uchar code  cdis2[ ] = {"                "};
  32          uchar code  cdis3[ ] = {" DS18B20  ERR0R "};
  33          uchar code  cdis4[ ] = {"  PLEASE CHECK  "};
  34          uchar code  cdis5[ ] = {" TEMP:          "};
  35          uchar code  cdis6[ ] = {"TH:     TL:     "};
  36          
  37          unsigned char data  temp_data[2] = {0x01,0x20};
  38          unsigned char data  temp_alarm[2] = {0x20,0x10};
  39          unsigned char data  display[5] =   {0x00,0x00,0x00,0x00,0x00}; //温度值显示
  40          unsigned char data  display1[3] =  {0x00,0x00,0x00}; //温度报警值显示
  41          
  42          unsigned char data  RomCode[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
  43           
  44          unsigned char code  mytab1[8] = {0x0C,0x12,0x12,0x0C,0x00,0x00,0x00,0x00};
  45          unsigned char code  mytab2[8] = {0x01,0x1b,0x1d,0x19,0x1d,0x1b,0x01,0x00};//小喇叭
  46          #define delayNOP(); {_nop_();_nop_();_nop_();_nop_();};
  47          
  48          unsigned char Temp,temp_comp,timecount,count;
  49          unsigned char  crc;
  50          void Disp_Temp_alarm(uchar addr,uchar num);
  51          void  spk(uchar addr);
  52          void set_temp_alarm();
  53          void temp_compare();
  54          void beep();
  55          /*******************************************************************/
C51 COMPILER V8.08   DS18B20_LCD1602_C51                                                   03/21/2009 19:07:17 PAGE 2   

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

 118          {                          
 119   1         while(lcd_busy());
 120   1          LCD_RS = 1;
 121   1          LCD_RW = 0;
 122   1          LCD_EN = 0;
 123   1          P0 = dat;
 124   1          delayNOP();
 125   1          LCD_EN = 1;
 126   1          delayNOP();
 127   1          LCD_EN = 0; 
 128   1      }
 129          
 130          /*******************************************************************/
 131          /*                                                                 */
 132          /*自定义字符写入CGRAM                                              */
 133          /*                                                                 */
 134          /*******************************************************************/
 135          void  writetab()  
 136          {  
 137   1          unsigned char i;
 138   1          lcd_wcmd(0x40);            //写CGRAM
 139   1          for (i = 0; i< 8; i++)       
 140   1          lcd_wdat(mytab1[i]);
 141   1          for (i = 0; i< 8; i++)       
 142   1          lcd_wdat(mytab2[i]);    
 143   1      }
 144          
 145          /*******************************************************************/
 146          /*                                                                 */
 147          /*  LCD初始化设定                                                  */
 148          /*                                                                 */
 149          /*******************************************************************/
 150          void lcd_init()
 151          { 
 152   1          delay1(15);   
 153   1          lcd_wcmd(0x01);      //清除LCD的显示内容            
 154   1          lcd_wcmd(0x38);      //16*2显示,5*7点阵,8位数据
 155   1          delay1(5);
 156   1          lcd_wcmd(0x38);         
 157   1          delay1(5);
 158   1          lcd_wcmd(0x38);         
 159   1          delay1(5);
 160   1      
 161   1          lcd_wcmd(0x0c);      //显示开,关光标
 162   1          delay1(5);
 163   1          lcd_wcmd(0x06);      //移动光标
 164   1          delay1(5);
 165   1          lcd_wcmd(0x01);      //清除LCD的显示内容
 166   1          delay1(5);
 167   1      
 168   1              writetab();               //自定义字符写入CGRAM
 169   1      }
 170          
 171          /*******************************************************************/
 172          /*                                                                 */
 173          /*  设定显示位置                                                   */
 174          /*                                                                 */
 175          /*******************************************************************/
 176          
 177          void lcd_pos(uchar pos)
 178          {                          
 179   1        lcd_wcmd(pos | 0x80);  //数据指针=80+地址变量
C51 COMPILER V8.08   DS18B20_LCD1602_C51                                                   03/21/2009 19:07:17 PAGE 4   

 180   1      }
 181          
 182          /*******************************************************************/
 183          /*                                                                 */
 184          /*us级延时函数                                                     */
 185          /*                                                                 */
 186          /*******************************************************************/
 187          
 188          void Delay(unsigned int num)
 189          {
 190   1        while( --num );
 191   1      }
 192          
 193          /*******************************************************************/
 194          /*                                                                 */
 195          /*初始化ds1820                                                     */
 196          /*                                                                 */
 197          /*******************************************************************/
 198          Init_DS18B20(void)
 199          {  
 200   1           DQ = 1;      //DQ复位
 201   1           Delay(8);    //稍做延时
 202   1      
 203   1           DQ = 0;      //单片机将DQ拉低
 204   1           Delay(90);   //精确延时 大于 480us
 205   1      
 206   1           DQ = 1;       //拉高总线
 207   1           Delay(8);
 208   1      
 209   1           presence = DQ;    //如果=0则初始化成功 =1则初始化失败
 210   1           Delay(100);
 211   1           DQ = 1; 
 212   1           
 213   1           return(presence); //返回信号,0=presence,1= no presence
 214   1      }
 215          
 216          /*******************************************************************/
 217          /*                                                                 */
 218          /* 读一个字节                                                      */
 219          /*                                                                 */
 220          /*******************************************************************/
 221           ReadOneChar(void)
 222          {
 223   1         unsigned char i = 0;
 224   1         unsigned char dat = 0;
 225   1      
 226   1         for (i = 8; i > 0; i--)
 227   1         {
 228   2           DQ = 0; // 给脉冲信号

⌨️ 快捷键说明

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