lcd2.lst

来自「这是一段开始学单片机时写的LCD程序」· LST 代码 · 共 269 行

LST
269
字号
C51 COMPILER V7.50   LCD2                                                                  07/24/2007 16:45:13 PAGE 1   


C51 COMPILER V7.50, COMPILATION OF MODULE LCD2
OBJECT MODULE PLACED IN LCD2.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE LCD2.C BROWSE DEBUG OBJECTEXTEND

line level    source

   1          //****************************************
   2          //该程序实现用液晶显示器LCD显示一篇英语作文
   3          //作者:李锡坚
   4          //完成时间:2007.07.24.16:43
   5          //****************************************
   6          #include<reg51.h>               //包含常用头文件
   7          #include<stdio.h>
   8          #include<intrins.h>
   9          #include<absacc.h>
  10          #define uchar unsigned char        //定义常用数据类型
  11          int cnt;
  12          void LCD_INIT(void);               //LCD的初始化函数
  13          void LCD_DISPLAY_STR(char *DATA);//在指定的位置显示字符串
  14          void LCD_CLR(uchar y);                                                   //清除LCD指定的行
  15          void LCD_SEND_COMMAND(uchar COMMAND);                    //向LCD发送命令
  16          void LCD_SEND_DATA(uchar DATA);                                  //向LCD发送数据
  17          void LCD_WAIT(void);                             //检查LCD空闲
  18          uchar LCD_GET_FLAG(void);                                                //检查LCD状态
  19          void DELAY(void);                                                                //延时
  20          /*定义所要显示的数据*/
  21          char code DISPLAY[]="It goes without saying that this picture aims at revealing a current problem: what ki
             -nd of attitude we will choose when facing difficulties and challenges. In this drawing, a football-player is prepared to
             - kick a ball towards the net, where a goal-keeper keeps guard. However, in the player’s mind appears a scene in which t
             -he keeper becomes a giant covering the net completely, while the latter imagines that he turns out to be a dwarf standin
             -g below the huge net. Obviously, both of them lack courage and confidence in front of challenges.These two players repre
             -sent those who often choose to magnify their enemies and dangers, and lose their confidence to fight against them. As a 
             -result, what they can achieve in the end is nothing but failure. This sad situation can be best illustrated in the fact 
             -that some people lose their chance of success in the entrance examination for the MA program. When preparing for the exa
             -m, they often feel depressed thinking that they are never well-prepared. In fact, they will soon realize that it is not 
             -as difficult as they thought before. In a word, they suffer from underestimating their abilities.In our life, what we ne
             -ed most is self-insurance and a proper view of challenges before us. Therefore, we should bear in mind that our competit
             -ors may not be as terrible as expected, and our painstaking efforts will pay off as long as we arm ourselves with courag
             -e and confidence. Only in this way can we overcome any difficulties and challenges.";
  22          /*定义LCD控制字*/
  23          #define LCD_MODE 0x3C        /* 接口数据8位,显示2行,字体为1号 */          
  24          #define LCD_NO_FLASH 0x0C    /* 屏幕显示开,无光标 */        
  25          #define LCD_HIDE 0x08        /* 屏幕显示关 */       
  26          #define LCD_FLASH 0x0D       /* 屏幕显示开,并打开闪烁光标 */    
  27          #define LCD_SHIFT 0x07       /* 模块数据输入为增量方式,显示内容移动 */      
  28          #define LCD_NO_SHIFT 0x06    /* 模块数据输入为增量方式,显示光标移动 */     
  29          #define LCD_SH 0x14          /* 移动光标及整体显示 */ 
  30          #define LCD_LINE1  0x80          /*第一行DDRAM起始地址*/
  31          #define LCD_LINE2  0xc0          /*第二行DDRAM起始地址*/
  32          #define SEND_IN  XBYTE[0xff00] /*定义LCD的实际地址*/
  33          sbit LCD_RS=P3^4;                          //定义LCD的RS控制位
  34          sbit LCD_RW=P3^5;                          //定义LCD的RW控制位
  35          sbit LCD_DISPLAY_START=P1^0;   //LCD开始显示的指示灯
  36          int t=0;                                           //中断计数
  37          //*************************************************
  38          //LCD显示字符串的主程序
  39          //利用中断间隔循环显示
  40          //
  41          //*************************************************  
  42          main()
  43          {
C51 COMPILER V7.50   LCD2                                                                  07/24/2007 16:45:13 PAGE 2   

  44   1      LCD_INIT();                                       //初始化LCD
  45   1      do
  46   1       {
  47   2         LCD_DISPLAY_START=0;           //开LCD显示的指示灯
  48   2         DELAY();
  49   2         LCD_DISPLAY_START=1;           //灭LCD显示的指示灯
  50   2         LCD_DISPLAY_STR(DISPLAY);  //显示字符串
  51   2         }while(1);
  52   1      }
  53          //*************************************************
  54          //函数功能:LCD初始化
  55          //输入变量:无
  56          //输出变量:无
  57          //调用模块:LCD_SEND_COMMAND(),LCD_CLR()
  58          //*************************************************
  59          void LCD_INIT(void)
  60            {                                                                
  61   1         LCD_SEND_COMMAND(LCD_MODE);     //设置工作方式
  62   1         LCD_SEND_COMMAND(LCD_NO_FLASH); //设置显示方式
  63   1         LCD_SEND_COMMAND(LCD_NO_SHIFT); //设置光标画面滚动方式
  64   1         LCD_SEND_COMMAND(LCD_SH);       //设置输入方式
  65   1         LCD_CLR(1);                                     //清除LCD第一行
  66   1         LCD_CLR(2);                                     //清除LCD第二行
  67   1          }
  68          //*************************************************
  69          //函数功能:清除LCD指定行
  70          //输入变量:y
  71          //输出变量:无
  72          //调用模块:LCD_SEND_COMMAND(),LCD_SEND_DATA()
  73          //************************************************* 
  74          void LCD_CLR(uchar y)
  75             {
  76   1          uchar i;
  77   1              i=0;
  78   1              if(y==1)
  79   1                  {
  80   2                       LCD_SEND_COMMAND(LCD_LINE1);  //发送命令使LCD指向第一行
  81   2                       i=16;
  82   2                       }
  83   1          if(y==2)
  84   1                  {
  85   2                       LCD_SEND_COMMAND(LCD_LINE2);  //发送命令使LCD指向第二行
  86   2                       i=16;
  87   2                       }
  88   1               if(i!=0)
  89   1                       {
  90   2                        do
  91   2                         {
  92   3                          LCD_SEND_DATA(' ');            //让LCD的相应位置显示空格
  93   3                         }while(--i!=0);
  94   2           }
  95   1       }
  96          //*************************************************
  97          //函数功能:向LCD发送命令
  98          //输入变量:COMMAND
  99          //输出变量:无
 100          //调用模块:LCD_WAIT()
 101          //*************************************************
 102          void LCD_SEND_COMMAND(uchar COMMAND)
 103          {
 104   1        LCD_WAIT();    //等待空闲
 105   1        LCD_RS=0;              //命令方式
C51 COMPILER V7.50   LCD2                                                                  07/24/2007 16:45:13 PAGE 3   

 106   1        LCD_RW=0;              //写方式
 107   1        SEND_IN=COMMAND;//写实际的命令到LCD
 108   1      }
 109          //*************************************************
 110          //函数功能:向LCD发送数据
 111          //输入变量:DATA
 112          //输出变量:无
 113          //调用模块:LCD_WAIT()
 114          //*************************************************
 115          void LCD_SEND_DATA(uchar DATA)
 116          {
 117   1        LCD_WAIT();  //等待空闲
 118   1        LCD_RS=1;        //数据方式
 119   1        LCD_RW=0;        //写方式
 120   1        SEND_IN=DATA;//写实际的数据到LCD
 121   1      }
 122          //*************************************************
 123          //函数功能:等待LCD空闲
 124          //输入变量:无
 125          //输出变量:无
 126          //调用模块:LCD_GET_FLAG()
 127          //*************************************************
 128          void LCD_WAIT(void)
 129          {
 130   1       uchar i;
 131   1       i=1000;  //定义等待时间,可以防止由于LCD损坏而使程序死循环
 132   1       do
 133   1         {
 134   2              if((LCD_GET_FLAG()&0x80)==0) //判断BF是否为0
 135   2             {
 136   3                  break; 
 137   3                       }
 138   2               }while(--i!=0); 
 139   1      
 140   1      }
 141          //*************************************************
 142          //函数功能:检查LCD状态
 143          //输入变量:无
 144          //输出变量:LCD显示的当前状态
 145          //调用模块:无
 146          //*************************************************
 147          uchar LCD_GET_FLAG(void)
 148          {
 149   1        LCD_RS=0;
 150   1        LCD_RW=1;
 151   1        return(SEND_IN);
 152   1      }
 153          //*************************************************
 154          //函数功能:检查LCD状态
 155          //输入变量:无
 156          //输出变量:LCD显示的当前状态
 157          //调用模块:无
 158          //*************************************************
 159          void LCD_DISPLAY_STR(char *DATA)
 160          {
 161   1       int x=1,y=1;
 162   1       do
 163   1        {
 164   2         if(y==1)
 165   2         {
 166   3          LCD_CLR(1);
 167   3          LCD_SEND_COMMAND(LCD_LINE1);//发送显示位置命令
C51 COMPILER V7.50   LCD2                                                                  07/24/2007 16:45:13 PAGE 4   

 168   3          for(;x<(17)&&*DATA!='\0';x++)
 169   3             {
 170   4             LCD_SEND_DATA(*DATA++);           //发送数据
 171   4                 }
 172   3                       if(*DATA!='\0')                                 //判断是否发送完毕
 173   3                           {
 174   4                                x=1;
 175   4                                y=2;                                           //未完毕转到第二行显示
 176   4                                }
 177   3                DELAY();
 178   3                 }
 179   2              if(y==2)
 180   2          {
 181   3               LCD_CLR(2);
 182   3               LCD_SEND_COMMAND(LCD_LINE2);
 183   3               for(;x<(17)&&*DATA!='\0';x++)
 184   3                 {
 185   4                      LCD_SEND_DATA(*DATA++);
 186   4                  }
 187   3                      if(*DATA!='\0')                          //判断是否发送完毕
 188   3                           {
 189   4                                x=1;
 190   4                                y=1;                                           //未完毕转到第一行显示
 191   4                                }
 192   3                DELAY();
 193   3                }
 194   2         }while(*DATA!='\0');
 195   1      }
 196          //*************************************************
 197          //函数功能:延时3秒
 198          //输入变量:无
 199          //输出变量:无
 200          //调用模块:无
 201          //*************************************************
 202          void DELAY(void)
 203          {
 204   1       TMOD=0x02;
 205   1       TH0=0x06;
 206   1       TL0=0x06;
 207   1       TR0=1;
 208   1       ET0=1;
 209   1       EA=1;
 210   1       while(t!=8000);  //延时2秒   
 211   1       TR0=0;
 212   1       ET0=0;
 213   1       EA=0;
 214   1       t=0;
 215   1       }
 216          //*****************************************
 217          //
 218          //定时器0的溢出中断程序
 219          //
 220          //*****************************************
 221          void timer0(void) interrupt 1 using 0
 222          {
 223   1       t++;
 224   1      
 225   1       }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    418    ----
C51 COMPILER V7.50   LCD2                                                                  07/24/2007 16:45:13 PAGE 5   

   CONSTANT SIZE    =   1489    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =      4      12
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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