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

📄 disp.lst

📁 KS0108 LCD液晶模块的驱动函数 包括PROTEUS仿真图
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.50   DISP                                                                  07/01/2008 15:53:05 PAGE 1   


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

line level    source

   1          /*
   2          ****************************************************
   3          
   4                          显示
   5          
   6          ****************************************************
   7          */
   8          
   9          #include <reg52.H>
  10          #include "Typedef.H"
  11          #include "UserDef.H"
  12          #include "Disp.h"
  13          #include "Font.H"
  14          
  15          
  16          /* 端口定义 */
  17          #define DISPDATAPORT    P0              //数据端口
  18          sbit Pin_CS1 = P2^1;                    //片选
  19          sbit Pin_CS2 = P2^0;                    //片选
  20          sbit Pin_RS = P2^2;                             //指令、数据选择(0=指令;1=数据)
  21          sbit Pin_RW = P2^3;                             //读写选择(0=写,1=读)
  22          sbit Pin_E = P2^4;                              //锁存(下降沿有效)
  23          sbit Pin_RST = P2^5;                            //锁存(下降沿有效)
  24          
  25          
  26          /*  全局变量 */
  27          static INT8U idata DispPro[2][MAXDISPLEN];              //显示属性缓冲区
  28          static INT8U CurRow = 0;
  29          static INT8U CurCol = 0;
  30          static INT8U CurFont = 0;
  31          //显示属性定义
  32          #define PRO_BLINK       (1<<1)  //闪烁
  33          
  34          
  35          /***************************************
  36          
  37                  LCD忙等待
  38          
  39          ****************************************/
  40          void Busy(void)
  41                  {
  42   1              INT8U bf;
  43   1      
  44   1              Pin_E = 0;
  45   1              DISPDATAPORT = 0xFF;    //使端口为输入状态
  46   1              Pin_RW = 1;                             //读
  47   1              Pin_RS = 0;                             //指令
  48   1      
  49   1              while (1)
  50   1                      {
  51   2                      Pin_E = 1;
  52   2                      bf = DISPDATAPORT;
  53   2                      Pin_E = 0;
  54   2                      if ((bf & 0x80) == 0)
  55   2                              break;
C51 COMPILER V7.50   DISP                                                                  07/01/2008 15:53:05 PAGE 2   

  56   2                      }
  57   1              }
  58          
  59          
  60          /***************************************
  61          
  62                  LCD数据写
  63          
  64          ****************************************/
  65          void LCD_Data(INT8U Data)
  66                  {
  67   1              Busy();
  68   1              
  69   1              Pin_E = 0;
  70   1              Pin_RW = 0;             //写
  71   1              Pin_RS = 1;             //数据
  72   1      
  73   1              Pin_E = 1;
  74   1      
  75   1              DISPDATAPORT = Data;
  76   1      
  77   1              Pin_E = 0;
  78   1              }
  79          
  80          /***************************************
  81          
  82                  LCD命令写
  83          
  84          ****************************************/
  85          void LCD_Cmd(INT8U cmd)
  86                  {
  87   1              Busy();
  88   1              
  89   1              Pin_E = 0;
  90   1              Pin_RW = 0;             //写
  91   1              Pin_RS = 0;             //指令
  92   1      
  93   1              Pin_E = 1;
  94   1      
  95   1              DISPDATAPORT = cmd;
  96   1      
  97   1              Pin_E = 0;
  98   1              }
  99          
 100          /***************************************
 101          
 102                  
 103          
 104          ****************************************/
 105          void LCD_Disp_Pattern(INT8U img,INT8U len)
 106                  {
 107   1              INT8U col;
 108   1      
 109   1              col = CurCol;
 110   1              if (col<64)
 111   1                      Pin_CS1 = 1;
 112   1              else
 113   1                      {
 114   2                      col -= 64;
 115   2                      Pin_CS2 = 1;
 116   2                      }
 117   1      
C51 COMPILER V7.50   DISP                                                                  07/01/2008 15:53:05 PAGE 3   

 118   1              LCD_Cmd(0xB8|CurRow);
 119   1              LCD_Cmd(0x40|col);
 120   1      
 121   1              while (len != 0)
 122   1                      {
 123   2                      LCD_Data(img);
 124   2                      len --;
 125   2                      col ++;
 126   2                      CurCol ++;
 127   2                      if (col>=64)
 128   2                              {
 129   3                              Pin_CS1 = 0;
 130   3                              Pin_CS2 = 1;
 131   3                              LCD_Cmd(0xB8|CurRow);
 132   3                              LCD_Cmd(0x40|0);
 133   3                              col -= 64;
 134   3                              }
 135   2                      }
 136   1              Pin_CS1 = 0;
 137   1              Pin_CS2 = 0;
 138   1              }
 139          
 140          
 141          /***************************************
 142          
 143                  
 144          
 145          ****************************************/
 146          void LCD_Disp_Pic(INT8U * img,INT8U len)
 147                  {
 148   1              INT8U col;
 149   1      
 150   1              col =CurCol;
 151   1      
 152   1              if (col<64)
 153   1                      Pin_CS1 = 1;
 154   1              else
 155   1                      {
 156   2                      col -= 64;
 157   2                      Pin_CS2 = 1;
 158   2                      }
 159   1              LCD_Cmd(0xB8|CurRow);
 160   1              LCD_Cmd(0x40|col);
 161   1      
 162   1              do
 163   1                      {
 164   2                      LCD_Data(*img);
 165   2                      len --;
 166   2                      col ++;
 167   2                      CurCol ++;
 168   2                      img ++;
 169   2                      if (col>=64)
 170   2                              {
 171   3                              Pin_CS1 = 0;
 172   3                              Pin_CS2 = 1;
 173   3                              LCD_Cmd(0xB8|CurRow);
 174   3                              LCD_Cmd(0x40|0);
 175   3                              col -= 64;
 176   3                              }
 177   2                      }while (len != 0);
 178   1              Pin_CS1 = 0;
 179   1              Pin_CS2 = 0;
C51 COMPILER V7.50   DISP                                                                  07/01/2008 15:53:05 PAGE 4   

 180   1              }
 181          
 182          /***************************************
 183          
 184                  显示扫描刷新程序
 185          
 186          ****************************************/
 187          void DispRef(void)
 188                  {
 189   1              static INT8U BlinkCnt = 0;              //闪烁显示计数器
 190   1              static BOOLEAN BlinkStatus = 0; //当前闪烁状态
 191   1      
 192   1              /* 计算显示闪烁状态 */
 193   1              BlinkCnt ++;                                                    
 194   1              BlinkCnt %= T_BLINK;
 195   1              if (BlinkCnt == 0)
 196   1                      BlinkStatus = !BlinkStatus;
 197   1      
 198   1              }
 199          
 200          
 201          /***************************************
 202          
 203                  获取整数的长度  
 204          
 205          ****************************************/
 206          static INT8U GetIntLen(INT32U val)
 207                  {
 208   1              INT8U len;
 209   1      
 210   1              len = 0;
 211   1              while (val != 0)
 212   1                      {
 213   2                      val /= 10;
 214   2                      len ++;
 215   2                      }
 216   1      
 217   1              if (len == 0)
 218   1                      len = 1;
 219   1      
 220   1              return len;
 221   1              }
 222          
 223          
 224          

⌨️ 快捷键说明

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