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

📄 12864.lst

📁 液晶12864驱动代码
💻 LST
字号:
C51 COMPILER V7.09   12864                                                                 12/10/2006 04:29:21 PAGE 1   


C51 COMPILER V7.09, COMPILATION OF MODULE 12864
OBJECT MODULE PLACED IN 12864.OBJ
COMPILER INVOKED BY: F:\软件安装1\软件安装\安装软件\C51\BIN\C51.EXE 12864.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          #include<head.h>
   2          //======================
   3          sbit RS =P1^0;
   4          sbit RW =P1^1;
   5          sbit E  =P1^2;
   6          sbit PSB=P1^3;
   7          //======================
   8          #define CS                      RS      //片选信号
   9          #define SID                     RW      //串行数据口
  10          #define CLK                     E       //串行同步时钟
  11          //================================================
  12          //串行数据传送第一字节--串口控制
  13          //================================================
  14          #define busy            0x80
  15          #define _rdata_         0xfe
  16          #define _rcomm_         0xfc
  17          #define _wdata_         0xfa
  18          #define _wcomm_         0xf8
  19          
  20          void delay(uint a)//不能忘了这些延时啊
  21          {uint i,j;
  22   1      for(i=0;i<a;i++)
  23   1      for(j=0;j<3500;j++);
  24   1      }
  25          
  26          void delay400ms(void)
  27          {
  28   1         uint u=555;
  29   1         while(u--);
  30   1      }
  31          //=========================
  32          void udelay(uint i)
  33          {
  34   1      while(i--);
  35   1      }
  36          
  37          //================================================
  38          //函数:void sendbyte(uchar senddata);
  39          //功能描述:发送一字节
  40          //================================================
  41          void sendbyte(uchar senddata)
  42          {uint i;
  43   1      CLK=0;
  44   1      for(i=0;i<8;i++)
  45   1              {
  46   2              if(senddata&0x80)SID=1;
  47   2              else SID=0;
  48   2              CLK=1;
  49   2              senddata<<=1;
  50   2              CLK=0;
  51   2              }
  52   1      }
  53          //================================================
  54          //函数:uchar readbyte(uchar readtype);
  55          //功能描述:读取一字节
