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

📄 lcd1602.lst

📁 基于DTH11+LCD温湿度采集
💻 LST
字号:
C51 COMPILER V9.01   LCD1602                                                               06/03/2013 17:32:38 PAGE 1   


C51 COMPILER V9.01, COMPILATION OF MODULE LCD1602
OBJECT MODULE PLACED IN LCD1602.OBJ
COMPILER INVOKED BY: D:\软件\keil\C51\BIN\C51.EXE LCD1602.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          //LCD1602文件
   2          #include<reg52.h>
   3          #include <stdio.h>
   4          #include <INTRINS.H>
   5          #include <Lcd_1602.h>
*** WARNING C318 IN LINE 5 OF LCD1602.c: can't open file 'Lcd_1602.h'
   6          #include <Time_Delay.h>
*** WARNING C318 IN LINE 6 OF LCD1602.c: can't open file 'Time_Delay.h'
   7          #define LCD_DATA P0                    //LCD1602 data transfer define
   8          
   9          #define uint unsigned int
  10          #define uchar unsigned char
  11          /*只由主函数调用的 有
  12           Init_Lcd()
  13           LCD_write_str(uchar X,uchar Y,uchar *s)
  14           LCD_value(unsigned char x,unsigned char y,float f)
  15          */
  16          
  17          sbit LCD_RS = P2^5;               //1602  control  define        
  18          sbit RW = P2^6;
  19          sbit LCD_E = P2^7;
  20          
  21          
  22          
  23          /**********************************************************************

  24          *****
  25          #define LCD_SCREEN_ON  0x0C    //显示开
  26          #define LCD_SCREEN_OFF  0x08    //显示关   
  27          #define LCD_CURSOR_ON  0x0A  //显示光标
  28          #define LCD_CURSOR_OFF    0x0c    //无光标       
  29          #define LCD_C_FLASH_ON  0x0f    //有光标,光标闪动
  30          #define LCD_C_FLASH_OFF  0x0e    //有光标,光标不闪动
  31          //进入模式设置指令
  32          #define LCD_AC_UP  0x06     //新数据后光标右移
  33          #define LCD_AC_DOWN  0x04     //新数据后光标左移
  34          #define LCD_S_MOVE_ON  0x05     // 画面可平移
  35          #define LCD_S_MOVE_OFF  0x04     //画面不可平移
  36          //设定显示屏或光标移动方向指令
  37          #define LCD_C_LEFT  0x10     //光标左移1格,且AC值减1
  38          #define LCD_C_RIGHT  0x11     //光标右移1格,且AC值加1
  39          #define LCD_CHAR_LEFT  0x18     //显示器上字符全部左移一格,但光标不动
  40          #define LCD_CHAR_RIGHT  0x1C     //显示器上字符全部右移一格,但光标不动
  41          ***********************************************************************

  42          ****/
  43          //注  有主函数调用的函数都已作说明 其他函数一般不由主函数调用
  44          
  45          /**********************************************************************

  46          ******
  47          * 名    称:Init_Lcd() 主函数调用
  48          * 功    能:Lcd初始化
  49          * 入口参数:无
  50          * 出口参数:无
  51          * 范    例: 在主函数中直接调用
  52                      
  53          ***********************************************************************

C51 COMPILER V9.01   LCD1602                                                               06/03/2013 17:32:38 PAGE 2   

  54          *****/
  55          
  56          void Init_Lcd()                           //LCD初始化
  57          {
  58   1      
  59   1       LCD_write_char(0x38,0);
*** WARNING C206 IN LINE 59 OF LCD1602.C: 'LCD_write_char': missing function-prototype
*** ERROR C267 IN LINE 59 OF LCD1602.C: 'LCD_write_char': requires ANSI-style prototype
  60   1       Delay_ms(1);
  61   1       LCD_write_char(0x38,0);
  62   1       Delay_ms(1);
  63   1       LCD_write_char(0x38,0);
  64   1       Delay_ms(1);
  65   1       LCD_write_char(0x0c,0);
  66   1       Delay_ms(1);
  67   1       LCD_write_char(0x06,0);
  68   1       Delay_ms(1);
  69   1       LCD_write_char(0x0c,0);
  70   1       Delay_ms(1); 
  71   1       //
  72   1      }
  73          
  74          /**********************************************************************

  75          ******
  76          * 名    称:LCD_write_str(uchar X,uchar Y,uchar *s)主函数调用   
  77          * 功    能:在指定地址写一个字符串   eg:Y=0,1,2,3,4,5,6,7,8,9,10...15。 

  78           X=0,1。
  79          * 入口参数:X:横坐标 Y:纵坐标 *s:字符串首地址 
  80          * 出口参数:无
  81          * 范    例: LCD_write_str(1,1,uchar *s)
  82                      
  83          ***********************************************************************

  84          *****/
  85          void LCD_write_str(unsigned char X,unsigned char Y,unsigned char *s)
  86            {
  87   1          LCD_write_char(0,' ');
  88   1          LCD_set_xy( X, Y );         //写地址    
  89   1          while (*s)                          // 写显示字符
  90   1            {
  91   2              LCD_write_char( 0, *s );
  92   2                      s ++;
  93   2            }
  94   1        }
  95          
  96          
  97          
  98          /**********************************************************************

  99          ******
 100          * 名    称:LCD_set_xy( uchar x, uchar y )          the optic sign  

 101          flash?
 102          * 功    能:指定一个地址
 103          * 入口参数:X:横坐标 Y:纵坐标 
 104          * 出口参数:无
 105          * 范    例: LCD_set_xy(5,1)
 106                      
 107          *************CD_set_xy*************************************************

 108          **************/
 109          void LCD_set_xy( uchar x, uchar y )  //写地址函数
 110            {
 111   1          unsigned char address;
 112   1          if (y == 0) address = 0x80 + x;
 113   1          else 
C51 COMPILER V9.01   LCD1602                                                               06/03/2013 17:32:38 PAGE 3   

 114   1             address = 0xc0 + x;
 115   1          LCD_write_char( address, 0 );
 116   1        }
 117          
 118          
 119          
 120          /**********************************************************************

 121          ******
 122          * 名    称:LCD_en_write(void)  
 123          * 功    能:液晶使能
 124          * 入口参数:无
 125          * 出口参数:无
 126          * 范    例: 直接调用
 127                      
 128          *************CD_set_xy*************************************************

 129          **************/
 130          void LCD_en_write(void)         //液晶使能
 131          {
 132   1        _nop_();
 133   1        LCD_E=1;//EN=1
 134   1        _nop_();
 135   1        LCD_E=0;//EN=0
 136   1      }
 137          //------------------------------------------------
 138          
 139          /**********************************************************************

 140          ******
 141          * 名    称:LCD_write_char(uchar cd,uchar ab)   
 142          * 功    能:写指令或数据  当写ab时 应使cd=0      当cd不为0 则写cd  且ab

 143          的赋值无效
 144          * 入口参数:cd:指令内容 ab:数据内容      指令常量已在上面定义  但一般不

 145          用
 146          * 出口参数:无
 147          * 范    例: LCD_write_char( 0, ‘f’)  
 148                      
 149          *************LCD_set_xy************************************************

 150          ***************/
 151          void LCD_write_char(uchar cd,uchar ab) // 写数据
 152          { 
 153   1       Delay_us(20);
 154   1       if(cd==0)
 155   1       {
 156   2        LCD_RS=1;                             //RS=1,写显示内容  
 157   2        LCD_byte(ab);
 158   2       }
 159   1       else
 160   1       {
 161   2        LCD_RS=0;                             //RS=0,写命令
 162   2        LCD_byte(cd);
 163   2        }
 164   1      }
 165          
 166          
 167          
 168          /**********************************************************************

 169          ******
 170          * 名    称:LCD_byte(abc);  
 171          * 功    能:写一个字符到 or called one byte to LCD中
 172          * 入口参数:
 173          * 出口参数:无
 174          
 175                      
C51 COMPILER V9.01   LCD1602                                                               06/03/2013 17:32:38 PAGE 4   

 176          *************LCD_set_xy************************************************

 177          ***************/
 178          void LCD_byte(unsigned char abc)  
 179          {
 180   1       RW = 0;
 181   1       LCD_E = 0;
 182   1       LCD_DATA = abc;
 183   1       LCD_en_write();
 184   1      }
 185            
 186          //在液晶中显示浮点数函数
 187          LCD_value(unsigned char x,unsigned char y,float f)
 188          {
 189   1       unsigned char str[15];                  //不能定义为char* str,数组长

 190   1      度一定要大于浮点数的总位数
 191   1      sprintf(str,"%.1f",f);                //1表示小数位数 小数太多 自动四舍

 192   1      五入
 193   1      LCD_write_str( x, y, str);
 194   1      return 0;
 195   1      }
 196          
 197          //主函数文件
 198          #include <reg52.h>
 199          #include <intrins.h>
 200          #include <Lcd_1602.h>
