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

📄 lcd12864.lst

📁 这个事在51上面实现lcd串行驱动
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V8.02   LCD12864                                                              07/09/2008 11:10:59 PAGE 1   


C51 COMPILER V8.02, COMPILATION OF MODULE LCD12864
OBJECT MODULE PLACED IN .\temp\LCD12864.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE ..\Driver\LCD12864\LCD12864.C LARGE BROWSE DEBUG OBJECTEXTEND PRINT(.\temp\
                    -LCD12864.lst) OBJECT(.\temp\LCD12864.obj)

line level    source

   1          /*
   2          *****************************************************************************************
   3          *                                          电赛
   4          *                                     
   5          *                                     LCD12864液晶驱动程序
   6          *
   7          *                               (c) Copyright 2007, yyw, hbut
   8          *                                     All Rights Reserved
   9          *
  10          *                                            V1.00
  11          *
  12          * File : LCD12864.H
  13          * By   : 
  14          *****************************************************************************************
  15          */
  16          
  17          #define IN_LCD12864_C
  18          
  19          #include <stdio.h>
  20          #include <stdarg.h>
  21          #include "LCD12864.H"
  22          #include "ascii_8_16.h"
  23          #include "hanzi.h"
  24          
  25          // 定义lcd操作地址
  26          
  27          // 写命令
  28          // 写数据
  29          void LCD_C_D(bit Flag,uint8 Data)          // flag=1 con flag=0 data
  30          {
  31   1          LCD_RS = !Flag; LCD_E = 0; LCD_RW = 0; DataOut = Data; _nop_();
  32   1          LCD_E = 1; _nop_(); _nop_();
  33   1          LCD_E = 0; LCD_RW = 1; LCD_RS = 1;
  34   1      }
  35                          
  36          // 返回状态
  37          uint8 LCD_GET_FLAG(void)
  38          {
  39   1              LCD_RS = 0;
  40   1              return (LCD_RW);
  41   1      }
  42          
  43          // 等待LCD空闲
  44          void LCDDelay(void)
  45          {
  46   1              uint8 i;
  47   1              
  48   1              i = 200;
  49   1              do {
  50   2                      if(((LCD_GET_FLAG()) & 0x80 ) == 0)
  51   2                      {
  52   3                              break;
  53   3                      }
  54   2              }while(--i != 0);
C51 COMPILER V8.02   LCD12864                                                              07/09/2008 11:10:59 PAGE 2   

  55   1      }
  56          
  57          
  58          // 向LCD发送命令
  59          void LCDSendComm(uint8 Command)
  60          {
  61   1              LCDDelay();
  62   1              LCD_C_D(1, Command);
  63   1      }
  64          
  65          // 向LCD发送数据
  66          void LCDSendData(uint8 Data)
  67          {
  68   1              LCDDelay();
  69   1              LCD_C_D(0, Data);
  70   1      }
  71          
  72          // 清屏
  73          void LCDClr(uint8 Number)
  74          {
  75   1          uint8 i,j;
  76   1              
  77   1          LCD_CS1 = LCD_CS2 = 1;
  78   1          for (i = 0xb8; i < 0xc0;i++)
  79   1          {
  80   2              LCDSendComm(i);
  81   2              LCDSendComm(0X40);
  82   2              for (j = 0; j < 0x40; j++)
  83   2                  LCDSendData(Number);
  84   2          }
  85   1          LCD_CS1 = LCD_CS2 = 0;
  86   1      }
  87          
  88          // LCD初始化
  89          void LCDInit(void)
  90          {
  91   1              uint8 i;
  92   1              
  93   1              LCD_SET = 0;
  94   1          for ( i = 0; i != 0xff; i++);
  95   1          LCD_SET = 1;
  96   1          for ( i = 0; i != 0xff; i++);
  97   1              
  98   1              LCDSendComm(LCD_DISP_OFF);
  99   1              LCDSendComm(LCD_PAGE_ADD + 0);
 100   1              LCDSendComm(LCD_START_LINE + 0);
 101   1              LCDSendComm(LCD_COL_ADD + 0);
 102   1              LCDSendComm(LCD_DISP_ON);
 103   1              LCDClr(0);
 104   1      }
 105          
 106          // LCD显示坐标设置 
 107          void LCDSetPos(uint8 Page, uint8 Col)
 108          {
 109   1              if (Col < 64)
 110   1              {
 111   2                      LCD_CS1 = 1;
 112   2                      LCD_CS2 = 0;
 113   2              }
 114   1              else
 115   1              {
 116   2                      LCD_CS1 = 0;
C51 COMPILER V8.02   LCD12864                                                              07/09/2008 11:10:59 PAGE 3   

 117   2                      LCD_CS2 = 1;
 118   2                      Col = Col - 64;
 119   2              }
 120   1              LCDDelay();
 121   1              LCDSendComm(0x40 + Col);
 122   1              LCDDelay();
 123   1              LCDSendComm(0xb8 + Page);
 124   1      }
 125          
 126          
 127          void LCDPrintCn(uint8 Page, uint8 Col, uint8 Mod, uint8 *pStr)
 128          {
 129   1              uint8 c1, c2, i, temp;
 130   1              uint8 *pData;
 131   1              Col = Col * 16;
 132   1              while(*pStr != '\0')
 133   1              {
 134   2                      c1 = *pStr++;
 135   2                      c2 = *pStr++;
 136   2                      for(i = 0; i < sizeof(GB_16)/sizeof(GB_16[0]); i++)
 137   2                      {
 138   3                              if (c1 == GB_16[i].Index[0] && c2 == GB_16[i].Index[1])
 139   3                              {
 140   4                                      pData = &GB_16[i].Msk[0];
 141   4                                      break;
 142   4                              }
 143   3                      }
 144   2                      LCDSetPos(Page * 2, Col);
 145   2                      for(i = 0; i < 16; i++)
 146   2                      {
 147   3                              temp = *pData++;
 148   3                              temp = (Mod == 1) ? ~temp : temp;
 149   3                              LCDSendData(temp);
 150   3                      }
 151   2                      LCDSetPos(Page * 2 + 1, Col);
 152   2                      for(i = 0; i < 16; i++)
 153   2                      {
 154   3                              temp = *pData++;
 155   3                              temp = (Mod == 1) ? ~temp : temp;
 156   3                              LCDSendData(temp);
 157   3                      }
 158   2                      Col = Col + 16;
 159   2              }
 160   1      }
 161          
 162          void LCDPrintEn(uint8 Page, uint8 Col, uint8 Mod, uint8 *pStr)
 163          {
 164   1              uint8 c1,i,temp;
 165   1              uint8 *pData;
 166   1              Col = Col * 8;
 167   1              // 取出一个字符
 168   1              while(*pStr != '\0')
 169   1              {
 170   2                      c1 = *pStr++;
 171   2                      if (c1 < 0x20)          // 如果是转意字符
 172   2                      {
 173   3                              switch (c1)
 174   3                              {
 175   4                                      case '\n':
 176   4                                      case '\t':
 177   4                                      case '\b':
 178   4                                      default: ;
C51 COMPILER V8.02   LCD12864                                                              07/09/2008 11:10:59 PAGE 4   

 179   4                              }
 180   3                      }
 181   2                      else// 如果是一般字符

⌨️ 快捷键说明

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