C51 COMPILER V7.09   12864                                                                 12/10/2006 04:29:21 PAGE 2   

  56          //================================================
  57          uchar readbyte(uchar readtype)
  58          {
  59   1      uchar temph=0,templ=0,temp=0;
  60   1      uint  i;
  61   1      sendbyte(readtype);
  62   1      CLK=0;
  63   1      //SID=1;
  64   1      for(i=0;i<8;i++)
  65   1              {//udelay(144);
  66   2              CLK=1;
  67   2              //udelay(144);
  68   2              if(SID)temph=temph|1;
  69   2              temph<<=1;
  70   2              CLK=0;
  71   2              }
  72   1      for(i=0;i<8;i++)
  73   1              {//udelay(144);
  74   2              CLK=1;
  75   2              //udelay(144);
  76   2              if(SID)templ=templ|1;
  77   2              templ<<=1;
  78   2              CLK=0;
  79   2              }
  80   1              temp=(temph&0xf0)|((temph&0xf0)>>4);
  81   1              return(temp);
  82   1      }
  83          //================================================
  84          //函数:busywait();
  85          //功能描述:判断忙,直到不忙才往下运行
  86          //================================================
  87          void busywait(void)
  88          {uchar bf;
  89   1      loop:
  90   1      //udelay(100);
  91   1      bf=readbyte(_rcomm_);
  92   1      if(bf&busy)goto loop;
  93   1      }
  94          //================================================
  95          //函数:wr_comm_lcd(uchar command);
  96          //功能描述:写入一个命令
  97          //注意:命令只占一个字节
  98          //================================================
  99          void wr_comm_lcd(uchar command)
 100          {CS=1;
 101   1      busywait();
 102   1      sendbyte(_wcomm_);
 103   1      sendbyte(command&0xf0);
 104   1      sendbyte((command&0x0f)<<4);
 105   1      //CS=0;
 106   1      }
 107          //================================================
 108          //函数:wr_data_lcd(uchar wdata);
 109          //功能描述:写入一个字节的数据
 110          //注意:显示一个中文字符需要16位
 111          //================================================
 112          void wr_data_lcd(uchar wrdata)
 113          {CS=1;
 114   1      busywait();
 115   1      sendbyte(_wdata_);
 116   1      sendbyte(wrdata&0xf0);
 117   1      sendbyte((wrdata&0x0f)<<4);
C51 COMPILER V7.09   12864                                                                 12/10/2006 04:29:21 PAGE 3   

 118   1      //CS=0;
 119   1      }
 120          //================================================
 121          //函数:reset_lcd();
 122          //功能描述:液晶屏幕初始化
 123          //================================================
 124          void reset_lcd(void)
 125          {
 126   1      PSB=0;//使用串行口
 127   1      CLK=0;
 128   1      wr_comm_lcd(0x30);//功能设置 8位数据,基本指令
 129   1      delay400ms();
 130   1      wr_comm_lcd(0x0c);//显示状态 ON,游标OFF,反白OFF
 131   1      delay400ms();
 132   1      wr_comm_lcd(0x01);//清除显示
 133   1      delay400ms();
 134   1      wr_comm_lcd(0x02);//地址归位
 135   1      } 
 136          //================================================
 137          //函数:clear_disppanel();
 138          //功能描述:清液晶屏幕
 139          //================================================
 140          void clear_disppanel(void)
 141          {
 142   1      wr_comm_lcd(0x01);//清除显示
 143   1      }
 144          //================================================
 145          //函数:locate_xy(uint x,uint y);
 146          //功能描述:定光标位置
 147          //================================================
 148          void locate_xy(uint x,uint y)
 149          {
 150   1      uchar addr;
 151   1      switch(y)
 152   1              {
 153   2              case 0:addr=0x80+x;break;
 154   2              case 1:addr=0x90+x;break;
 155   2              case 2:addr=0x88+x;break;
 156   2              case 3:addr=0x98+x;break;
 157   2              default:break;
 158   2              }
 159   1      wr_comm_lcd(addr);
 160   1      }
 161          //=============================================================
 162          //函数:display_oneword(uint x,uint y,uchar word1,uchar word2);
 163          //功能描述:显示一个中文字,进行两次写一字节的操作
 164          //=============================================================
 165          void display_oneword(uint x,uint y,uchar word1,uchar word2)
 166          {
 167   1      locate_xy(x,y);
 168   1      wr_data_lcd(word1);
 169   1      wr_data_lcd(word2);
 170   1      }
 171          //=============================================================
 172          //函数:display_strword(uint x,uint y,uchar *pstr);
 173          //功能描述:显示整个中文字符数组里的文字
 174          //=============================================================
 175          void display_strword(uint x,uint y,uchar *pstr)
 176          {uint i,t=0;
 177   1      busywait();
 178   1      while(pstr[t]!='\0')t++;
 179   1      for(i=0;i<(t-1);i++)
C51 COMPILER V7.09   12864                                                                 12/10/2006 04:29:21 PAGE 4   

 180   1              {display_oneword(x++,y,pstr[i++],pstr[i]);
 181   2              delay(10);//显示一个字停0.5s
 182   2              if(x==8)
 183   2                      {
 184   3                      y+=1;
 185   3                      x=0;
 186   3                      if(y==4)y=0;
 187   3                      }
 188   2              }
 189   1      
 190   1      }
 191          //=============================================================
 192          //函数:disponechar(uint x,uint y,uchar *pstr,uint i);
 193          //功能描述:在指定的位置显示数组里指定的字
 194          //参数接口:x,y为定位坐标,pstr为操作数组,i为数组的第i个文字
 195          //=============================================================
 196          void disponechar(uint x,uint y,uchar *pstr,uint i)
 197          {
 198   1      uint k;
 199   1      k=2*i;
 200   1      display_oneword(x,y,pstr[k],pstr[k+1]);
 201   1      }
 202          //=============================================================
 203          //函数:drawpic(uint *pdraw);
 204          //功能描述:画图形
 205          //参数接口:pdraw,是存放图形数据的表
 206          //=============================================================
 207          void drawpic(uint *pdraw)
 208          {uint idata x,y,k=0;
 209   1      uchar yaddr=0x80;
 210   1      wr_comm_lcd(0x30);//功能设置---8BIT控制界面,绘图显示OFF
 211   1      wr_comm_lcd(0x34);//功能设置---8BIT控制界面,扩充指令集
 212   1      for(y=0;y<32;y++)
 213   1              {
 214   2              wr_comm_lcd(yaddr++);//设置绘图区的Y地址坐标
 215   2              wr_comm_lcd(0x80);//设置绘图区的X地址坐标
 216   2              for(x=0;x<8;x++)
 217   2                      {
 218   3                      wr_data_lcd(((pdraw[k])&0xff00)>>8);
 219   3                      wr_data_lcd((pdraw[k++])&0xff);
 220   3                      }
 221   2              }
 222   1      yaddr=0x80;
 223   1      for(y=0;y<32;y++)
 224   1              {       
 225   2              wr_comm_lcd(yaddr++);//设置绘图区的Y地址坐标
 226   2              wr_comm_lcd(0x88);//设置绘图区的X地址坐标
 227   2              for(x=0;x<8;x++)
 228   2                      {
 229   3                      wr_data_lcd(((pdraw[k])&0xff00)>>8);
 230   3                      wr_data_lcd((pdraw[k++])&0xff);
 231   3                      }
 232   2              }
 233   1      wr_comm_lcd(0x32);//功能设置---8BIT控制界面,绘图显示ON
 234   1      wr_comm_lcd(0x36);//功能设置---8BIT控制界面,绘图显示OFF
 235   1      }
 236          //=============================================================
 237          //函数:draw_byte(int x,int y);
 238          //功能描述:画一条一双字节的线
 239          //=============================================================
 240          void draw_word(int x,int y,int draw_data)
 241          {
C51 COMPILER V7.09   12864                                                                 12/10/2006 04:29:21 PAGE 5   

 242   1      wr_comm_lcd(0x30);//功能设置---8BIT控制界面,绘图显示OFF
 243   1      wr_comm_lcd(0x34);//功能设置---8BIT控制界面,扩充指令集
 244   1      wr_comm_lcd(y);//设置绘图区的Y地址坐标
 245   1      wr_comm_lcd(x);//设置绘图区的X地址坐标
 246   1      wr_data_lcd((draw_data&0xff00)>>8);//线条数据
 247   1      wr_data_lcd(draw_data&0xff);//线条数据
 248   1      wr_comm_lcd(0x32);//功能设置---8BIT控制界面,绘图显示ON
 249   1      wr_comm_lcd(0x36);//功能设置---8BIT控制界面,绘图显示OFF
 250   1      }
 251          //=============================================================
 252          //函数:clear_drawpanel()
 253          //功能描述:清整个画屏
 254          //=============================================================
 255          void clear_drawpanel()
 256          {int idata x,y;
 257   1      uchar yadrr=0x80;
 258   1      wr_comm_lcd(0x30);//功能设置---8BIT控制界面,绘图显示OFF
 259   1      wr_comm_lcd(0x34);//功能设置---8BIT控制界面,扩充指令集
 260   1      for(y=0;y<32;y++)
 261   1              { 
 262   2                      wr_comm_lcd(yadrr++);//设置绘图区的Y地址坐标
 263   2                      wr_comm_lcd(0x80);//设置绘图区的Y地址坐标
 264   2                      for(x=0;x<16;x++)
 265   2                      {
 266   3                      wr_data_lcd(0x00);//线条数据
 267   3                      }
 268   2              }
 269   1      yadrr=0x80;
 270   1      for(y=0;y<32;y++)
 271   1              {
 272   2                      wr_comm_lcd(yadrr++);//设置绘图区的Y地址坐标
 273   2                      wr_comm_lcd(0x88);//设置绘图区的x地址坐标
 274   2                      for(x=0;x<16;x++)
 275   2                      {
 276   3                      wr_data_lcd(0x00);//线条数据
 277   3                      }
 278   2              }
 279   1      wr_comm_lcd(0x32);//功能设置---8BIT控制界面,绘图显示ON
 280   1      wr_comm_lcd(0x36);//功能设置---8BIT控制界面,绘图显示OFF
 281   1      }
 282          //=============================================================
 283          //函数:int readback_word(int x,int y)
 284          //功能描述:readback a word draw data
 285          //=============================================================
 286          int readback_word(uchar x,uchar y)
 287          {int readdata;
 288   1      uchar H,L;
 289   1      wr_comm_lcd(0x32);//功能设置---8BIT控制界面,绘图显示ON
 290   1      wr_comm_lcd(0x36);//功能设置---8BIT控制界面,扩充指令集
 291   1      wr_comm_lcd(y);//设置绘图区的Y地址坐标
 292   1      wr_comm_lcd(x);//设置绘图区的x地址坐标
 293   1      H=readbyte(_rdata_);
 294   1      L=readbyte(_rdata_);
 295   1      readdata=H;
 296   1      readdata<<=8;
 297   1      readdata|=L;
 298   1      return(readdata);
 299   1      }
 300          //=============================================================
 301          //函数:the end;
 302          //功能描述:ok
 303          //=============================================================
C51 COMPILER V7.09   12864                                                                 12/10/2006 04:29:21 PAGE 6   



MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1083    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----      40
   IDATA SIZE       =   ----      10
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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