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

📄 fun.lst

📁 lcd1602编程资料。包括8位和4位口的c语言程序。当单片机口不够时可用4位接法
💻 LST
字号:
C51 COMPILER V8.02   FUN                                                                   04/11/2007 22:48:45 PAGE 1   


C51 COMPILER V8.02, COMPILATION OF MODULE FUN
OBJECT MODULE PLACED IN fun.OBJ
COMPILER INVOKED BY: D:\Program Files\Keil\C51\BIN\C51.EXE fun.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          #include <reg51.h>
   2          #include <intrins.h>
   3          #include "lcd1602.h"
   4          
   5           
   6          void delay (uchar times)                         //delay times ms
   7          {
   8   1        uchar i = 0;
   9   1        while (times --)
  10   1        {
  11   2          for (i = 0; i < 120; i++);
  12   2        }
  13   1      
  14   1      }
  15          
  16          bit bBusy()
  17          {
  18   1        bit result;
  19   1        RS = 0; RW = 1;      // read the AC and BF
  20   1        EN = 1;                          // generate a high level to read
  21   1      
  22   1        _nop_();  _nop_(); 
  23   1        _nop_();  _nop_();
  24   1      
  25   1        result = (bit)(P0 & 0x80);  //-----important------ *the four higher bits*
  26   1      
  27   1        // the lower four bits has been ignored //
  28   1      
  29   1        EN = 0;
  30   1      
  31   1        return result;
  32   1      
  33   1      }
  34          
  35          void wr_byte(bit bcmd, uchar cmd)
  36          {
  37   1        uchar Hcmd, Lcmd;
  38   1        Hcmd = cmd & 0xF0;
  39   1        Lcmd = (cmd << 4) & 0xF0;
  40   1      
  41   1        while (bBusy());     // wait if the lcd is busy
  42   1      
  43   1        if (bcmd)                        // if it's  cmd, RS = 0;
  44   1          RS = 0;
  45   1        else                             // if it's data, RS = 1;
  46   1          RS = 1;
  47   1      
  48   1        RW = 0;                  // set  R/W = 0
  49   1      //  EN = 0;                        // this step is ignorable
  50   1      
  51   1        _nop_();  _nop_(); 
  52   1        _nop_();  _nop_();
  53   1      
  54   1        P0 = Hcmd;            // prepare the higher four bits of the valid data
  55   1        EN = 1;                               // set E = 1
C51 COMPILER V8.02   FUN                                                                   04/11/2007 22:48:45 PAGE 2   

  56   1      
  57   1        _nop_();  _nop_(); 
  58   1        _nop_();  _nop_();
  59   1      
  60   1        EN = 0;                               // set E = 0, generate a falling edge to write
  61   1      
  62   1        _nop_(); _nop_();  
  63   1        _nop_(); _nop_();
  64   1      
  65   1        P0 = Lcmd;            // prepare the lower four bits of the valid data
  66   1        EN = 1;                               // set E = 1
  67   1      
  68   1        _nop_();  _nop_(); 
  69   1        _nop_();  _nop_();
  70   1      
  71   1        EN = 0;                               // set E = 0, generate a falling edge to write
  72   1      
  73   1        _nop_(); 
  74   1      
  75   1      }
  76          
  77          
  78          void ini_lcd1602(void)
  79          {
  80   1        delay (10);
  81   1        
  82   1      /* Function Set */
  83   1        wr_byte (1, 0x28);                            // 2 lines; 5*7 font; 4 bits
  84   1        delay (5);
  85   1        wr_byte (1, 0x28);                            // repeat the Function Set
  86   1        delay (5);
  87   1      
  88   1          
  89   1       /* --Display on/off-- */
  90   1        wr_byte (1, 0x0c);                            // Display: on; Cursor: on; Blink: on;
  91   1      
  92   1      /* --Display clear-- */
  93   1        wr_byte (1, 0x01);                            // display clear;
  94   1        delay (5);
  95   1        
  96   1      /* --Entry mode set-- */           // I/D: incremental; SH: 0;
  97   1        wr_byte (1, 0x06);
  98   1      
  99   1      }
 100          
 101          void wr_byte_ram (bit bDDram, uchar addr, uchar ch)
 102          {
 103   1        if (bDDram)                             // write data to DDRAM
 104   1           wr_byte (1, addr | 0x80);
 105   1        else                                            // write data to CGRAM
 106   1           wr_byte (1, addr | 0x40);
 107   1      
 108   1        wr_byte (0, ch);              
 109   1      }
 110          
 111          void wr_length_ram (bit bDDram, uchar addr, uchar *pch, uchar len)
 112          {
 113   1        uchar i = 0;
 114   1      
 115   1        if (bDDram)                             // write data to DDRAM
 116   1          wr_byte (1, addr | 0x80);
 117   1        else                                            // write data to CGRAM
C51 COMPILER V8.02   FUN                                                                   04/11/2007 22:48:45 PAGE 3   

 118   1          wr_byte (1, addr | 0x40);
 119   1      
 120   1        for (; i < len; i++)
 121   1        {
 122   2          wr_byte (0, *pch);            // the AC will increase/decrease automatically
 123   2              pch ++;
 124   2        }
 125   1      
 126   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    238    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----       8
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----       4
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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