C51 COMPILER V9.01   LCD                                                                   07/18/2014 12:12:01 PAGE 1   


C51 COMPILER V9.01, COMPILATION OF MODULE LCD
OBJECT MODULE PLACED IN LCD.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE LCD\LCD.c LARGE BROWSE DEBUG OBJECTEXTEND PRINT(.\LCD.lst) OBJECT(LCD.obj)

line level    source

   1          #include <reg51.h>
   2          #include <intrins.h>
   3          #include <font\font.h>
   4          #include <sys\sys.h>
   5          #include <lcd\lcd.h>
   6          
   7          unsigned char bdata bitdata;
   8          sbit bit7=bitdata^7;
   9          sbit bit6=bitdata^6;
  10          sbit bit5=bitdata^5;
  11          sbit bit4=bitdata^4;
  12          sbit bit3=bitdata^3;
  13          sbit bit2=bitdata^2;
  14          sbit bit1=bitdata^1;
  15          sbit bit0=bitdata^0;
  16          
  17          u16 BACK_COLOR, POINT_COLOR;   //背景色，画笔色   
  18          void LCD_Writ_Bus(char da)   //串行数据写入
  19          {       
  20   1              bitdata=da;
  21   1              LCD_SDI=bit7;LCD_SCK=0;LCD_SCK=1;
  22   1              LCD_SDI=bit6;LCD_SCK=0;LCD_SCK=1;
  23   1              LCD_SDI=bit5;LCD_SCK=0;LCD_SCK=1;
  24   1              LCD_SDI=bit4;LCD_SCK=0;LCD_SCK=1;
  25   1              LCD_SDI=bit3;LCD_SCK=0;LCD_SCK=1;
  26   1              LCD_SDI=bit2;LCD_SCK=0;LCD_SCK=1;
  27   1              LCD_SDI=bit1;LCD_SCK=0;LCD_SCK=1;
  28   1              LCD_SDI=bit0;LCD_SCK=0;LCD_SCK=1; 
  29   1      } 
  30          void LCD_WR_DATA8(char da) //发送数据-8位参数
  31          {
  32   1          LCD_DC=1;
  33   1              LCD_Writ_Bus(da);
  34   1      }  
  35           void LCD_WR_DATA(int da)
  36          {
  37   1          LCD_DC=1;
  38   1              LCD_Writ_Bus(da>>8);
  39   1              LCD_Writ_Bus(da);
  40   1      }         
  41          void LCD_WR_REG(char da)         
  42          {
  43   1          LCD_DC=0;
  44   1              LCD_Writ_Bus(da);
  45   1      }
  46           void LCD_WR_REG_DATA(int reg,int da)
  47          {
  48   1          LCD_WR_REG(reg);
  49   1              LCD_WR_DATA(da);
  50   1      }
  51          void Address_set(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2)
  52          {  
  53   1         LCD_WR_REG(0x2a);
  54   1         LCD_WR_DATA8(x1>>8);
  55   1         LCD_WR_DATA8(x1);
C51 COMPILER V9.01   LCD                                                                   07/18/2014 12:12:01 PAGE 2   

  56   1         LCD_WR_DATA8(x2>>8);
  57   1         LCD_WR_DATA8(x2);
  58   1        
  59   1         LCD_WR_REG(0x2b);
  60   1         LCD_WR_DATA8(y1>>8);
  61   1         LCD_WR_DATA8(y1);
  62   1         LCD_WR_DATA8(y2>>8);
  63   1         LCD_WR_DATA8(y2);
  64   1      
  65   1         LCD_WR_REG(0x2C);
  66   1      
  67   1      }
  68          void Lcd_Init(void)
  69          {
  70   1      
  71   1      //调用一次这些函数，免得编译的时候提示警告
  72   1              LCD_CS =1;
  73   1              if(LCD_CS==0)
  74   1              {
  75   2                 LCD_WR_REG_DATA(0,0);
  76   2                 LCD_ShowString(0,0," ");
  77   2                 LCD_ShowNum(0,0,0,0);
  78   2                 LCD_Show2Num(0,0,0,0);
  79   2                 LCD_DrawPoint_big(0,0);
  80   2                 LCD_DrawRectangle(0,0,0,0);
  81   2                 Draw_Circle(0,0,0);
  82   2               }    
  83   1              LCD_REST=0;
  84   1              delayms(20);
  85   1              LCD_REST=1;
  86   1              delayms(20);
  87   1              LCD_CS =0;  //打开片选使能
  88   1      
  89   1              LCD_WR_REG(0xCB);  
  90   1          LCD_WR_DATA8(0x39); 
  91   1          LCD_WR_DATA8(0x2C); 
  92   1          LCD_WR_DATA8(0x00); 
  93   1          LCD_WR_DATA8(0x34); 
  94   1          LCD_WR_DATA8(0x02); 
  95   1      
  96   1          LCD_WR_REG(0xCF);  
  97   1          LCD_WR_DATA8(0x00); 
  98   1          LCD_WR_DATA8(0XC1); 
  99   1          LCD_WR_DATA8(0X30); 
 100   1              
 101   1              LCD_WR_REG(0xE8);  
 102   1          LCD_WR_DATA8(0x85); 
 103   1          LCD_WR_DATA8(0x00); 
 104   1          LCD_WR_DATA8(0x78); 
 105   1              
 106   1              LCD_WR_REG(0xEA);  
 107   1          LCD_WR_DATA8(0x00); 
 108   1          LCD_WR_DATA8(0x00); 
 109   1              
 110   1              LCD_WR_REG(0xED);  
 111   1          LCD_WR_DATA8(0x64); 
 112   1          LCD_WR_DATA8(0x03); 
 113   1          LCD_WR_DATA8(0X12); 
 114   1          LCD_WR_DATA8(0X81); 
 115   1      
 116   1          LCD_WR_REG(0xF7);  
 117   1          LCD_WR_DATA8(0x20); 
C51 COMPILER V9.01   LCD                                                                   07/18/2014 12:12:01 PAGE 3   

 118   1         
 119   1          LCD_WR_REG(0xC0);    //Power control 
 120   1          LCD_WR_DATA8(0x23);   //VRH[5:0] 
 121   1         
 122   1          LCD_WR_REG(0xC1);    //Power control 
 123   1          LCD_WR_DATA8(0x10);   //SAP[2:0];BT[3:0] 
 124   1       
 125   1          LCD_WR_REG(0xC5);    //VCM control 
 126   1          LCD_WR_DATA8(0x3e); //对比度调节
 127   1          LCD_WR_DATA8(0x28); 
 128   1       
 129   1          LCD_WR_REG(0xC7);    //VCM control2 
 130   1          LCD_WR_DATA8(0x86);  //--
 131   1       
 132   1          LCD_WR_REG(0x36);    // Memory Access Control 
 133   1          LCD_WR_DATA8(0x48); //         //48 68竖屏//28 E8 横屏
 134   1      
 135   1          LCD_WR_REG(0x3A);    
 136   1          LCD_WR_DATA8(0x55); 
 137   1      
 138   1          LCD_WR_REG(0xB1);    
 139   1          LCD_WR_DATA8(0x00);  
 140   1          LCD_WR_DATA8(0x18); 
 141   1       
 142   1          LCD_WR_REG(0xB6);    // Display Function Control 
 143   1          LCD_WR_DATA8(0x08); 
 144   1          LCD_WR_DATA8(0x82);
 145   1          LCD_WR_DATA8(0x27);  
 146   1              
 147   1              LCD_WR_REG(0xF2);    // 3Gamma Function Disable 
 148   1          LCD_WR_DATA8(0x00); 
 149   1              
 150   1              LCD_WR_REG(0x26);    //Gamma curve selected 
 151   1          LCD_WR_DATA8(0x01); 
 152   1       
 153   1              LCD_WR_REG(0xE0);    //Set Gamma 
 154   1          LCD_WR_DATA8(0x0F); 
 155   1          LCD_WR_DATA8(0x31); 
 156   1          LCD_WR_DATA8(0x2B); 
 157   1          LCD_WR_DATA8(0x0C); 
 158   1          LCD_WR_DATA8(0x0E); 
 159   1          LCD_WR_DATA8(0x08); 
 160   1          LCD_WR_DATA8(0x4E); 
 161   1          LCD_WR_DATA8(0xF1); 
 162   1          LCD_WR_DATA8(0x37); 
 163   1          LCD_WR_DATA8(0x07); 
 164   1          LCD_WR_DATA8(0x10); 
 165   1          LCD_WR_DATA8(0x03); 
 166   1          LCD_WR_DATA8(0x0E); 
 167   1          LCD_WR_DATA8(0x09); 
 168   1          LCD_WR_DATA8(0x00); 
 169   1      
 170   1          LCD_WR_REG(0XE1);    //Set Gamma 
 171   1          LCD_WR_DATA8(0x00); 
 172   1          LCD_WR_DATA8(0x0E); 
 173   1          LCD_WR_DATA8(0x14); 
 174   1          LCD_WR_DATA8(0x03); 
 175   1          LCD_WR_DATA8(0x11); 
 176   1          LCD_WR_DATA8(0x07); 
 177   1          LCD_WR_DATA8(0x31); 
 178   1          LCD_WR_DATA8(0xC1); 
 179   1          LCD_WR_DATA8(0x48); 
C51 COMPILER V9.01   LCD                                                                   07/18/2014 12:12:01 PAGE 4   

 180   1          LCD_WR_DATA8(0x08); 
 181   1          LCD_WR_DATA8(0x0F); 
 182   1          LCD_WR_DATA8(0x0C); 
 183   1          LCD_WR_DATA8(0x31); 
 184   1          LCD_WR_DATA8(0x36); 
 185   1          LCD_WR_DATA8(0x0F); 
 186   1      
 187   1          LCD_WR_REG(0x11);    //Exit Sleep 
 188   1          delayms(120); 
 189   1                              
 190   1           LCD_WR_REG(0x29);    //Display on 
 191   1           LCD_WR_REG(0x2c); 
 192   1      
 193   1      }
 194          //清屏函数
 195          //Color:要清屏的填充色
 196          void LCD_Clear(u16 Color)
 197          {
 198   1              u8 VH,VL;
 199   1              u16 i,j;
 200   1              VH=Color>>8;
 201   1              VL=Color;       
 202   1              Address_set(0,0,LCD_W-1,LCD_H-1);
 203   1          for(i=0;i<LCD_W;i++)
 204   1               {
 205   2                for (j=0;j<LCD_H;j++)
 206   2                      {
 207   3                       LCD_WR_DATA8(VH);
 208   3                               LCD_WR_DATA8(VL);      
 209   3      
 210   3                  }
 211   2      
 212   2                }
 213   1      }
 214          //画点
 215          //POINT_COLOR:此点的颜色
 216          void LCD_DrawPoint(u16 x,u16 y)
 217          {
 218   1              Address_set(x,y,x,y);//设置光标位置 
 219   1              LCD_WR_DATA(POINT_COLOR);           
 220   1      }        
 221          //画一个大点
 222          //POINT_COLOR:此点的颜色
 223          void LCD_DrawPoint_big(u16 x,u16 y)
 224          {
 225   1              LCD_Fill(x-1,y-1,x+1,y+1,POINT_COLOR);
 226   1      } 
 227          //在指定区域内填充指定颜色
 228          //区域大小:
 229          //  (xend-xsta)*(yend-ysta)
 230          void LCD_Fill(u16 xsta,u16 ysta,u16 xend,u16 yend,u16 color)
 231          {          
 232   1              u16 i,j; 
 233   1              Address_set(xsta,ysta,xend,yend);      //设置光标位置 
 234   1              for(i=ysta;i<=yend;i++)
 235   1              {                                                                                                                       
 236   2                      for(j=xsta;j<=xend;j++)LCD_WR_DATA(color);//设置光标位置            
 237   2              }                                                   
 238   1      }  
 239          //画线
 240          //x1,y1:起点坐标
 241          //x2,y2:终点坐标  