*** WARNING C318 IN LINE 200 OF LCD1602.c: can't open file 'Lcd_1602.h'
 201          #include <Time_Delay.h>
*** WARNING C318 IN LINE 201 OF LCD1602.c: can't open file 'Time_Delay.h'
 202          #include"DHT11.h"
*** WARNING C318 IN LINE 202 OF LCD1602.c: can't open file 'DHT11.h'
 203          
 204          
 205          extern float F16T,F16RH;   //全局变量声明
 206          void main ()
 207          {
 208   1        Init_Lcd();
 209   1        LCD_write_str(0,1,"abc");      //液晶预显示测试
 210   1        LCD_value(0,0,34.345);
 211   1        Delay_ms(2000);
 212   1      
 213   1        Init_Lcd();
 214   1       
 215   1          while(1)
 216   1        {
 217   2       
 218   2        getDHT11();
 219   2        LCD_write_str(0,0,"T=");
 220   2        LCD_value(3,0,F16T);  LCD_write_str(8,0,"\"C");       //字符" 应用转

 221   2      义格式
 222   2         LCD_write_str(0,1,"RH=");
 223   2        LCD_value(4,1,F16RH);   LCD_write_str(9,1,"%");
 224   2        Delay_ms(500);
 225   2        }
 226   1        
 227   1      }
 228          
 229          //延时函数文件
 230          //以下为延时函数 this is fit to old  C51  12MHz,   12 devide freqency
 231          void Delay_ms(unsigned int n)//n毫秒延时
 232          { 
 233   1       unsigned char j
 234   1       while(n--)
C51 COMPILER V9.01   LCD1602                                                               06/03/2013 17:32:38 PAGE 5   

 235   1       {
 236   1         for(j=0;j<125;j++);
 237   1       }
 238   1      }
 239   1      
 240   1      void Delay_us(unsigned char n)       //N us延时函数      精度 ±4us
 241   1        {
 242   1         n=n/2;
 243   1         while(--n);
 244   1        }

C51 COMPILATION COMPLETE.  6 WARNING(S),  1 ERROR(S)

⌨️ 快捷键说明

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