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

📄 12864.lst

📁 3线控制12864液晶的源程序代码
💻 LST
字号:
C51 COMPILER V8.02   12864                                                                 09/06/2008 13:07:47 PAGE 1   


C51 COMPILER V8.02, COMPILATION OF MODULE 12864
OBJECT MODULE PLACED IN 12864.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE 12864.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          /******************************************************/ 
   2          /*设计:赖卫国 */ 
   3          /* */ 
   4          /* 12864(ST7920)串口驱动程序C51,11.0592M晶振 */ 
   5          /*使用这款LCD应该要注意的问题: */ 
   6          /*一定要在VO与VDD及VSS这三个脚间接一个20K的电位器, */ 
   7          /*电位器的中间脚接VO,其它二脚接VDD和VSS。 */ 
   8          /*然后调节电位器的大小,直到有显示为止。若是不接的话,*/ 
   9          /*显示器可能是一片黑暗,什么也没有显示,发命令也没有反*/ 
  10          /*应的。本程序我已经测试通过了。欢迎大家提出意见。 */ 
  11          
  12          
  13          //陈仲库搜集于网络  创达科技 
  14          //技术支持:kuzi00@163.com
  15           /******************************************************/ 
  16          #include <reg52.H> 
  17          #include <intrins.h>
  18          
  19          
  20          
  21          #define uint unsigned int 
  22          #define uchar unsigned char
  23          
  24          
  25          
  26          /*12864(ST7920) pins define*/ 
  27          sbit CS=P1^0; 
  28          sbit SID=P1^1; 
  29          sbit SCLK=P1^2; 
  30          
  31          
  32          
  33          void delay_1ms(uint x) 
  34          { 
  35   1      uint j; 
  36   1      uchar i; 
  37   1      for(j=0;j<x;j++) 
  38   1      { 
  39   2      for(i=0;i<120;i++); 
  40   2      } 
  41   1      }
  42          
  43          
  44          
  45          void send_command(uchar command_data) 
  46          { 
  47   1      uchar i; 
  48   1      uchar i_data,temp_data1,temp_data2; 
  49   1      i_data=0xf8; 
  50   1      delay_1ms(10); 
  51   1      CS=1; 
  52   1      SCLK=0; 
  53   1      for(i=0;i<8;i++) 
  54   1      { 
  55   2      SID=(bit)(i_data&0x80); 
C51 COMPILER V8.02   12864                                                                 09/06/2008 13:07:47 PAGE 2   

  56   2      SCLK=0; 
  57   2      SCLK=1; 
  58   2      i_data=i_data<<1; 
  59   2      } 
  60   1      i_data=command_data; 
  61   1      i_data&=0xf0; 
  62   1      for(i=0;i<8;i++) 
  63   1      { 
  64   2      SID=(bit)(i_data&0x80); 
  65   2      SCLK=0; 
  66   2      SCLK=1; 
  67   2      i_data=i_data<<1; 
  68   2      } 
  69   1      i_data=command_data; 
  70   1      temp_data1=i_data&0xf0; 
  71   1      temp_data2=i_data&0x0f; 
  72   1      temp_data1>>=4; 
  73   1      temp_data2<<=4; 
  74   1      i_data=temp_data1|temp_data2; 
  75   1      i_data&=0xf0; 
  76   1      for(i=0;i<8;i++) 
  77   1      { 
  78   2      SID=(bit)(i_data&0x80); 
  79   2      SCLK=0; 
  80   2      SCLK=1; 
  81   2      i_data=i_data<<1; 
  82   2      } 
  83   1      CS=0; 
  84   1      } 
  85          
  86          void send_data(uchar command_data) 
  87          { 
  88   1      uchar i; 
  89   1      uchar i_data,temp_data1,temp_data2; 
  90   1      i_data=0xfa; 
  91   1      delay_1ms(10); 
  92   1      CS=1; 
  93   1      for(i=0;i<8;i++) 
  94   1      { 
  95   2      SID=(bit)(i_data&0x80); 
  96   2      SCLK=0; 
  97   2      SCLK=1; 
  98   2      i_data=i_data<<1; 
  99   2      } 
 100   1      i_data=command_data; 
 101   1      i_data&=0xf0; 
 102   1      for(i=0;i<8;i++) 
 103   1      { 
 104   2      SID=(bit)(i_data&0x80); 
 105   2      SCLK=0; 
 106   2      SCLK=1; 
 107   2      i_data=i_data<<1; 
 108   2      } 
 109   1      i_data=command_data; 
 110   1      temp_data1=i_data&0xf0; 
 111   1      temp_data2=i_data&0x0f; 
 112   1      temp_data1>>=4; 
 113   1      temp_data2<<=4; 
 114   1      i_data=temp_data1|temp_data2; 
 115   1      i_data&=0xf0; 
 116   1      for(i=0;i<8;i++) 
 117   1      { 
C51 COMPILER V8.02   12864                                                                 09/06/2008 13:07:47 PAGE 3   

 118   2      SID=(bit)(i_data&0x80); 
 119   2      SCLK=0; 
 120   2      SCLK=1; 
 121   2      i_data=i_data<<1; 
 122   2      } 
 123   1      CS=0; 
 124   1      }
 125          
 126          
 127          
 128          void lcd_init() 
 129          { 
 130   1      uchar command_data; 
 131   1      delay_1ms(100); 
 132   1      command_data=0x30; 
 133   1      send_command(command_data); /*功能设置:一次送8位数据,基本指令集*/ 
 134   1      command_data=0x04; 
 135   1      send_command(command_data); /*点设定:显示字符/光标从左到右移位,DDRAM地址加1*/ 
 136   1      command_data=0x0c; 
 137   1      send_command(command_data); /*显示设定:开显示,显示光标,当前显示位反白闪动*/ 
 138   1      command_data=0x01; 
 139   1      send_command(command_data); /*清DDRAM*/ 
 140   1      command_data=0x02; 
 141   1      send_command(command_data); /*DDRAM地址归位*/ 
 142   1      command_data=0x80; 
 143   1      send_command(command_data); /*把显示地址设为0X80,即为第一行的首位*/ 
 144   1      }
 145          
 146          
 147          
 148          void display_cpubbs() 
 149          { 
 150   1      uchar command_data; 
 151   1      while(1) 
 152   1      { 
 153   2      command_data=0x01; 
 154   2      send_command(command_data); /*清DDRAM*/ 
 155   2      command_data=0x80; 
 156   2      send_command(command_data); /*把显示地址设为0X80,即为第一行的首位*/ 
 157   2      command_data=0x68; /*“h”字的编码*/ 
 158   2      send_data(command_data); 
 159   2      command_data=0x74; 
 160   2      send_data(command_data); /*“t”字的编码*/ 
 161   2      command_data=0x74; 
 162   2      send_data(command_data); /*“t”字的编码*/ 
 163   2      command_data=0x70; 
 164   2      send_data(command_data); /*“p”字的编码*/ 
 165   2      command_data=0x3a; 
 166   2      send_data(command_data); /*“:”字的编码*/ 
 167   2      command_data=0x2f; 
 168   2      send_data(command_data); /*“/”字的编码*/ 
 169   2      command_data=0x2f; 
 170   2      send_data(command_data); /*“/”字的编码*/ 
 171   2      command_data=0x57; 
 172   2      send_data(command_data); /*“w”字的编码*/ 
 173   2      command_data=0x57; 
 174   2      send_data(command_data); /*“w”字的编码*/ 
 175   2      command_data=0x57; 
 176   2      send_data(command_data); /*“w”字的编码*/ 
 177   2      command_data=0x2e; 
 178   2      send_data(command_data); /*“.”字的编码*/ 
 179   2      command_data=0x63; 
C51 COMPILER V8.02   12864                                                                 09/06/2008 13:07:47 PAGE 4   

 180   2      send_data(command_data); /*“c”字的编码*/ 
 181   2      command_data=0x70; 
 182   2      send_data(command_data); /*“p”字的编码*/ 
 183   2      command_data=0x75; 
 184   2      send_data(command_data); /*“u”字的编码*/ 
 185   2      command_data=0x62; 
 186   2      send_data(command_data); /*“b”字的编码*/ 
 187   2      
 188   2      command_data=0x90; 
 189   2      send_command(command_data); /*把显示地址设为0X90,即为第二行的首位,因为第一行已经满了*/ 
 190   2      command_data=0x62; 
 191   2      send_data(command_data); /*“b”字的编码*/ 
 192   2      command_data=0x73; 
 193   2      send_data(command_data); /*“s”字的编码*/ 
 194   2      command_data=0x2e; 
 195   2      send_data(command_data); /*“.”字的编码*/ 
 196   2      command_data=0x63; 
 197   2      send_data(command_data); /*“c”字的编码*/ 
 198   2      command_data=0x6f; 
 199   2      send_data(command_data); /*“o”字的编码*/ 
 200   2      command_data=0x6d; 
 201   2      send_data(command_data); /*“m”字的编码*/ 
 202   2      
 203   2      delay_1ms(3000); 
 204   2      
 205   2      command_data=0x01; 
 206   2      send_command(command_data); /*清DDRAM*/ 
 207   2      command_data=0x80; 
 208   2      send_command(command_data); /*把显示地址设为0X80,即为第一行的首位*/ 
 209   2      
 210   2      command_data=0xbb; 
 211   2      send_data(command_data); 
 212   2      command_data=0xb6; 
 213   2      send_data(command_data); /*“欢”字的编码*/ 
 214   2      command_data=0xd3; 
 215   2      send_data(command_data); 
 216   2      command_data=0xad; 
 217   2      send_data(command_data); /*“迎”字的编码*/ 
 218   2      command_data=0xb7; 
 219   2      send_data(command_data); 
 220   2      command_data=0xc3; 
 221   2      send_data(command_data); /*“访”字的编码*/ 
 222   2      command_data=0xce; 
 223   2      send_data(command_data); 
 224   2      command_data=0xca; 
 225   2      send_data(command_data); /*“问”字的编码*/ 
 226   2      command_data=0x90; 
 227   2      send_command(command_data); /*把显示地址设为0X90,即为第二行的首位,因为第一行已经满了*/ 
 228   2      command_data=0x63; 
 229   2      send_data(command_data); /*“c”字的编码*/ 
 230   2      command_data=0x70; 
 231   2      send_data(command_data); /*“p”字的编码*/ 
 232   2      command_data=0x75; 
 233   2      send_data(command_data); /*“u”字的编码*/ 
 234   2      command_data=0x62; 
 235   2      send_data(command_data); /*“b”字的编码*/ 
 236   2      command_data=0x62; 
 237   2      send_data(command_data); /*“b”字的编码*/ 
 238   2      command_data=0x73; 
 239   2      send_data(command_data); /*“s”字的编码*/ 
 240   2      command_data=0xc2; 
 241   2      send_data(command_data); 
C51 COMPILER V8.02   12864                                                                 09/06/2008 13:07:47 PAGE 5   

 242   2      command_data=0xdb; 
 243   2      send_data(command_data); /*“论”字的编码*/ 
 244   2      command_data=0xcc; 
 245   2      send_data(command_data); 
 246   2      command_data=0xb3; 
 247   2      send_data(command_data); /*“坛”字的编码*/ 
 248   2      delay_1ms(3000); 
 249   2      } 
 250   1      }
 251          
 252          
 253          
 254          main() 
 255          { 
 256   1      uchar command_data; 
 257   1      lcd_init(); 
 258   1      /*while(1){
 259   1               
 260   1               send_command(0x80);
 261   1              delay_1ms(5);
 262   1      
 263   1              send_data(0x31);
 264   1              delay_1ms(5);
 265   1        
 266   1              //        lcdmode0();
 267   1        }      */
 268   1      display_cpubbs(); 
 269   1      while(1); 
 270   1      }
*** WARNING C280 IN LINE 256 OF 12864.C: 'command_data': unreferenced local variable


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    585    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----       2
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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