C51 COMPILER V9.01   LCD                                                                   07/18/2014 12:12:01 PAGE 5   

 242          void LCD_DrawLine(u16 x1, u16 y1, u16 x2, u16 y2)
 243          {
 244   1              u16 t; 
 245   1              int xerr=0,yerr=0,delta_x,delta_y,distance; 
 246   1              int incx,incy,uRow,uCol; 
 247   1      
 248   1              delta_x=x2-x1; //计算坐标增量 
 249   1              delta_y=y2-y1; 
 250   1              uRow=x1; 
 251   1              uCol=y1; 
 252   1              if(delta_x>0)incx=1; //设置单步方向 
 253   1              else if(delta_x==0)incx=0;//垂直线 
 254   1              else {incx=-1;delta_x=-delta_x;} 
 255   1              if(delta_y>0)incy=1; 
 256   1              else if(delta_y==0)incy=0;//水平线 
 257   1              else{incy=-1;delta_y=-delta_y;} 
 258   1              if( delta_x>delta_y)distance=delta_x; //选取基本增量坐标轴 
 259   1              else distance=delta_y; 
 260   1              for(t=0;t<=distance+1;t++ )//画线输出 
 261   1              {  
 262   2                      LCD_DrawPoint(uRow,uCol);//画点 
 263   2                      xerr+=delta_x ; 
 264   2                      yerr+=delta_y ; 
 265   2                      if(xerr>distance) 
 266   2                      { 
 267   3                              xerr-=distance; 
 268   3                              uRow+=incx; 
 269   3                      } 
 270   2                      if(yerr>distance) 
 271   2                      { 
 272   3                              yerr-=distance; 
 273   3                              uCol+=incy; 
 274   3                      } 
 275   2              }  
 276   1      }    
 277          //画矩形
 278          void LCD_DrawRectangle(u16 x1, u16 y1, u16 x2, u16 y2)
 279          {
 280   1              LCD_DrawLine(x1,y1,x2,y1);
 281   1              LCD_DrawLine(x1,y1,x1,y2);
 282   1              LCD_DrawLine(x1,y2,x2,y2);
 283   1              LCD_DrawLine(x2,y1,x2,y2);
 284   1      }
 285          //在指定位置画一个指定大小的圆
 286          //(x,y):中心点
 287          //r    :半径
 288          void Draw_Circle(u16 x0,u16 y0,u8 r)
 289          {
 290   1              int a,b;
 291   1              int di;
 292   1              a=0;b=r;          
 293   1              di=3-(r<<1);             //判断下个点位置的标志
 294   1              while(a<=b)
 295   1              {
 296   2                      LCD_DrawPoint(x0-b,y0-a);             //3           
 297   2                      LCD_DrawPoint(x0+b,y0-a);             //0           
 298   2                      LCD_DrawPoint(x0-a,y0+b);             //1       
 299   2                      LCD_DrawPoint(x0-b,y0-a);             //7           
 300   2                      LCD_DrawPoint(x0-a,y0-b);             //2             
 301   2                      LCD_DrawPoint(x0+b,y0+a);             //4               
 302   2                      LCD_DrawPoint(x0+a,y0-b);             //5
 303   2                      LCD_DrawPoint(x0+a,y0+b);             //6 
C51 COMPILER V9.01   LCD                                                                   07/18/2014 12:12:01 PAGE 6   

 304   2                      LCD_DrawPoint(x0-b,y0+a);             
 305   2                      a++;
 306   2                      //使用Bresenham算法画圆     
 307   2                      if(di<0)di +=4*a+6;       
 308   2                      else
 309   2                      {
 310   3                              di+=10+4*(a-b);   
 311   3                              b--;
 312   3                      } 
 313   2                      LCD_DrawPoint(x0+a,y0+b);
 314   2              }
 315   1      } 
 316          //在指定位置显示一个字符
 317          
 318          //num:要显示的字符:" "--->"~"
 319          //mode:叠加方式(1)还是非叠加方式(0)
 320          //在指定位置显示一个字符
 321          
 322          //num:要显示的字符:" "--->"~"
 323          
 324          //mode:叠加方式(1)还是非叠加方式(0)
 325          void LCD_ShowChar(u16 x,u16 y,u8 num,u8 mode)
 326          {
 327   1          u8 temp;
 328   1          u8 pos,t;
 329   1              u16 x0=x;
 330   1              u16 colortemp=POINT_COLOR;      
 331   1          if(x>LCD_W-16||y>LCD_H-16)return;       
 332   1              //设置窗口                 
 333   1              num=num-' ';//得到偏移后的值
 334   1              Address_set(x,y,x+8-1,y+16-1);      //设置光标位置 
 335   1              if(!mode) //非叠加方式
 336   1              {
 337   2                      for(pos=0;pos<16;pos++)
 338   2                      { 
 339   3                              temp=asc2_1608[(u16)num*16+pos];                 //调用1608字体
 340   3                              for(t=0;t<8;t++)
 341   3                          {                 
 342   4                              if(temp&0x01)POINT_COLOR=colortemp;
 343   4                                      else POINT_COLOR=BACK_COLOR;
 344   4                                      LCD_WR_DATA(POINT_COLOR);       
 345   4                                      temp>>=1; 
 346   4                                      x++;
 347   4                          }
 348   3                              x=x0;
 349   3                              y++;
 350   3                      }       
 351   2              }else//叠加方式
 352   1              {
 353   2                      for(pos=0;pos<16;pos++)
 354   2                      {
 355   3                          temp=asc2_1608[(u16)num*16+pos];             //调用1608字体
 356   3                              for(t=0;t<8;t++)
 357   3                          {                 
 358   4                              if(temp&0x01)LCD_DrawPoint(x+t,y+pos);//画一个点     
 359   4                              temp>>=1; 
 360   4                          }
 361   3                      }
 362   2              }
 363   1              POINT_COLOR=colortemp;                            
 364   1      }   
 365          //m^n函数
