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

📄 51

📁 51单片机大量源码
💻
字号:
C51 COMPILER V8.09   1602GD                                                                07/12/2010 14:32:13 PAGE 1   


C51 COMPILER V8.09, COMPILATION OF MODULE 1602GD
OBJECT MODULE PLACED IN 1602GD.OBJ
COMPILER INVOKED BY: D:\Keil\C51\BIN\C51.EXE 1602GD.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          #include <reg51.h>
   2          #include <intrins.h>
   3          #define uchar unsigned char
   4          #define uint unsigned int
   5          
   6          sbit LCD_RS = P2^7;             
   7          sbit LCD_RW = P2^6;
   8          sbit LCD_EN = P2^5;
   9          
  10          uchar code dis1[] = {"   WLCOME  TO   "};
  11          uchar code dis2[] = {" WWW.RICHMCU.COM "};
  12          uchar code dis3[] = {"   OT  EMOCLW   "};
  13          uchar code dis4[] = {" MOC.UCMHCIR.WWW "};
  14          
  15          /*******************************************************************/
  16          /*                                                                                                        
             -                          */
  17          /* 延时子程序                                                                                             
             -                     */
  18          /*                                                                                                        
             -                          */
  19          /*******************************************************************/
  20          
  21          void delay(int ms)
  22          {                           
  23   1         int i;
  24   1         while(ms--)
  25   1         {
  26   2           for(i = 0; i< 250; i++)
  27   2           {
  28   3            _nop_();
  29   3            _nop_();
  30   3            _nop_();
  31   3            _nop_();
  32   3           }
  33   2         }
  34   1      }
  35          
  36          /*******************************************************************/
  37          /*                                                                                                        
             -                          */
  38          /*检查LCD忙状态                                                                                           
             -                  */
  39          /*lcd_busy为1时,忙,等待。lcd-busy为0时,闲,可写指令与数据。                                      */
  40          /*                                                                                                        
             -                          */
  41          /*******************************************************************/
  42          
  43          bit lcd_busy()
  44          {                          
  45   1          bit result;
  46   1          LCD_RS = 0;
  47   1          LCD_RW = 1;
  48   1          LCD_EN = 1;
  49   1          _nop_();
C51 COMPILER V8.09   1602GD                                                                07/12/2010 14:32:13 PAGE 2   

  50   1          _nop_();
  51   1          _nop_();
  52   1          _nop_();
  53   1           result = (bit)(P0&0x80);
  54   1          LCD_EN = 0;
  55   1          return result; 
  56   1      }
  57          
  58          /*******************************************************************/
  59          /*                                                                                                        
             -                          */
  60          /*写指令数据到LCD                                                                                         
             -                 */
  61          /*RS=L,RW=L,E=高脉冲,D0-D7=指令码。                                                                   *
             -/
  62          /*                                                                                                        
             -                          */
  63          /*******************************************************************/
  64          
  65          void lcd_wcmd(uchar cmd)
  66          {                          
  67   1         while(lcd_busy());
  68   1          LCD_RS = 0;
  69   1          LCD_RW = 0;
  70   1          LCD_EN = 0;
  71   1          _nop_();
  72   1          _nop_(); 
  73   1          P0 = cmd;
  74   1          _nop_();
  75   1          _nop_();
  76   1          _nop_();
  77   1          _nop_();
  78   1          LCD_EN = 1;
  79   1          _nop_();
  80   1          _nop_();
  81   1          _nop_();
  82   1          _nop_();
  83   1          LCD_EN = 0;  
  84   1      }
  85          
  86          /*******************************************************************/
  87          /*                                                                                                        
             -                          */
  88          /*写显示数据到LCD                                                                                         
             -                 */
  89          /*RS=H,RW=L,E=高脉冲,D0-D7=数据。                                                                     *
             -/
  90          /*                                                                                                        
             -                          */
  91          /*******************************************************************/
  92          
  93          void lcd_wdat(uchar dat) 
  94          {                          
  95   1         while(lcd_busy());
  96   1          LCD_RS = 1;
  97   1          LCD_RW = 0;
  98   1          LCD_EN = 0;
  99   1          P0 = dat;
 100   1          _nop_();
 101   1          _nop_();
 102   1          _nop_();
 103   1          _nop_();
C51 COMPILER V8.09   1602GD                                                                07/12/2010 14:32:13 PAGE 3   

 104   1          LCD_EN = 1;
 105   1          _nop_();
 106   1          _nop_();
 107   1          _nop_();
 108   1          _nop_();
 109   1          LCD_EN = 0; 
 110   1      }
 111          
 112          /*******************************************************************/
 113          /*                                                                                                        
             -                          */
 114          /*  设定显示位置                                                                                          
             -                    */
 115          /*                                                                                                        
             -                          */
 116          /*******************************************************************/
 117          
 118          void lcd_pos(uchar pos)
 119          {                          
 120   1         lcd_wcmd(pos|0x80);      //数据指针=80+地址变量
 121   1      }
 122          
 123          /*******************************************************************/
 124          /*                                                                                                        
             -                          */
 125          /*  LCD初始化设定                                                                                         
             -                  */
 126          /*                                                                                                        
             -                          */
 127          /*******************************************************************/
 128          
 129          void lcd_init()
 130          {                        
 131   1          lcd_wcmd(0x38);          //16*2显示,5*7点阵,8位数据
 132   1          delay(5);
 133   1          lcd_wcmd(0x38);         
 134   1          delay(5);
 135   1          lcd_wcmd(0x38);         
 136   1          delay(5);
 137   1      
 138   1          lcd_wcmd(0x0c);          //显示开,关光标
 139   1          delay(5);
 140   1          lcd_wcmd(0x06);          //移动光标
 141   1          delay(5);
 142   1          lcd_wcmd(0x01);          //清除LCD的显示内容
 143   1          delay(5);
 144   1      }
 145          
 146          /*******************************************************************/
 147          /*                                                                                                        
             -                          */
 148          /*  闪动子程序                                                                                            
             -                     */
 149          /*                                                                                                        
             -                          */
 150          /*******************************************************************/
 151          
 152          void flash()
 153          {
 154   1            delay(600);                    //控制停留时间
 155   1            lcd_wcmd(0x08);            //关闭显示
 156   1            delay(200);                    //延时
C51 COMPILER V8.09   1602GD                                                                07/12/2010 14:32:13 PAGE 4   

 157   1            lcd_wcmd(0x0c);            //开显示
 158   1            delay(200);                    //延时
 159   1            lcd_wcmd(0x08);            //关闭显示
 160   1            delay(200);                    //延时
 161   1            lcd_wcmd(0x0c);            //开显示
 162   1            delay(200);
 163   1      }
 164          
 165          /*******************************************************************/
 166          /*                                                                                                        
             -                          */
 167          /*  主程序                                                                                                
             -                       */
 168          /*                                                                                                        
             -                          */
 169          /*******************************************************************/
 170          
 171          main()
 172          {
 173   1          uchar i;
 174   1          delay(10);
 175   1          lcd_init();                        // 初始化LCD
 176   1            
 177   1      
 178   1          while(1)              
 179   1         { 
 180   2            lcd_wcmd(0x06);           //向右移动光标
 181   2            lcd_pos(0);                    //设置显示位置为第一行的第1个字符
 182   2            i = 0;
 183   2      
 184   2           while(dis1[i] != '\0')
 185   2           {                                     //显示字符"   Welcome  TO   "
 186   3             lcd_wdat(dis1[i]);
 187   3             i++;
 188   3             delay(30);                     //控制两字之间显示速度
 189   3           }
 190   2      
 191   2            lcd_pos(0x40);               //设置显示位置为第二行第1个字符
 192   2            i = 0;
 193   2      
 194   2           while(dis2[i] != '\0')
 195   2           {
 196   3             lcd_wdat(dis2[i]);          //显示字符" WWW.RICHMCU.COM "
 197   3             i++;
 198   3             delay(30);                     //控制两字之间显示速度
 199   3           }
 200   2      
 201   2            flash();                           //闪动二次
 202   2            lcd_wcmd(0x01);           //清除LCD的显示内容
 203   2            delay(200);                    //控制转换时间
 204   2            lcd_wcmd(0x04);           //向左移动光标
 205   2            lcd_pos(15);                  //设置显示位置为第一行的第16个字符
 206   2            i = 0;
 207   2      
 208   2           while(dis3[i] != '\0')
 209   2           {                                     //显示字符"   Welcome  TO   "
 210   3             lcd_wdat(dis3[i]);
 211   3             i++;
 212   3             delay(30);                     //控制两字之间显示速度
 213   3           }
 214   2      
 215   2            lcd_pos(0x4F);              //设置显示位置为第二行的第16个字符
C51 COMPILER V8.09   1602GD                                                                07/12/2010 14:32:13 PAGE 5   

 216   2            i = 0;
 217   2      
 218   2           while(dis4[i] != '\0')
 219   2           {
 220   3             lcd_wdat(dis4[i]);        //显示字符" WWW.RICHMCU.COM "
 221   3             i++;
 222   3             delay(30);                   //控制两字之间显示速度
 223   3           }
 224   2      
 225   2            flash();                         //闪动二次
 226   2            lcd_wcmd(0x01);         //清除LCD的显示内容
 227   2            delay(200);                 //控制转换时间
 228   2                
 229   2         }
 230   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    383    ----
   CONSTANT SIZE    =     70    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----       1
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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