C51 COMPILER V9.01   LCD                                                                   07/18/2014 12:12:01 PAGE 7   

 366          u32 mypow(u8 m,u8 n)
 367          {
 368   1              u32 result=1;    
 369   1              while(n--)result*=m;    
 370   1              return result;
 371   1      }                        
 372          //显示2个数字
 373          //x,y :起点坐标  
 374          //len :数字的位数
 375          //color:颜色
 376          //num:数值(0~4294967295);       
 377          void LCD_ShowNum(u16 x,u16 y,u32 num,u8 len)
 378          {               
 379   1              u8 t,temp;
 380   1              u8 enshow=0;
 381   1              num=(u16)num;
 382   1              for(t=0;t<len;t++)
 383   1              {
 384   2                      temp=(num/mypow(10,len-t-1))%10;
 385   2                      if(enshow==0&&t<(len-1))
 386   2                      {
 387   3                              if(temp==0)
 388   3                              {
 389   4                                      LCD_ShowChar(x+8*t,y,' ',0);
 390   4                                      continue;
 391   4                              }else enshow=1; 
 392   3                               
 393   3                      }
 394   2                      LCD_ShowChar(x+8*t,y,temp+48,0); 
 395   2              }
 396   1      } 
 397          //显示2个数字
 398          //x,y:起点坐标
 399          //num:数值(0~99);        
 400          void LCD_Show2Num(u16 x,u16 y,u16 num,u8 len)
 401          {               
 402   1              u8 t,temp;                                                 
 403   1              for(t=0;t<len;t++)
 404   1              {
 405   2                      temp=(num/mypow(10,len-t-1))%10;
 406   2                      LCD_ShowChar(x+8*t,y,temp+'0',0); 
 407   2              }
 408   1      } 
 409          //显示字符串
 410          //x,y:起点坐标  
 411          //*p:字符串起始地址
 412          //用16字体
 413          void LCD_ShowString(u16 x,u16 y,const u8 *p)
 414          {         
 415   1          while(*p!='\0')
 416   1          {       
 417   2              if(x>LCD_W-16){x=0;y+=16;}
 418   2              if(y>LCD_H-16){y=x=0;}
 419   2              LCD_ShowChar(x,y,*p,0);
 420   2              x+=8;
 421   2              p++;
 422   2          }  
 423   1      }
 424          
 425          
 426          
 427          
C51 COMPILER V9.01   LCD                                                                   07/18/2014 12:12:01 PAGE 8   

 428          
 429          
 430          
 431          
 432          
 433          
 434          
 435          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   3202    ----
   CONSTANT SIZE    =      2    ----
   XDATA SIZE       =      4     113
   PDATA SIZE       =   ----    ----
   DATA SIZE        =      1    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


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